public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug lto/109369] New: LTO drops explicitly referenced symbol _pei386_runtime_relocator
@ 2023-04-01 11:06 pali at kernel dot org
  2023-04-01 11:52 ` [Bug lto/109369] " pinskia at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: pali at kernel dot org @ 2023-04-01 11:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369

            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 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-04-13  7:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-01 11:06 [Bug lto/109369] New: LTO drops explicitly referenced symbol _pei386_runtime_relocator pali at kernel dot org
2023-04-01 11:52 ` [Bug lto/109369] " pinskia at gcc dot gnu.org
2023-04-01 12:29 ` amonakov at gcc dot gnu.org
2023-04-01 12:30 ` jakub at gcc dot gnu.org
2023-04-01 12:34 ` pali at kernel dot org
2023-04-01 12:42 ` amonakov at gcc dot gnu.org
2023-04-11 11:57 ` rguenth at gcc dot gnu.org
2023-04-11 12:49 ` amonakov at gcc dot gnu.org
2023-04-11 18:20 ` pali at kernel dot org
2023-04-13  6:25 ` amonakov at gcc dot gnu.org
2023-04-13  7:13 ` pali at kernel dot org
2023-04-13  7:56 ` xry111 at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).