[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-27 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

--- Comment #13 from H.J. Lu  ---
(In reply to Andi Kleen from comment #12)
> Okay. I only compared gcc-7 (working) vs gcc-9 (broken), but always with LTO.
> 
> Looking at the kernel link it also uses --whole-archive. Perhaps that makes
> a difference?
> 
> I'll redo the test case with --whole-archive (will need some fixes)

--whole-archive makes the difference.

[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-27 Thread andi-gcc at firstfloor dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

--- Comment #12 from Andi Kleen  ---
Okay. I only compared gcc-7 (working) vs gcc-9 (broken), but always with LTO.

Looking at the kernel link it also uses --whole-archive. Perhaps that makes a
difference?

I'll redo the test case with --whole-archive (will need some fixes)

[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-27 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

--- Comment #11 from H.J. Lu  ---
(In reply to Andi Kleen from comment #9)
> I think the STB_SECONDARY stuff is only needed if ld -r is used, but not for
> ar

Linker won't search archive to resolve weak definition. Since SECONDARY is
between WEAK and undefined, linker will keep searching archive for strong
definition to override secondary definition.

[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-27 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

--- Comment #10 from H.J. Lu  ---
(In reply to Andi Kleen from comment #8)
> It works fine without LTO.
> 
> Otherwise the Linux kernel wouldn't work. It relies on this behavior for its
> syscalls.
> 

[hjl@gnu-cfl-2 pr95928]$ make
/usr/gcc-9.3.1-x32/bin/gcc -B./-c -o dummy.o dummy.c
/usr/gcc-9.3.1-x32/bin/gcc -B./  -c sys_ni.i
/usr/gcc-9.3.1-x32/bin/gcc -B./  -c capability.i
/usr/gcc-9.3.1-x32/bin/gcc-ar rc -o libx.a sys_ni.o capability.o
/usr/gcc-9.3.1-x32/bin/gcc -B./ -O2  -o x dummy.o libx.a
/usr/gcc-9.3.1-x32/bin/gcc -B./ -O2  -o y dummy.o sys_ni.o capability.o
objdump --disassemble=__x64_sys_capget x | grep sys_ni_syscall
  401127:   e8 e5 ff ff ff  callq  40 
objdump --disassemble=__x64_sys_capget y | grep sys_ni_syscall
make: *** [Makefile:20: all] Error 1
[hjl@gnu-cfl-2 pr95928]$ 

> The test case is extracted from there.

Something is missing in this testcase.

[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-27 Thread andi-gcc at firstfloor dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

--- Comment #9 from Andi Kleen  ---
I think the STB_SECONDARY stuff is only needed if ld -r is used, but not for ar

[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-27 Thread andi-gcc at firstfloor dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

--- Comment #8 from Andi Kleen  ---
It works fine without LTO.

Otherwise the Linux kernel wouldn't work. It relies on this behavior for its
syscalls.

The test case is extracted from there.

[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-27 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

--- Comment #7 from H.J. Lu  ---
(In reply to H.J. Lu from comment #6)
> It has nothing to do with LTO.  You get the same behavior without LTO.
> This is how weak symbol works.

BTW, this is why I proposed STB_SECONDARY:

https://gcc.gnu.org/legacy-ml/gcc/2012-06/msg00390.html

[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-27 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

H.J. Lu  changed:

   What|Removed |Added

 CC||hjl.tools at gmail dot com

--- Comment #6 from H.J. Lu  ---
It has nothing to do with LTO.  You get the same behavior without LTO.
This is how weak symbol works.

[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-26 Thread andi-gcc at firstfloor dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

--- Comment #5 from Andi Kleen  ---
It doesn't seem to be the plugin itself, I compiled trunk with the gcc-7
lto-plugin.c and it fails too.

[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-26 Thread andi-gcc at firstfloor dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

--- Comment #4 from Andi Kleen  ---
Reproduced on trunk too

11.0-200626  e74c281bf4955eea7fdc5f21b43e29fa0235a5b0

[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-26 Thread andi-gcc at firstfloor dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

--- Comment #3 from Andi Kleen  ---
Versions reproduced:

gcc version 10.1.1 20200507 [revision dd38686d9c810cecbaa80bb82ed91caaa58ad635]
(SUSE Linux) 

gcc-9 (SUSE Linux) 9.3.1 20200406 [revision
6db837a5288ee3ca5ec504fbd5a765817e556ac2]


Version which worked correctly:

gcc version 7.5.0 (SUSE Linux) 



binutils:

GNU ld (GNU Binutils; openSUSE Tumbleweed) 2.34.0.20200325-1

[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-26 Thread andi-gcc at firstfloor dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

--- Comment #1 from Andi Kleen  ---
Created attachment 48792
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48792&action=edit
sys_ni.i

[Bug lto/95928] LTO through ar breaks weak function resolution

2020-06-26 Thread andi-gcc at firstfloor dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95928

--- Comment #2 from Andi Kleen  ---
Created attachment 48793
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48793&action=edit
capability.i