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
If you make viewport non-common (-fno-common), does that fix it as well?
(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
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
I will take a look.
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]$
Created attachment 10960 [details] A patch Try this.
(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.