-
-
Notifications
You must be signed in to change notification settings - Fork 448
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
Link failure with LTOed toolchain binaries #977
Comments
With this gcc patch:
(disables LTO on crt files) I'm not sure if that's the right thing to do though |
Could you try to extract the linker inputs? There are a few ways to do this:
|
Sure, but the inputs of which part? |
The app that fails to link. |
Oh, that's handy, nice switch! |
In case the cmdline in not in there:
|
OK, I see the problem now. @rui314 I guess we need to add more special casing to https://github.com/rui314/mold/blob/main/elf/mold.h#L2472-L2492? Although I don't know what's the best pattern to match this against. Edit: In additional to the special casing, we also need the reference to this symbol to resolve, which currently doesn't after the changes from #810. Maybe we could defer setting is_alive like we did for mergeable sections. |
Thanks for looking into it! |
I'm not sure why this case causes an undefined symbol error while other symbols referring to an input |
OK, I see it now, so the crtstuff itself is compiled with LTO bitcode and that's why GCC is trying to move stuff around. The reason BFD handles it fine is probably because it follows the normal ELF rule for resolving symbols in .eh_frame; mold on the other hand runs with the assumption that symbols does not reside within .eh_frame and only special case when they are really needed. Now, usually, the Is LTOed C runtime a supported use case by GCC? Looking at the linked bug reports, I wonder if LTOed C runtime can cause you to run into other issues apart from this one. |
I wouldn't say not supported. The bug was acknowledged, just won't get fixed in the near future. No idea if there're other scenarios where this might hit. |
To be clear, this is a tricky problem. We parse individual .eh_frame entries and reconstruct when doing output to achieve deduplication and garbage collection: Line 332 in 51845ac
Since each input object has a single .eh_frame section, instead of being split by their logical boundary, symbols referring to a middle of .eh_frame section have ambiguous meaning wrt reordering and compaction. That’s basically why we have a specific whitelist of symbols that are matched against and resolves to either begin or end of .eh_frame. That said, it shouldn’t be hard to make cross module eh_frame symbols to resolve, and if everything else is working for you, it makes sense to have this supported in mold. I’ll draft a patch next week. |
Alright, feel free to ping me and I'll give it a spin! |
Hi, mind trying https://github.com/ishitatsuyuki/mold/tree/lto-eh-frame and see if it works for you? |
Thanks, I applied both of your patches on top of v1.10.1 but that doesn't fix it. |
No, only the two commits are relevant. I probably have a coding error somewhere. It's a little bit tricky to test LTO linking on my end, though, as the toolchain LTO plugin needs to be invoked here and there's no sane way for I'll re-check the code to see if I'm missing something, but in the meanwhile, if you have a good way to let me repro the issue locally, let me know. (e.g. full toolchain build instructions, or your prebuilt toolchain binary + link command would help) |
Here's a packaged toolchain for a x64 linux host with LTOed target libraries: https://ufile.io/hg6f694m
Does that work for you? |
Thanks, I can reproduce. I'll debug it on my end. |
I pushed a new version to the branch (also filed #1004). Could you test if the compiled binaries work? |
When using a gcc (v12.2.0) cross compiler which was build with:
CFLAGS_FOR_TARGET="-flto=auto -ffat-lto-objects"
LDFLAGS_FOR_TARGET="-flto=auto -fuse-linker-plugin"
(There's https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108630, so add
--enable-symvers=no
for now too if attempting that).I see link errors when building various programs that link libgcc/libatomic/libc/etc:
mold: error: undefined symbol: __EH_FRAME_BEGIN__.lto_priv.0
I haven't digged further, so didn't find out what combinations trigger this.
I don't know if the existence of symbols with a name of
__EH_FRAME_BEGIN__.lto_priv.0
is a toolchain bug, or how useful LTOing the cross toolchain's target libraries even is, but the fact is that bfd links the programs in question while mold errors out.This is the only hit for
lto_priv
in the gcc source: https://github.com/gcc-mirror/gcc/blob/master/gcc/lto/lto-partition.cc#L950It sounds like mold may need support for "LTO privatized symbols"?
The text was updated successfully, but these errors were encountered: