dmd
dmd copied to clipboard
Link failed due to --gc-sections begin enabled by default
When trying to link any program, the error message below appears.
This is DMD64 D Compiler v2.112.0-beta.1 running on Linux.
The compiler command used as the linker is clang, which in turn invokes lld.
The problem is resolved if dmd explicity passed --no-gc-sections to the linker.
see https://github.com/OpenMandrivaAssociation/dmd/blob/88afa4d72ed721e5b1175e2fff11be7bc5d63320/no-gc-sections.patch
ld.lld: error: undefined hidden symbol: __stop_minfo
>>> referenced by example.d
>>> example.o:(.text.d_dso_init+0x7)
ld.lld: error: undefined hidden symbol: __start_minfo
>>> referenced by example.d
>>> example.o:(.text.d_dso_init+0xf)
>>> the encapsulation symbol needs to be retained under --gc-sections properly; consider -z nostart-stop-gc (see https://lld.llvm.org/ELF/start-stop-gc)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: linker exited with status 1
clang example.o -o example -m64 -Xlinker --export-dynamic -L/opt/dlang/src/dmd2/linux/bin64/../lib64 -Xlinker -Bstatic -lphobos2 -Xlinker -Bdynamic -lpthread -lm -lrt -ldl