Skip to content

build: keep the NVML -L out of LDFLAGS - #18

Merged
ricky-chaoju merged 1 commit into
mainfrom
fix/nvml-ldflags-override
Sep 5, 2026
Merged

build: keep the NVML -L out of LDFLAGS#18
ricky-chaoju merged 1 commit into
mainfrom
fix/nvml-ldflags-override

Conversation

@ricky-chaoju

@ricky-chaoju ricky-chaoju commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

LDFLAGS is a user variable, so folding the NVML -L into it (added in #15) means a caller-supplied value replaces it. make LDFLAGS="-Wl,-z,now" — roughly what dpkg-buildflags and rpm's build flags do — drops the -L, and the link then fails on exactly the layout the lookup was added for: Debian keeps libnvidia-ml.so.1 in /usr/lib/<triplet>/nvidia/current, which only ld.so searches, not ld. An exported LDFLAGS also fails make check, because test_makefile_nvml_detection.sh compares the whole variable.

This moves the flag into NVML_LDFLAGS and puts it in LIBS, which is not a user variable, so a caller's LDFLAGS composes with it instead of replacing it. The test now asserts on NVML_LDFLAGS.

Verified in a container reproducing the Debian layout (driver library only in nvidia/current, registered via ld.so.conf):

before after
make ok ok
make LDFLAGS="-Wl,-z,now" fails, no -L on the link line ok, -L kept
LDFLAGS="-Wl,-z,now" make check fails ok
make NVML_LIBDIR=... ok ok
make check, make -j4, scripts/install.sh ok ok

Also rebuilt on the standard layout (Ubuntu 26.04, driver 595.84): make, make check and nvfd list against a real RTX 5090 all fine.

LDFLAGS is a user variable. A value passed on the command line, or
exported by a packaging system such as dpkg-buildflags or rpm's build
flags, replaces the makefile's `LDFLAGS +=` and takes the NVML -L with
it, so the link fails on exactly the layouts the lookup was added for
(Debian keeps libnvidia-ml.so.1 in /usr/lib/<triplet>/nvidia/current,
which only ld.so searches).

Hold the flag in NVML_LDFLAGS and put it in LIBS, which is not a user
variable, so a caller-supplied LDFLAGS composes with it instead of
replacing it. test_makefile_nvml_detection.sh now asserts on
NVML_LDFLAGS, which also stops an exported LDFLAGS from failing
`make check`.
@ricky-chaoju
ricky-chaoju force-pushed the fix/nvml-ldflags-override branch from 8234606 to ce698f9 Compare September 5, 2026 05:19
@ricky-chaoju
ricky-chaoju merged commit c4c8491 into main Sep 5, 2026
2 checks passed
@ricky-chaoju
ricky-chaoju deleted the fix/nvml-ldflags-override branch September 5, 2026 05:19
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