https://sourceware.org/bugzilla/show_bug.cgi?id=30343
Bug ID: 30343 Summary: LTO drops explicitly referenced symbol _pei386_runtime_relocator Product: binutils Version: 2.39 Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: pali at kernel dot org Target Milestone: --- Originally reported on: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369 Points from discussion: * OTOH if the linker(?) introduces such use then it should properly communicate this via the resolution info. That would hint at a binutils bug. * Yes, ld should claim _pei386_runtime_relocator (even if later it becomes unneeded due to zero relocations left to fix up) to make this work properly. That's for Binutils to fix on their side. Original description: When PE runtime-pseudo-reloc is used (e.g. referencing member of global array from DLL library without being marked as dllimport), LTO drops _pei386_runtime_relocator symbol even when it is explicitly referenced from used symbol and then it complains that _pei386_runtime_relocator symbol was dropped. This is a bug because LTO compiler 1) should not drop any symbol which is explicitly referenced from some used symbol and 2) should not drop special _pei386_runtime_relocator symbol when it detected that PE runtime-pseudo-reloc is used. Test case: Create simple DLL library with global array arr[]: $ cat arr.c int arr[2] = { 1, 2 }; $ i686-w64-mingw32-gcc -shared arr.c -o arr.dll Define simple startup file for mingw (so to compile full test case without mingw). Function _pei386_runtime_relocator() is explicitly referenced from the startup function mainCRTStartup(): $ cat startup.c extern void _pei386_runtime_relocator(void); extern int main(); int __main() { } __attribute__((force_align_arg_pointer)) __attribute__((noinline)) static int _mainCRTStartup(void) { _pei386_runtime_relocator(); return main(); } __attribute__((used)) /* required due to bug 109368 */ int mainCRTStartup(void) { return _mainCRTStartup(); } Implement PE runtime-pseudo-reloc. For compile-only purposes (without runtime tests) it can be empty: $ cat pseudo-reloc.c void _pei386_runtime_relocator(void) { } And finally simple test program which uses global array from DLL library which is not explicitly marked with dllimport. $ cat main.c extern int arr[]; int main() { return arr[1]; } Without LTO this example compiles fine: $ i686-w64-mingw32-gcc -Os -nostartfiles -nodefaultlibs -nostdlib startup.c pseudo-reloc.c main.c arr.dll -o test.exe With LTO enabled this example does not compile due to dropping explicitly referenced symbol: $ i686-w64-mingw32-gcc -Os -nostartfiles -nodefaultlibs -nostdlib startup.c pseudo-reloc.c main.c arr.dll -o test.exe -flto `__pei386_runtime_relocator' referenced in section `.rdata' of test_exe_ertr000004.o: defined in discarded section `.text' of /tmp/ccDpfRvt.o (symbol from plugin) collect2: error: ld returned 1 exit status -- You are receiving this mail because: You are on the CC list for the bug.