-
-
Notifications
You must be signed in to change notification settings - Fork 260
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
ELF: __minfo
global variables may be garbage collected by ld.lld>=13.0.0 if built with llvm-project<13.0.0
#3861
Comments
This removes an abuse of ELF linker behaviors while keeping Mach-O/COFF/WebAssembly linker behaviors unchanged. LLD 13.0.0 (default) and GNU ld 2.37 support `-z start-stop-gc` which enables the linker to linker to garbage collect unreferenced C identifier name sections in the presence of `__start_/__stop_`. The `__minfo` section is otherwise unreferenced and may be garbage collected. Add the global variables to `llvm.used` can prevent garbage collection. Fixes ldc-developers#3861
__minfo
global variables are garbage collected by ld.lld>=13.0.0__minfo
global variables may be garbage collected by ld.lld>=13.0.0 if built with llvm-project<13.0.0
Would it help if we always pass |
The problem is that ld.lld errors for unknown % ld.bfd -z nostart-stop-gc a.o
ld.bfd: warning: cannot find entry symbol _start; defaulting to 0000000000401000
% ld.bfd -z unknown a.o
ld.bfd: warning: -z unknown ignored
ld.bfd: warning: cannot find entry symbol _start; defaulting to 0000000000401000
% ~/llvm-prebuilt/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/ld.lld -z nostart-stop-gc a.o
ld.lld: error: unknown -z value: nostart-stop-gc Perhaps @lwhsu can tag the https://www.freshports.org/lang/ldc maintainer here. |
I've seen these failures with lld v13; it's somehow fixed by declaring the start/stop symbols in one object file instead of each object file (and, FWIW, as IR constants if that makes a difference), in #3850 (comment). |
This has come up for GDC on OpenBSD, is this confirmed to be fixed now? |
Yeah well nowadays we only support LLVM 15+, with 'proper' |
I maintain lld/ELF nowadays. Sorry for your inconvenience but for the benefit of better garbage collection for metadata sections (PGO/sanitizer and more future instrumentation), I changed a garbage collection rule in LLD 13.0.0 (https://releases.llvm.org/13.0.0/tools/lld/docs/ReleaseNotes.html):
A
__start___minfo
reference from a live input section no longer keeps a__minfo
section live.(The topic is complex. You may read https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order#garbage-collection-on-metadata-sections for more information.)
FreeBSD is trying to upgrade its
/usr/bin/ld
to LLD 13.0.0. If ldc is built with llvm-project<13.0.0 when host ld.lld >= 13.0.0, there can be breakage:-z start-stop-gc
and discards unreferenced__minfo
sections.__minfo
section will be retained if it has theSHF_GNU_RETAIN
flag.llvm.used
does not setSHF_GNU_RETAIN
flag.Some fixes:
LDC_LLVM_VER < 1300 && ld.lld >= 13.0.0
, pass-z nostart-stop-gc
. This can be a CMake-time check.__minfo
in a section group with aSHT_INIT_ARRAY
section. This is a hack which should retire ASAP.--gc-sections
ld64 on Mach-O behaves similar to
ld.lld -z nostart-stop-gc
in the presence of-dead_strip
.The text was updated successfully, but these errors were encountered: