Skip to content

failing to compile when C compiler driver defaults to -z now #1706

Closed

Description

@drjoms

meson compile -C builddir
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/sbin/ninja -C /home/dimko/compiled/toolbox/builddir
ninja: Entering directory `/home/dimko/compiled/toolbox/builddir'
[1/1] Generating src/zsh-completion with a custom command (wrapped by meson to capture output)
FAILED: src/_toolbox
/usr/lib/python-exec/python3.13/meson --internal exe --capture src/_toolbox -- /usr/bin/python3.13 /home/dimko/compiled/toolbox/src/meson_generate_completions.py /home/dimko/compiled/toolbox/src zsh
--- stderr ---
/tmp/go-build2866398736/b001/exe/toolbox: symbol lookup error: /tmp/go-build2866398736/b001/exe/toolbox: undefined symbol: nvmlGpuInstanceGetComputeInstanceProfileInfoV
exit status 127
Traceback (most recent call last):
File "/home/dimko/compiled/toolbox/src/meson_generate_completions.py", line 32, in
output = subprocess.run(['go', 'run', '.', 'completion', completion_type], check=True)
File "/usr/lib/python3.13/subprocess.py", line 577, in run
raise CalledProcessError(retcode, process.args,
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['go', 'run', '.', 'completion', 'zsh']' returned non-zero exit status 1.

ninja: build stopped: subcommand failed.

Expected behaviour
No errors after compilation attempt

Actual behaviour
as per output above

Toolbx package info (rpm -q toolbox)
compiling from source

Output of podman version
e.g.,

Version:            1.9.2
RemoteAPI Version:  1
Go Version:         go1.14.2
OS/Arch:            linux/amd64

Podman package info (rpm -q podman)
[ebuild R ] app-containers/podman-5.3.2::gentoo USE="seccomp systemd -apparmor -btrfs (-selinux) -wrapper" 0 KiB

Info about your OS
current one only and latest Gentoo.(ongoing release)

Additional context
Attempting to follow those instructions:
https://containertoolbx.org/install/

meson compile -C builddir
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/sbin/ninja -C /home/dimko/compiled/toolbox/builddir
ninja: Entering directory `/home/dimko/compiled/toolbox/builddir'
[12/12] Generating src/zsh-completion with a custom command (wrapped by meson to capture output)
FAILED: src/_toolbox
/usr/lib/python-exec/python3.13/meson --internal exe --capture src/_toolbox -- /usr/bin/python3.13 /home/dimko/compiled/toolbox/src/meson_generate_completions.py /home/dimko/compiled/toolbox/src zsh
--- stderr ---
/home/dimko/.cache/go-build/8a/8acae153aba024568e3f0ca5d79f7f48544f8f994b124b69c9e8514ee61f787e-d/toolbox: symbol lookup error: /home/dimko/.cache/go-build/8a/8acae153aba024568e3f0ca5d79f7f48544f8f994b124b69c9e8514ee61f787e-d/toolbox: undefined symbol: nvmlGpuInstanceGetComputeInstanceProfileInfoV
exit status 127
Traceback (most recent call last):
File "/home/dimko/compiled/toolbox/src/meson_generate_completions.py", line 32, in
output = subprocess.run(['go', 'run', '.', 'completion', completion_type], check=True)
File "/usr/lib/python3.13/subprocess.py", line 577, in run
raise CalledProcessError(retcode, process.args,
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['go', 'run', '.', 'completion', 'zsh']' returned non-zero exit status 1.

ninja: build stopped: subcommand failed.

Not sure if relevant, I have modern AMD GPU with AMDGPU drivers.(because, undefined symbol: nvmlGpuInstanceGetComputeInstanceProfileInfoV)

Activity

  1. added
    1. Bug
    on Aug 12, 2025
  2. drjoms commented on Aug 12, 2025

    @drjoms
    Author

    dev-lang/go-1.24.6

  3. debarshiray commented on Aug 12, 2025

    @debarshiray
    Member

    Which version of Toolbx are you trying to compile? Are you using your own linker flags?

    --- stderr ---
    /tmp/go-build2866398736/b001/exe/toolbox: symbol lookup error: /tmp/go-build2866398736/b001/exe/toolbox: undefined symbol: nvmlGpuInstanceGetComputeInstanceProfileInfoV
    exit status 127

    This error makes me think that this about the linker flags. See these two commits:

    I will be away for two weeks, starting from tomorrow, so I won't be able to respond immediately.

  4. debarshiray commented on Sep 4, 2025

    @debarshiray
    Member

    Ping.

  5. drjoms commented on Sep 4, 2025

    @drjoms
    Author

    I am not entirely sure how those two commits relevant to my case. I am not owning any nvidia hardware, only AMD CPU and GPU.(amdgpu driver)
    I went with what was in README.
    I dont think Gentoo has tinkered with settings of "ld"(I assume this is what you asked?). I certainly did not put any specific ld options.

  6. drjoms commented on Sep 4, 2025

    @drjoms
    Author

    i dont know if this helps
    sys-devel/binutils-2.44-r4:2.44::gentoo USE="(cet) nls pgo plugins zstd -debuginfod -doc -gprofng -hardened -multitarget -static-libs -test -vanilla -xxhash" 0 KiB

  7. debarshiray commented on Sep 10, 2025

    @debarshiray
    Member

    I am not entirely sure how those two commits relevant to my case. I am not owning any nvidia hardware, only AMD CPU and GPU.(amdgpu driver)

    The code to support the proprietary NVIDIA driver is always compiled, regardless of whether the hardware is present or not. Some of it is used at runtime to find out if the hardware and the proprietary driver is present. If it's present, then the rest of it used, else not.

  8. debarshiray commented on Sep 10, 2025

    @debarshiray
    Member

    meson compile -C builddir
    INFO: autodetecting backend as ninja
    INFO: calculating backend command to run: /usr/sbin/ninja -C /home/dimko/compiled/toolbox/builddir
    ninja: Entering directory `/home/dimko/compiled/toolbox/builddir'
    [1/1] Generating src/zsh-completion with a custom command (wrapped by meson to capture output)
    FAILED: src/_toolbox /usr/lib/python-exec/python3.13/meson --internal exe --capture src/_toolbox -- /usr/bin/python3.13 /home/dimko/compiled/toolbox/src/meson_generate_completions.py /home/dimko/compiled/toolbox/src zsh
    --- stderr ---
    /tmp/go-build2866398736/b001/exe/toolbox: symbol lookup error: /tmp/go-build2866398736/b001/exe/toolbox: undefined symbol: nvmlGpuInstanceGetComputeInstanceProfileInfoV

    The error above when compiling Toolbx is exactly the same as described in commit 83f28c52e47c2d44:

    $ toolbox
      toolbox: symbol lookup error: toolbox: undefined symbol:
          nvmlGpuInstanceGetComputeInstanceProfileInfoV

    In your case, when you are compiling Toolbx, it's trying to run toolbox(1) to generate the shell completions, and that's failing.

    I went with what was in README.

    You mean https://containertoolbx.org/install/ ? The upstream Toolbx CI uses the same way to build Toolbx, so it should work.

    I am not familiar enough with Gentoo to dig into it and pinpoint what's exactly wrong. Right now my theory is that for some reason you are ending up using the -z now linker flag.

  9. changed the title [-]failing to compile[/-] [+]failing to compile because it can't lookup undefined symbol nvmlGpuInstanceGetComputeInstanceProfileInfoV[/+] on Sep 15, 2025
  10. drjoms commented on Sep 17, 2025

    @drjoms
    Author

    Can you please give me an example of command that allows me to check linker settings for go programming language?(right?)
    I understand that every (compiled)language can have custom flags for compilation of a specific program, due to making process?

    is there a verbose way to compile toolbox?

  11. PeakKS commented on Sep 21, 2025

    @PeakKS

    I'm also on gentoo, and I also get this issue.

    If I explicitly set -Wl,-z,lazy in go-build-wrapper the binary in builddir/src/toolbox works okay:

    blake@gbox ~/Code/toolbox $ ./builddir/src/toolbox
    Error: missing command
    
    create    Create a new Toolbx container
    enter     Enter an existing Toolbx container
    list      List all existing Toolbx containers and images
    
    Run 'toolbox --help' for usage.
    

    However the on in the go build cache does not work correctly:

    blake@gbox ~/Code/toolbox $ /home/blake/.cache/go-build/ac/ac4db54da5e00df3baa68975a29060c989f1fbd5ac1d6f48100d0835fd076f37-d/toolbox 
    /home/blake/.cache/go-build/ac/ac4db54da5e00df3baa68975a29060c989f1fbd5ac1d6f48100d0835fd076f37-d/toolbox: symbol lookup error: /home/blake/.cache/go-build/ac/ac4db54da5e00df3baa68975a29060c989f1fbd5ac1d6f48100d0835fd076f37-d/toolbox: undefined symbol: nvmlGpuInstanceGetComputeInstanceProfileInfoV
    

    And since go tries to generate completions with the one in the cache, the build fails:

    FAILED: [code=1] src/toolbox.bash 
    /usr/lib/python-exec/python3.13/meson --internal exe --capture src/toolbox.bash -- /usr/bin/python3.13 /home/blake/Code/toolbox/src/meson_generate_completions.py /home/blake/Code/toolbox/src bash
    --- stderr ---
    /home/blake/.cache/go-build/ac/ac4db54da5e00df3baa68975a29060c989f1fbd5ac1d6f48100d0835fd076f37-d/toolbox: symbol lookup error: /home/blake/.cache/go-build/ac/ac4db54da5e00df3baa68975a29060c989f1fbd5ac1d6f48100d0835fd076f37-d/toolbox: undefined symbol: nvmlGpuInstanceGetComputeInstanceProfileInfoV
    exit status 127
    Traceback (most recent call last):
      File "/home/blake/Code/toolbox/src/meson_generate_completions.py", line 32, in <module>
        output = subprocess.run(['go', 'run', '.', 'completion', completion_type], check=True)
      File "/usr/lib/python3.13/subprocess.py", line 577, in run
        raise CalledProcessError(retcode, process.args,
                                 output=stdout, stderr=stderr)
    subprocess.CalledProcessError: Command '['go', 'run', '.', 'completion', 'bash']' returned non-zero exit status 1.
    
    [3/3] Generating src/zsh-completion with a custom command (wrapped by meson to capture output)
    FAILED: [code=1] src/_toolbox 
    /usr/lib/python-exec/python3.13/meson --internal exe --capture src/_toolbox -- /usr/bin/python3.13 /home/blake/Code/toolbox/src/meson_generate_completions.py /home/blake/Code/toolbox/src zsh
    --- stderr ---
    /home/blake/.cache/go-build/ac/ac4db54da5e00df3baa68975a29060c989f1fbd5ac1d6f48100d0835fd076f37-d/toolbox: symbol lookup error: /home/blake/.cache/go-build/ac/ac4db54da5e00df3baa68975a29060c989f1fbd5ac1d6f48100d0835fd076f37-d/toolbox: undefined symbol: nvmlGpuInstanceGetComputeInstanceProfileInfoV
    exit status 127
    Traceback (most recent call last):
      File "/home/blake/Code/toolbox/src/meson_generate_completions.py", line 32, in <module>
        output = subprocess.run(['go', 'run', '.', 'completion', completion_type], check=True)
      File "/usr/lib/python3.13/subprocess.py", line 577, in run
        raise CalledProcessError(retcode, process.args,
                                 output=stdout, stderr=stderr)
    subprocess.CalledProcessError: Command '['go', 'run', '.', 'completion', 'zsh']' returned non-zero exit status 1.
    
    ninja: build stopped: subcommand failed.
    
    

    They list different dependencies with ldd as well.

    blake@gbox ~/Code/toolbox $ ldd builddir/src/toolbox 
    	linux-vdso.so.1 (0x00007f603952d000)
    	libresolv.so.2 => /run/host/usr/lib64/libresolv.so.2 (0x00007f6039513000)
    	libc.so.6 => /run/host/usr/lib64/libc.so.6 (0x00007f6039325000)
    	/run/host/usr/lib64/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f603952f000)
    blake@gbox ~/Code/toolbox $ ldd /home/blake/.cache/go-build/ac/ac4db54da5e00df3baa68975a29060c989f1fbd5ac1d6f48100d0835fd076f37-d/toolbox 
    	linux-vdso.so.1 (0x00007f3d662a8000)
    	libresolv.so.2 => /usr/lib64/libresolv.so.2 (0x00007f3d66268000)
    	libc.so.6 => /usr/lib64/libc.so.6 (0x00007f3d6607a000)
    	/lib64/ld-linux-x86-64.so.2 (0x00007f3d662aa000)
    
  12. PeakKS commented on Sep 21, 2025

    @PeakKS

    @drjoms If it helps I now have updated the toolbox ebuild in my overlay to the latest release plus the patches I have pending in #1722 : https://github.com/PeakKS/peakover/blob/master/app-containers/toolbox/toolbox-0.3.ebuild

  13. debarshiray commented on Sep 22, 2025

    @debarshiray
    Member

    I'm also on gentoo, and I also get this issue.

    If I explicitly set -Wl,-z,lazy in go-build-wrapper the binary in builddir/src/toolbox works okay:

    [...]

    However the on in the go build cache does not work correctly:

    I see. Thanks for tracking this down!

    They list different dependencies with ldd as well.

    blake@gbox ~/Code/toolbox $ ldd builddir/src/toolbox 
    	linux-vdso.so.1 (0x00007f603952d000)
    	libresolv.so.2 => /run/host/usr/lib64/libresolv.so.2 (0x00007f6039513000)
    	libc.so.6 => /run/host/usr/lib64/libc.so.6 (0x00007f6039325000)
    	/run/host/usr/lib64/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f603952f000)
    blake@gbox ~/Code/toolbox $ ldd /home/blake/.cache/go-build/ac/ac4db54da5e00df3baa68975a29060c989f1fbd5ac1d6f48100d0835fd076f37-d/toolbox 
    	linux-vdso.so.1 (0x00007f3d662a8000)
    	libresolv.so.2 => /usr/lib64/libresolv.so.2 (0x00007f3d66268000)
    	libc.so.6 => /usr/lib64/libc.so.6 (0x00007f3d6607a000)
    	/lib64/ld-linux-x86-64.so.2 (0x00007f3d662aa000)
    

    Yes, the binary in the cache is broken. Containers created with it might have trouble starting.

    I am curious, does the problem go away if you delete the cache or the cached binary?

  14. debarshiray commented on Jun 5, 2026

    @debarshiray
    Member

    I am looking into this again in the context of this pull request from @xandris The code changes look correct to me. I think we should merge it to enforce -z lazy because it's a hard requirement for Toolbx.

    Before doing that, I am trying to get a better understanding of what exactly happened here. I am unable to understand how Gentoo or any other distributor managed to disable lazy binding by default (ie., enforce -z now) for Toolbx.

    As far as I can make out, GNU ld.bfd doesn't have any build-time option to change its default. Were you using some other linker? If not, the only way to make the change seems to be to pass the -z now option at runtime, which will require either editing Toolbx's src/go-build-wrapper or changing the defaults passed by the Go toolchain to the linker.

    After digging around, I came across this request to make Gentoo default to -z now. However, the changes there are for the GCC and LLVM toolchains, not Go.

  15. xandris commented on Jun 6, 2026

    @xandris
    Contributor

    could this be due to github.com/NVIDIA/go-nvml/pkg/nvml itself? it uses cgo any code that uses or imports code with import "C" forces Go to use cgo, which uses $CC. on Gentoo, GCC has the DEF_GENTOO_ZNOW patch, affecting the linker spec.

    i thought CC=clang would sidestep the issue but i found this in clang-common:

    		newins - gentoo-hardened-ld.cfg <<-EOF
    			# Some of these options are added unconditionally, regardless of
    			# USE=hardened, for parity with sys-devel/gcc.
    			-Wl,-z,relro
    			-Wl,-z,now
    		EOF
    and just to confirm, i made a hello world program that does `import "C"` and asked go and clang to print their commands:
    Details ... host link: "clang" "-m64" "-s" "-Wl,--build-id=0x95cb0bc13341216f9aa2a0b9af945305fdbf7721" "-o" "/tmp/go-build2661240062/b001/exe/m" "-Wl,--export-dynamic-symbol=_cgo_panic" "-Wl,--export-dynamic-symbol=_cgo_topofstack" "-Wl,--export-dynamic-symbol=crosscall2" "-Qunused-arguments" "-Wl,--compress-debug-sections=zlib" "/tmp/go-link-2952583088/go.o" "/tmp/go-link-2952583088/000000.o" "/tmp/go-link-2952583088/000001.o" "/tmp/go-link-2952583088/000002.o" "/tmp/go-link-2952583088/000003.o" "/tmp/go-link-2952583088/000004.o" "/tmp/go-link-2952583088/000005.o" "/tmp/go-link-2952583088/000006.o" "/tmp/go-link-2952583088/000007.o" "/tmp/go-link-2952583088/000008.o" "/tmp/go-link-2952583088/000009.o" "/tmp/go-link-2952583088/000010.o" "/tmp/go-link-2952583088/000011.o" "/tmp/go-link-2952583088/000012.o" "/tmp/go-link-2952583088/000013.o" "/tmp/go-link-2952583088/000014.o" "/tmp/go-link-2952583088/000015.o" "/tmp/go-link-2952583088/000016.o" "-O2" "-g" "-O2" "-g" "-lpthread" "-no-pie" "-v" ... "/usr/lib/llvm/22/bin/ld.lld" -s --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o $WORK/b001/exe/m /usr/lib/gcc/x86_64-pc-linux-gnu/16/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-pc-linux-gnu/16/../../../../lib64/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/16/crtbegin.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/16 -L/usr/lib/gcc/x86_64-pc-linux-gnu/16/../../../../lib64 -L/lib/../lib64 -L/usr/lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/16/../../../../x86_64-pc-linux-gnu/lib -L/lib -L/usr/lib -z relro -z now --build-id=0x95cb0bc13341216f9aa2a0b9af945305fdbf7721 --export-dynamic-symbol=_cgo_panic --export-dynamic-symbol=_cgo_topofstack --export-dynamic-symbol=crosscall2 --compress-debug-sections=zlib /tmp/go-link-2952583088/go.o /tmp/go-link-2952583088/000000.o /tmp/go-link-2952583088/000001.o /tmp/go-link-2952583088/000002.o /tmp/go-link-2952583088/000003.o /tmp/go-link-2952583088/000004.o /tmp/go-link-2952583088/000005.o /tmp/go-link-2952583088/000006.o /tmp/go-link-2952583088/000007.o /tmp/go-link-2952583088/000008.o /tmp/go-link-2952583088/000009.o /tmp/go-link-2952583088/000010.o /tmp/go-link-2952583088/000011.o /tmp/go-link-2952583088/000012.o /tmp/go-link-2952583088/000013.o /tmp/go-link-2952583088/000014.o /tmp/go-link-2952583088/000015.o /tmp/go-link-2952583088/000016.o -lpthread -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-pc-linux-gnu/16/crtend.o /usr/lib/gcc/x86_64-pc-linux-gnu/16/../../../../lib64/crtn.o

    note that it uses $CC to do the linking, not $LD. i think it's to get the C runtime stuff like crt*.o without having to reimplement the lookup logic but i don't really know. so no matter what, Go code that uses C interop is at the mercy of the host C compiler and whatever hardening efforts the vendor has done to them

  16. drjoms commented on Jun 6, 2026

    @drjoms
    Author

    I dont remember why i needed toolbox, i found alternative to what i needed. I have no reason to reproduce or fix issue now. May be it was specific to my installation and my fault. Closing this.

  17. debarshiray commented on Jun 9, 2026

    @debarshiray
    Member

    on Gentoo, GCC has the DEF_GENTOO_ZNOW patch, affecting the linker spec.

    Thanks for digging up the reference to Gentoo's downstream GCC build and spec file! I didn't know where to look.

    This explains why we didn't see this problem in the Fedora family and other distributions so far. Fedora passes -Wl,z,now to the clang(1) and gcc(1) compiler drivers through the LDFLAGS environment variable, and Gentoo uses a Clang configuration file and a GCC spec file. The hacky and messy wiring between Meson and go build filters out LDFLAGS, but not the spec or configuration file.

    i thought CC=clang would sidestep the issue but i found this in clang-common:

      newins - gentoo-hardened-ld.cfg <<-EOF
      	# Some of these options are added unconditionally, regardless of
      	# USE=hardened, for parity with sys-devel/gcc.
      	-Wl,-z,relro
      	-Wl,-z,now
      EOF
    

    Thanks again for the reference! It makes sense that the default Clang and GCC configurations match.

    and just to confirm, i made a hello world program that does import "C" and asked go and clang to print their commands:

    [...]

    note that it uses $CC to do the linking, not $LD. i think it's to get the C runtime stuff like crt*.o without having to reimplement the lookup logic but i don't really know. so no matter what, Go code that uses C interop is at the mercy of the host C compiler and whatever hardening efforts the vendor has done to them

    Thanks for the experiment!

    I see that the Go toolchain (ie., gc, not gccgo) always uses the clang(1) or gcc(1) compiler drivers when external linking mode (ie., go build -ldflags "-linkmode external" or go tool link -linkmode external) is used.

    The online documentation of go tool link hints at this, but not go tool link --help. It's confirmed by reading the code of go tool link, go build and friends, and the implementation notes of go tool cgo.

  18. debarshiray commented on Jun 9, 2026

    @debarshiray
    Member

    While staring at this issue, I started wondering if we should switch to go build -ldflags "-I $dynamic_linker" instead of the current go build -ldflags "-extldflags '-Wl,-dynamic-linker,$dynamic_linker' -linkmode external" to specify the runtime dynamic linker of the ELF executable (ie., PT_INTERP).

    It seems slightly better because it's not tied to the external linking mode and removes one layer of indirection/quotes/wrapping. In my quick test, it seems to work. What do you think?

    I wonder if -r can similarly replace -rpath, but I haven't tried it.

  19. changed the title [-]failing to compile because it can't lookup undefined symbol nvmlGpuInstanceGetComputeInstanceProfileInfoV[/-] [+]failing to compile when C compiler driver defaults to `-z now`[/+] on Jun 9, 2026
  20. xandris commented on Jun 9, 2026

    @xandris
    Contributor

    that makes sense to me, no need to reinvent the plumbing that cmd/link already has

  21. debarshiray commented on Jun 9, 2026

    @debarshiray
    Member

    that makes sense to me, no need to reinvent the plumbing that cmd/link already has

    Do you want to submit a pull request?

  22. xandris commented on Jun 9, 2026

    @xandris
    Contributor

    sure i can do that when i get home :)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    1. Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions