public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pali at kernel dot org" <gcc-bugzilla@gcc.gnu.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	[thread overview]
Message-ID: <bug-109369-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2023-04-01 11:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-01 11:06 pali at kernel dot org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-109369-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).