Bug 23079 - Multiple PREVAILING_DEF_IRONLY for a same symbol in an archive
Summary: Multiple PREVAILING_DEF_IRONLY for a same symbol in an archive
Status: RESOLVED WONTFIX
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.31
: P2 normal
Target Milestone: ---
Assignee: H.J. Lu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-18 14:10 UTC by Martin Liska
Modified: 2018-04-19 03:58 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
A patch (709 bytes, patch)
2018-04-19 03:56 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liska 2018-04-18 14:10:01 UTC
Let's consider:

$ cat 1.i
int igt_subtest_jmpbuf, viewport;
$ cat 2.i
int igt_subtest_jmpbuf, viewport;

$ gcc -flto 1.i -c
$ gcc -flto 2.i -c
$ ar cru libx.la 1.o 2.o
$ ranlib libx.la

$ cat main.i
int igt_subtest_jmpbuf;
extern int viewport;
int main()
{
  return igt_subtest_jmpbuf;
}

$ gcc main.i libx.la -flto
lto1: fatal error: multiple prevailing defs for ‘viewport’
compilation terminated.
lto-wrapper: fatal error: gcc returned 1 exit status
compilation terminated.
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

It's caused by fact that:

$ cat main.res
3
main.o 2
190 57d43a0e4f2e4898 PREVAILING_DEF main
194 57d43a0e4f2e4898 PREVAILING_DEF_IRONLY igt_subtest_jmpbuf
libx.la@0xcc 2
188 65b5ba79fd3c2703 PREVAILING_DEF_IRONLY viewport
190 65b5ba79fd3c2703 RESOLVED_IR igt_subtest_jmpbuf
libx.la@0x9d8 2
188 253018f931e7b9de PREVAILING_DEF_IRONLY viewport
190 253018f931e7b9de RESOLVED_IR igt_subtest_jmpbuf

While ld.gold does:
$ cat main.res
cat main.res
1
main.o 2
190 f4c25c288a258244 PREVAILING_DEF main
194 f4c25c288a258244 PREVAILING_DEF_IRONLY igt_subtest_jmpbuf

If I modify main.i to:
$ cat main.i
int igt_subtest_jmpbuf;
extern int viewport;
int main()
{
  return igt_subtest_jmpbuf + viewport;
}

Then it's all fine with BFD resolution file looking as follows:

$ cat main.res
3
main.o 3
190 aa0f078bbef97098 PREVAILING_DEF main
194 aa0f078bbef97098 PREVAILING_DEF_IRONLY igt_subtest_jmpbuf
196 aa0f078bbef97098 RESOLVED_IR viewport
libx.la@0xcc 2
188 65b5ba79fd3c2703 PREVAILING_DEF_IRONLY viewport
190 65b5ba79fd3c2703 RESOLVED_IR igt_subtest_jmpbuf
libx.la@0x9d8 2
188 253018f931e7b9de RESOLVED_IR viewport
190 253018f931e7b9de RESOLVED_IR igt_subtest_jmpbuf
Comment 1 Richard Biener 2018-04-18 14:13:22 UTC
If you make viewport non-common (-fno-common), does that fix it as well?
Comment 2 Martin Liska 2018-04-18 14:16:13 UTC
(In reply to Richard Biener from comment #1)
> If you make viewport non-common (-fno-common), does that fix it as well?

Yes, with res. file as follows:

$ cat main.res
2
main.o 2
190 3e1e8b5023c4516c PREVAILING_DEF main
194 3e1e8b5023c4516c RESOLVED_IR igt_subtest_jmpbuf
libx.la@0xcc 2
188 608e0e444e9214ca PREVAILING_DEF_IRONLY viewport
190 608e0e444e9214ca PREVAILING_DEF_IRONLY igt_subtest_jmpbuf
Comment 3 Jan Hubicka 2018-04-18 16:08:56 UTC
Thanks for isolating this! The diagnostics is new in GCC 8. We may silence it if we agree that choosing random prevailing variant is way to go.

Honza
Comment 4 H.J. Lu 2018-04-18 17:22:53 UTC
I will take a look.
Comment 5 H.J. Lu 2018-04-19 03:41:03 UTC
Gold works only because it treats COMMON symbol like definition:

[hjl@gnu-tools-1 nolto]$ cat main.c
#include <stdio.h>

int igt_subtest_jmpbuf;
int main ()
{
  printf ("igt_subtest_jmpbuf: %d\n", igt_subtest_jmpbuf);
  return 0;
}
[hjl@gnu-tools-1 nolto]$ cat x.i
int igt_subtest_jmpbuf = -1;
[hjl@gnu-tools-1 nolto]$ cat y.i
int igt_subtest_jmpbuf = -2;
[hjl@gnu-tools-1 nolto]$ make
gcc    -c -o main.o main.c
gcc -c  -o x.o x.i
gcc -c  -o y.o y.i
ar rcu -o libx.a x.o y.o
gcc  -o x main.o libx.a
gcc -fuse-ld=gold  -o y main.o libx.a
./x
igt_subtest_jmpbuf: -1
[hjl@gnu-tools-1 nolto]$ ./y
igt_subtest_jmpbuf: 0
[hjl@gnu-tools-1 nolto]$
Comment 6 H.J. Lu 2018-04-19 03:56:04 UTC
Created attachment 10960 [details]
A patch

Try this.
Comment 7 H.J. Lu 2018-04-19 03:58:42 UTC
(In reply to Jan Hubicka from comment #3)
> Thanks for isolating this! The diagnostics is new in GCC 8. We may silence
> it if we agree that choosing random prevailing variant is way to go.
> 

GCC should silence multiple PREVAILING_DEF_IRONLY defs error on COMMON
symbols since it isn't error.