Skip to content

fix: refactor linker scripts for mold compatibility#347

Open
wallentx wants to merge 1 commit intoNVIDIA:mainfrom
wallentx:wallentx/mold-linker
Open

fix: refactor linker scripts for mold compatibility#347
wallentx wants to merge 1 commit intoNVIDIA:mainfrom
wallentx:wallentx/mold-linker

Conversation

@wallentx
Copy link

@wallentx wallentx commented Feb 5, 2026

This pull request solves #226, and updates the build system to support the mold linker while maintaining full backward compatibility with the default GNU ld.

mold imposes stricter requirements on linker scripts than GNU ld. Specifically, it does not support ENTRY, EXTERN, or SECTIONS tokens inside scripts passed via standard flags, and it expects version scripts to contain raw symbol maps (without the wrapping VERSION { ... } block).

Updates were made to the build configuration and linker scripts for both the library and CLI binary, moving away from custom linker scripts and adopting version scripts for symbol management. The changes streamline the build process and improve compatibility with standard linker features.

Build system and linker script improvements:

  • Replaces the custom linker script src/libnvidia-container.lds with a version script src/libnvidia-container.ver for the library, updating Makefile to use -Wl,--version-script for symbol visibility control. This removes manual section and entrypoint definitions in favor of standard symbol versioning. [1] [2] [3]
  • Removes the CLI linker script src/cli/nvidia-container-cli.lds and updates the Makefile to use linker flags (-Wl,-u,<symbol>) to ensure required symbols are included, rather than relying on EXTERN directives in a linker script. [1] [2]
  • Adds linker flags in the Makefile for the library build to explicitly set the entrypoint and include required symbols (-Wl,-e,nvc_entrypoint, -Wl,-u,interpreter, -Wl,-u,abitag), replacing previous script-based configuration.

Verification

Build Environment

  • System: Linux (x86_64)
  • Linkers Tested: mold and GNU ld

Tests Performed

  1. Mold Compatibility:
    • Build succeeds without errors.
    • nvidia-container-cli info executes correctly.
    • Executable Shared Object: ./libnvidia-container.so.1 executes and prints version info (verified PT_INTERP segment existence).
  2. Backward Compatibility:
    • Build with default ld succeeds (no regression).
    • nvidia-container-cli info executes correctly.
    • ./libnvidia-container.so.1 executes and prints version info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant