The bug is originally discovered by Fabio Coatti in https://bugs.gentoo.org/682018. There isl-0.21 fails to link when built with CFLAGS="-O2 -flto=4 -pipe" LDFLAGS="${CFLAGS}". The trigger is all.c file name in isl source three. It gets translated to all.o. Here is the minimal reproducer: $ cat foo.bash #!/bin/bash export LANG=C cc=gcc mk() { local flag=$1 rm -rf -- *.o *.so* ${cc} ${flag} -fPIC -c all.c -o all.o ${cc} ${flag} -fPIC -c isl.c -o isl.o # Note: all.o is not used here and yet in interferes with -flto=4 ${cc} ${flag} -fPIC -shared isl.o -o libisl.so } # empty files are enough to trigger a bug touch all.c isl.c echo "=== -flto=1 (works) ===" mk "-flto=1" echo "=== -flto=4 (fails) ===" mk "-flto=4" Running: $ ./foo.bash === -flto=1 (works) === === -flto=4 (fails) === /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../lib64/../lib64/Scrt1.o: in function `_start': /usr/src/debug/sys-libs/glibc-2.29-r1/glibc-2.29/csu/../sysdeps/x86_64/start.S:104: undefined reference to `main' collect2: error: ld returned 1 exit status make: *** [<builtin>: all] Error 1 lto-wrapper: fatal error: make returned 2 exit status compilation terminated. /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed collect2: error: ld returned 1 exit status Note: all.o is never passed to gcc as an input. And yet it's presence interferes with the driver.
It seems that 'all.c' is actual trigger, not 'all.o'.
Confirmed, minimal reproducer: $ echo "" | gcc -shared -fPIC -flto=2 -x c - /usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/8/../../../../lib64/../lib64/crt1.o: in function `_start': /home/abuild/rpmbuild/BUILD/glibc-2.29/csu/../sysdeps/x86_64/start.S:104: undefined reference to `main' collect2: error: ld returned 1 exit status make: *** [<builtin>: all] Error 1 lto-wrapper: fatal error: make returned 2 exit status compilation terminated. /usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: error: lto-wrapper failed collect2: error: ld returned 1 exit status Looks to me a LD issue. @H.J. can you please take a look?
It seems to be make looking for all.c via the LTRANS makefile and us invoking make -f /tmp/ccfGbAMc.mk -j2 all /tmp/cczwBPXD.ltrans0.ltrans.o: @gcc-8 '-xlto' '-c' '-fno-openmp' '-fno-openacc' '-mtune=generic' '-march=x86-64' '-fPIC' '-shared' '-fPIC' '-v' '-save-temps' '-mtune=generic' '-march=x86-64' '-fltrans-output-list=/tmp/cczwBPXD.ltrans.out' '-fltrans' '-o' '/tmp/cczwBPXD.ltrans0.ltrans.o' '/tmp/cczwBPXD.ltrans0.o' all: \ /tmp/cczwBPXD.ltrans0.ltrans.o which eventually leads to 4924 execve("/usr/bin/cc", ["cc", "all.c", "/tmp/cczwBPXD.ltrans0.ltrans.o", "-o", "all"], [/* 107 vars */]) = 0 if you make all.c invalid C then you see > gcc-8 -shared -fPIC -flto=2 -x c t.c all.c:1:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input invalid ^~~~~~~ make: *** [all] Error 1 lto-wrapper: fatal error: make returned 2 exit status compilation terminated.
Index: gcc/lto-wrapper.c =================================================================== --- gcc/lto-wrapper.c (revision 270053) +++ gcc/lto-wrapper.c (working copy) @@ -1671,7 +1671,7 @@ cont: int j = ltrans_priorities[i*2 + 1]; fprintf (mstream, " \\\n\t%s", output_names[j]); } - fprintf (mstream, "\n"); + fprintf (mstream, "\n\t@:\n"); fclose (mstream); if (!jobserver) { fixes this, adding an empty rule to the all target: /tmp/ccZYd6M0.ltrans0.ltrans.o: @gcc-8 '-xlto' '-c' '-fno-openmp' '-fno-openacc' '-mtune=generic' '-march=x86-64' '-fPIC' '-shared' '-fPIC' '-B' '/abuild/rguenther/trunk2-g/gcc' '-v' '-save-temps' '-mtune=generic' '-march=x86-64' '-fltrans-output-list=/tmp/ccZYd6M0.ltrans.out' '-fltrans' '-o' '/tmp/ccZYd6M0.ltrans0.ltrans.o' '/tmp/ccZYd6M0.ltrans0.o' all: \ /tmp/ccZYd6M0.ltrans0.ltrans.o @:
$ gcc -shared -fPIC -flto=4 -o x.so isl.o -v ... make -f /tmp/ccj2DsQs.mk -j4 all ^^^ ... /usr/local/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/../lib64/crt1.o: in function `_start': (.text+0x24): undefined reference to `main' collect2: error: ld returned 1 exit status make: *** [<builtin>: all] Error 1 lto-wrapper: fatal error: make returned 2 exit status Since all.c matches the target "all", make tries to create "all".
Just make the target .PHONY.
Author: rguenth Date: Wed Apr 3 08:46:00 2019 New Revision: 270112 URL: https://gcc.gnu.org/viewcvs?rev=270112&root=gcc&view=rev Log: 2019-04-03 Richard Biener <rguenther@suse.de> PR lto/89896 * lto-wrapper.c (run_gcc): Avoid implicit rules making the all target phony. Modified: trunk/gcc/ChangeLog trunk/gcc/lto-wrapper.c
Author: rguenth Date: Wed Apr 3 08:46:35 2019 New Revision: 270113 URL: https://gcc.gnu.org/viewcvs?rev=270113&root=gcc&view=rev Log: 2019-04-03 Richard Biener <rguenther@suse.de> PR lto/89896 * lto-wrapper.c (run_gcc): Avoid implicit rules making the all target phony. Modified: branches/gcc-8-branch/gcc/ChangeLog branches/gcc-8-branch/gcc/lto-wrapper.c
Fixed.
Author: rguenth Date: Wed Apr 3 08:47:19 2019 New Revision: 270114 URL: https://gcc.gnu.org/viewcvs?rev=270114&root=gcc&view=rev Log: 2019-04-03 Richard Biener <rguenther@suse.de> PR lto/89896 * lto-wrapper.c (run_gcc): Avoid implicit rules making the all target phony. Modified: branches/gcc-7-branch/gcc/ChangeLog branches/gcc-7-branch/gcc/lto-wrapper.c