[Bug lto/69271] LTO drops weak binding from aliases
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69271 --- Comment #8 from Jan Hubicka --- Ok, compiling: int bar = 0; extern int bar_alias __attribute__((weak, alias("bar"))); main() { printf ("%i %i\n",bar,bar_alias); } as a static library leads to no dynamic relocations, but compiling as shared we get bar_alias still declared weak which affects the dynamic linking (because it can be replaced by strong definition which come later in the linking process). So all we need to do is to avoid turning WEAK to non-WEAK for non-hidden symbols when building with PIC?
[Bug lto/69271] LTO drops weak binding from aliases
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69271 --- Comment #4 from Jan Hubicka --- The optimization was intentional - dropping the weak bit makes GCC to optimize the references to symbol better (knowing it won't be NULL because the definition is provided). I wonder how this break glibc. What is the difference between weak and non-weak symbols in dynamic linking?
[Bug lto/69271] LTO drops weak binding from aliases
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69271 --- Comment #5 from nsz at gcc dot gnu.org --- copy pasting from http://www.openwall.com/lists/musl/2016/01/13/2 (this is musl libc, but glibc has the same issue) lto breaks symbol binding for environ, _environ, ___environ. (they should be weak, without that environ in a main binary has different address than in libc.so) libc.so built with -flto: $ readelf --dyn-syms -W libc.so |grep envi 22: 0028eb90 8 OBJECT GLOBAL DEFAULT 15 __environ 398: 0028eb90 8 OBJECT GLOBAL PROTECTED 15 ___environ 1034: 0028eb90 8 OBJECT GLOBAL PROTECTED 15 _environ 1107: 0028eb90 8 OBJECT GLOBAL DEFAULT 15 environ libc.so without -flto: $ readelf --dyn-syms -W libc.so |grep envi 22: 0028d2d8 8 OBJECT GLOBAL DEFAULT 15 __environ 398: 0028d2d8 8 OBJECT WEAK PROTECTED 15 ___environ 1034: 0028d2d8 8 OBJECT WEAK PROTECTED 15 _environ 1107: 0028d2d8 8 OBJECT WEAK DEFAULT 15 environ
[Bug lto/69271] LTO drops weak binding from aliases
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69271 Jan Hubicka changed: What|Removed |Added Status|UNCONFIRMED |ASSIGNED Last reconfirmed||2016-01-15 Assignee|unassigned at gcc dot gnu.org |hubicka at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #3 from Jan Hubicka --- mine. I wonder why WEAK makes difference here at all when all symbols are interposable with PIC.
[Bug lto/69271] LTO drops weak binding from aliases
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69271 --- Comment #6 from nsz at gcc dot gnu.org --- to complete the example here is a test application: #include #include extern char **environ; int main() { printf(": %p, environ: %p, *environ: %p\n", , environ, *environ); clearenv(); // *environ = 0 putenv("TEST=1"); // should change environ printf(": %p, environ: %p, *environ: %p\n", , environ, *environ); } with correct libc.so: $ gcc a.c $ ./a.out : 0x6008b0, environ: 0x7fffb9b0b478, *environ: 0x7fffb9b0d651 : 0x6008b0, environ: 0x600020, *environ: 0x400649 $ readelf --dyn-sym -W ./a.out |grep envi 2: 006008b0 8 OBJECT WEAK DEFAULT 19 _environ 5: 006008b0 8 OBJECT GLOBAL DEFAULT 19 __environ 7: 006008b0 8 OBJECT WEAK DEFAULT 19 environ 8: 006008b0 8 OBJECT WEAK DEFAULT 19 ___environ if libc.so is compiled with -flto: $ gcc a.c $ ./a.out : 0x600850, environ: 0x7fff52af6158, *environ: 0x7fff52af6651 : 0x600850, environ: 0x7fff52af6158, *environ: 0 $ readelf --dyn-sym -W ./a.out |grep envi 5: 00600850 8 OBJECT GLOBAL DEFAULT 19 environ so environ is shared between a.out and libc.so in the beginning (clearenv worked), but the address of the symbol () is different so changing it in the libc did not have an effect in the main module (putenv failed). this might be an issue in the static or dynamic linker but the difference is observable.
[Bug lto/69271] LTO drops weak binding from aliases
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69271 Rich Felker changed: What|Removed |Added CC||bugdal at aerifal dot cx --- Comment #7 from Rich Felker --- Jan Hubicka, when ld resolves a reference that requires a copy relocation to a weak definition in a shared library, it searches for a strong symbol for which the weak definition is an alias, and replaces the reference with one to the strong symbol. This is necessary to ensure that _alias == _sym at runtime after the copy relocation changes the address of the symbol.
[Bug lto/69271] LTO drops weak binding from aliases
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69271 nsz at gcc dot gnu.org changed: What|Removed |Added Version|6.0 |5.3.1 --- Comment #1 from nsz at gcc dot gnu.org --- hm it happens on gcc-5 too, gcc-49 is ok.
[Bug lto/69271] LTO drops weak binding from aliases
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69271 Richard Biener changed: What|Removed |Added Keywords||lto, wrong-code CC||hubicka at gcc dot gnu.org --- Comment #2 from Richard Biener --- Well, -shared is somewhat similar here.