Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys-apps/nix and app-text/lowdown-nix fail to link with CFLAGS=-flto: ld: ...ccsAsSAj.ltrans0.ltrans.o:(.debug_info+0x2f): undefined reference to `document.c....' #19

Closed
drnfc opened this issue Jun 6, 2022 · 12 comments

Comments

@drnfc
Copy link

drnfc commented Jun 6, 2022

Not sure if this is the right place to ask this, but I am having issues emerging nix.
here's my portage build log:

https://pastebin.com/VYV27NJR

things I've tried:

  • disabling LTO
  • installing nix v2.8.1
@trofi
Copy link
Owner

trofi commented Jun 6, 2022

It's the right place. Welcome! :) Let's try to figure out why it fails.

Is it a fresh sys-apps/nix install? Or an upgrade of some existing version? I'll try to reproduce locally as well.

Posting build snippet here to ease the search:

$ x86_64-pc-linux-gnu-g++ -o /var/tmp/portage/sys-apps/nix-2.9.0/image/usr/lib64/libnixcmd.so -shared  -L/var/tmp/portage/sys-apps/nix-2.9.0/image/usr/lib64 -lnixstore -Wl,-rpath,/usr/lib64  -L/var/tmp/portage/sys-apps/nix-2.9.0/image/usr/lib64 -lnixutil -Wl,-rpath,/usr/lib64  -L/var/tmp/portage/sys-apps/nix-2.9.0/image/usr/lib64 -lnixexpr -Wl,-rpath,/usr/lib64 -latomic_ops -lgc -lpthread -ldl  -L/var/tmp/portage/sys-apps/nix-2.9.0/image/usr/lib64 -lnixmain -Wl,-rpath,/usr/lib64  -L/var/tmp/portage/sys-apps/nix-2.9.0/image/usr/lib64 -lnixfetchers -Wl,-rpath,/usr/lib64 -L/usr/lib64 -Wl,-O1 -Wl,--as-needed -Wl,--no-copy-dt-needed-entries src/libcmd/command.o src/libcmd/common-eval-args.o src/libcmd/installables.o src/libcmd/legacy.o src/libcmd/markdown.o src/libcmd/repl.o -leditline -L/usr/lib64/lowdown-nix/lib -llowdown -lm -pthread -Wl,-z,defs -Wl,-soname=libnixcmd.so 
/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /var/tmp/portage/sys-apps/nix-2.9.0/temp/ccP05pSk.ltrans0.ltrans.o:(.debug_info+0x2f): undefined reference to `buffer.c.69cd1d9b'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /var/tmp/portage/sys-apps/nix-2.9.0/temp/ccP05pSk.ltrans0.ltrans.o:(.debug_info+0x4a): undefined reference to `buffer.c.69cd1d9b'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /var/tmp/portage/sys-apps/nix-2.9.0/temp/ccP05pSk.ltrans0.ltrans.o:(.debug_info+0x57): undefined reference to `buffer.c.69cd1d9b'
...

@drnfc
Copy link
Author

drnfc commented Jun 6, 2022

It is a fresh install, and wow, thanks for the quick response

@trofi
Copy link
Owner

trofi commented Jun 6, 2022

While nix itself is being built without LTO one of it's library depends does build with LTO and final driver fails to resolve it: buffer.c.69cd1d9b. That usually happens if one of libraries is statically linked.

It likely comes from /usr/lib64/lowdown-nix/lib/liblowdown.a from app-text/lowdown-nix (it does not provide dynamic library equivalent). As a workaround you can try rebuilding it without LTO as well and see if it helps.

Or if you suspect app-text/lowdown-nix was built before a compiler upgrade you can just rebuild it first and see if it's enough.

@trofi
Copy link
Owner

trofi commented Jun 6, 2022

Meanwhile I reproduced locally similar failure with -flto:

# CFLAGS="-O2 -flto" CXXFLAGS="-O2 -flto" LDFLAGS="-O2 -flto" emerge -v1 app-text/lowdown-nix sys-apps/nix
...
x86_64-pc-linux-gnu-g++ -o /dev/shm/portage/sys-apps/nix-2.9.0/image/usr/lib64/libnixcmd.so -shared  -L/dev/shm/portage/sys-apps/nix-2.9.0/image/usr/lib64 -lnixstore -Wl,-rpath,/usr/lib64  -L/dev/shm/portage/sys-apps/nix-2.9.0/image/usr/lib64 -lnixutil -Wl,-rpath,/usr/lib64  -L/dev/shm/portage/sys-apps/nix-2.9.0/image/usr/lib64 -lnixexpr -Wl,-rpath,/usr/lib64 -latomic_ops -lgc -lpthread -ldl  -L/dev/shm/portage/sys-apps/nix-2.9.0/image/usr/lib64 -lnixmain -Wl,-rpath,/usr/lib64  -L/dev/shm/portage/sys-apps/nix-2.9.0/image/usr/lib64 -lnixfetchers -Wl,-rpath,/usr/lib64 -L/usr/lib64 -O2 -flto -Wl,--no-copy-dt-needed-entries src/libcmd/command.o src/libcmd/common-eval-args.o src/libcmd/installables.o src/libcmd/legacy.o src/libcmd/markdown.o src/libcmd/repl.o -leditline -L/usr/lib64/lowdown-nix/lib -llowdown -lm -pthread -Wl,-z,defs -Wl,-soname=libnixcmd.so
/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../x86_64-pc-linux-gnu/bin/ld: /dev/shm/portage/sys-apps/nix-2.9.0/temp/ccsAsSAj.ltrans0.ltrans.o:(.debug_info+0x2f): undefined reference to `document.c.7180b45a'
/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../x86_64-pc-linux-gnu/bin/ld: /dev/shm/portage/sys-apps/nix-2.9.0/temp/ccsAsSAj.ltrans0.ltrans.o:(.debug_info+0x4a): undefined reference to `document.c.7180b45a'
/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../x86_64-pc-linux-gnu/bin/ld: /dev/shm/portage/sys-apps/nix-2.9.0/temp/ccsAsSAj.ltrans0.ltrans.o:(.debug_info+0x57): undefined reference to `document.c.7180b45a'
/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../x86_64-pc-linux-gnu/bin/ld: /dev/shm/portage/sys-apps/nix-2.9.0/temp/ccsAsSAj.ltrans0.ltrans.o:(.debug_info+0x64): undefined reference to `document.c.7180b45a'

Looking as well.

@trofi trofi changed the title emake failed sys-apps/nix and app-text/lowdown-nix fail to link with CFLAGS=-flto: ld: ...ccsAsSAj.ltrans0.ltrans.o:(.debug_info+0x2f): undefined reference to `document.c....' Jun 6, 2022
@drnfc
Copy link
Author

drnfc commented Jun 6, 2022

completely disabling lto and recompiling lowdown-nix fixed my issue. Now I just got to figure out the minimum number of settings to change and I'll report to the lto-overlay, as this is an LTO issue, not a nix one. Thanks for the help.

@drnfc drnfc closed this as completed Jun 6, 2022
@trofi
Copy link
Owner

trofi commented Jun 6, 2022

Adding FEATURES="nostrip" when building lowdonw-nix is enough to restore LTO build. I guess it's a form of https://bugs.gentoo.org/603594. Do you have AR=gcc-ar RANLIB=gcc-ranlib or equivalent set in your environment? (emerge --info app-text/lowdown-nix should tell)

@drnfc
Copy link
Author

drnfc commented Jun 6, 2022

no I don't seem to have those set in my environment.

@trofi
Copy link
Owner

trofi commented Jun 6, 2022

Maybe it's OK. Chances are that binutils automatically discover linker plugin and use it.

@trofi
Copy link
Owner

trofi commented Jun 6, 2022

Gentoo uses the following to strip files:

strip: x86_64-pc-linux-gnu-strip --strip-unneeded -N __gentoo_check_ldflags__ -R .comment -R .GCC.command.line -R .note.gnu.gold-version

   /usr/lib64/lowdown-nix/bin/lowdown
   /usr/lib64/lowdown-nix/bin/lowdown-diff
   /usr/lib64/lowdown-nix/lib/liblowdown.a

x86_64-pc-linux-gnu-strip: /dev/shm/portage/app-text/lowdown-nix-1.0.0/image/usr/lib64/lowdown-nix/lib/stPl3K5x/autolink.o: plugin needed to handle lto object

I think it hints at missing plugin load. Worth exploring if strip --strip-unneeded is supposed to keep .o files alive after stripping. I suspect it does not interact that well with LTO bytecode.

@trofi
Copy link
Owner

trofi commented Jun 6, 2022

Gentoo uses the following to strip files:

strip: x86_64-pc-linux-gnu-strip --strip-unneeded -N __gentoo_check_ldflags__ -R .comment -R .GCC.command.line -R .note.gnu.gold-version

   /usr/lib64/lowdown-nix/bin/lowdown
   /usr/lib64/lowdown-nix/bin/lowdown-diff
   /usr/lib64/lowdown-nix/lib/liblowdown.a

x86_64-pc-linux-gnu-strip: /dev/shm/portage/app-text/lowdown-nix-1.0.0/image/usr/lib64/lowdown-nix/lib/stPl3K5x/autolink.o: plugin needed to handle lto object

The log is misleading. Those strip flags are used only for ELF files. .a files followdifferent path:

+ x86_64-pc-linux-gnu-strip -g /dev/shm/portage/app-text/lowdown-nix-1.0.0/image/usr/lib64/lowdown-nix/lib/liblowdown.a
x86_64-pc-linux-gnu-strip: /dev/shm/portage/app-text/lowdown-nix-1.0.0/image/usr/lib64/lowdown-nix/lib/st9KFBGP/autolink.o: plugin needed to handle lto object
+ gcc-ranlib /dev/shm/portage/app-text/lowdown-nix-1.0.0/image/usr/lib64/lowdown-nix/lib/liblowdown.a

Looking at the binutils source only ar and nm can autoload LTO plugins. I think it's expected that FEATURES=strip (uses strip) and FEATURES=splitdebug (uses objcopy) both can break LTO .a archives.

What I'm not sure about is whether strip -g is guaranteed to work on .a/.o files. I could see how LTO's dwarf sections could contain not just debug info.

https://sourceware.org/PR21479 implies it might work, but is a "minefield".

@trofi
Copy link
Owner

trofi commented Jun 7, 2022

Filed https://gcc.gnu.org/PR105877 to see if we can clarify it upstream.

trofi added a commit that referenced this issue Jun 7, 2022
By default portage runs 'strip -g' on .a files.
This is known to break liblowdown.a when it's built with -flto:
  #19
Chances are it's a toolchain bug (or a limitation of LTO):
  https://gcc.gnu.org/PR105877

Reported-by: drnfc
Bug: https://gcc.gnu.org/PR105877
Closes: #19
@trofi
Copy link
Owner

trofi commented Jun 8, 2022

Meanwhile f9afe32 should allow building nix with lto.

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

No branches or pull requests

2 participants