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
* [Bug lto/109369] LTO drops explicitly referenced symbol _pei386_runtime_relocator
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 ` pinskia at gcc dot gnu.org
2023-04-01 12:29 ` amonakov at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-01 11:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |lto
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This could be a binutils issue rather than a GCC lto issue too.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug lto/109369] LTO drops explicitly referenced symbol _pei386_runtime_relocator
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
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: amonakov at gcc dot gnu.org @ 2023-04-01 12:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369
Alexander Monakov <amonakov at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amonakov at gcc dot gnu.org
--- Comment #2 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
GCC inlines _pei386_runtime_relocator and doesn't emit it because it doesn't
know that it's also referenced implicitly.
Does _pei386_runtime_relocator need to participate in LTO at all? If not, I'd
suggest moving it to a separate file that is compiled with -fno-lto.
If the linker can decide if it's needed only after seeing all post-LTO objects,
that might be the only solution.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug lto/109369] LTO drops explicitly referenced symbol _pei386_runtime_relocator
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
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-04-01 12:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
There is always __attribute__((used))
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug lto/109369] LTO drops explicitly referenced symbol _pei386_runtime_relocator
2023-04-01 11:06 [Bug lto/109369] New: LTO drops explicitly referenced symbol _pei386_runtime_relocator pali at kernel dot org
` (2 preceding siblings ...)
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
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pali at kernel dot org @ 2023-04-01 12:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369
--- Comment #4 from Pali Rohár <pali at kernel dot org> ---
I wanted to point that marking _pei386_runtime_relocator() function with
__attribute__((used)) is working fine.
And whether _pei386_runtime_relocator() should participate in LTO at all? I
would rather ask, why not? Is there any specific reason why
_pei386_runtime_relocator() should not be compiled with LTO? I would expect
from gcc/ld that whole application can be compiled with LTO.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug lto/109369] LTO drops explicitly referenced symbol _pei386_runtime_relocator
2023-04-01 11:06 [Bug lto/109369] New: LTO drops explicitly referenced symbol _pei386_runtime_relocator pali at kernel dot org
` (3 preceding siblings ...)
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
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: amonakov at gcc dot gnu.org @ 2023-04-01 12:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369
--- Comment #5 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
Indeed, sorry, __attribute__((used)) seems a much better solution for symbols
that might be referenced implicitly, in a manner that LTO plugin cannot see.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug lto/109369] LTO drops explicitly referenced symbol _pei386_runtime_relocator
2023-04-01 11:06 [Bug lto/109369] New: LTO drops explicitly referenced symbol _pei386_runtime_relocator pali at kernel dot org
` (4 preceding siblings ...)
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
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-11 11:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Alexander Monakov from comment #5)
> Indeed, sorry, __attribute__((used)) seems a much better solution for
> symbols that might be referenced implicitly, in a manner that LTO plugin
> cannot see.
OTOH if the linker(?) introduces such use then it should properly communicate
this via the resolution info. That would hint at a binutils bug.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug lto/109369] LTO drops explicitly referenced symbol _pei386_runtime_relocator
2023-04-01 11:06 [Bug lto/109369] New: LTO drops explicitly referenced symbol _pei386_runtime_relocator pali at kernel dot org
` (5 preceding siblings ...)
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
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: amonakov at gcc dot gnu.org @ 2023-04-11 12:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369
--- Comment #7 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
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.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug lto/109369] LTO drops explicitly referenced symbol _pei386_runtime_relocator
2023-04-01 11:06 [Bug lto/109369] New: LTO drops explicitly referenced symbol _pei386_runtime_relocator pali at kernel dot org
` (6 preceding siblings ...)
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
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pali at kernel dot org @ 2023-04-11 18:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369
--- Comment #8 from Pali Rohár <pali at kernel dot org> ---
So from the discussion, do I understand correctly that this is rather LD linker
issue?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug lto/109369] LTO drops explicitly referenced symbol _pei386_runtime_relocator
2023-04-01 11:06 [Bug lto/109369] New: LTO drops explicitly referenced symbol _pei386_runtime_relocator pali at kernel dot org
` (7 preceding siblings ...)
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
10 siblings, 0 replies; 12+ messages in thread
From: amonakov at gcc dot gnu.org @ 2023-04-13 6:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369
--- Comment #9 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
(In reply to Pali Rohár from comment #8)
> So from the discussion, do I understand correctly that this is rather LD
> linker issue?
Yes, ld changes will be needed to make this work automatically, without adding
the attribute manually. I would suggest to move the bug to the Binutils
Bugzilla.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug lto/109369] LTO drops explicitly referenced symbol _pei386_runtime_relocator
2023-04-01 11:06 [Bug lto/109369] New: LTO drops explicitly referenced symbol _pei386_runtime_relocator pali at kernel dot org
` (8 preceding siblings ...)
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
10 siblings, 0 replies; 12+ messages in thread
From: pali at kernel dot org @ 2023-04-13 7:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369
--- Comment #10 from Pali Rohár <pali at kernel dot org> ---
> I would suggest to move the bug to the Binutils Bugzilla.
Done: https://sourceware.org/bugzilla/show_bug.cgi?id=30343
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug lto/109369] LTO drops explicitly referenced symbol _pei386_runtime_relocator
2023-04-01 11:06 [Bug lto/109369] New: LTO drops explicitly referenced symbol _pei386_runtime_relocator pali at kernel dot org
` (9 preceding siblings ...)
2023-04-13 7:13 ` pali at kernel dot org
@ 2023-04-13 7:56 ` xry111 at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-04-13 7:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109369
Xi Ruoyao <xry111 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |xry111 at gcc dot gnu.org
Resolution|--- |MOVED
URL| |https://sourceware.org/bugz
| |illa/show_bug.cgi?id=30343
Status|UNCONFIRMED |RESOLVED
--- Comment #11 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Moved.
^ 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).