From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 109D43858D28; Sat, 1 Apr 2023 11:06:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 109D43858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680347219; bh=uc8c00rOJMsqlWqgI9c0pZnjzQugSUuyHSE+gvNBW+Q=; h=From:To:Subject:Date:From; b=Wdk9/Bp//PvAgDlTdaoeO1b3KOwU2mrFOxJ/oTUMeTD6QYDo8FBXmJm3PQBRAyzA7 73SvV1+Fi4ghJj0Adti8MTFtKkz3sabqRnt4JYLiXffY21OiBcvk8vEkdAzPuvlOnJ wSF68tflG90ZHrge/2hhJbWcCVTRzP/lmXE8oit0= From: "pali at kernel dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug lto/109369] New: LTO drops explicitly referenced symbol _pei386_runtime_relocator Date: Sat, 01 Apr 2023 11:06:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: lto X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pali at kernel dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone cf_gcctarget Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109369 Bug ID: 109369 Summary: LTO drops explicitly referenced symbol _pei386_runtime_relocator Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: pali at kernel dot org CC: marxin at gcc dot gnu.org Target Milestone: --- Target: Mingw32 When PE runtime-pseudo-reloc is used (e.g. referencing member of global arr= ay 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-re= loc is used. Test case: Create simple DLL library with global array arr[]: $ cat arr.c int arr[2] =3D { 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 runti= me 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 wh= ich 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/ccDpfRv= t.o (symbol from plugin) collect2: error: ld returned 1 exit status=