[Bug c/61144] Invalid optimizations for extern vars with local weak definitions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61144 --- Comment #16 from Marc Glisse glisse at gcc dot gnu.org --- (In reply to Rich Felker from comment #15) Can you clarify? As far as I can tell, the other bug is a missed optimization and this is an overly-aggressive, incorrect optimization. The same test is wrong, it optimizes cases it shouldn't and doesn't optimize cases it should (I am not familiar enough to tell, just trusting you), goes together. Having testcases in both directions will be useful when Jan (or someone else) rewrites it.
[Bug c/61144] Invalid optimizations for extern vars with local weak definitions
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61144 --- Comment #8 from Rich Felker bugdal at aerifal dot cx --- Further investigation suggests that the real gcc 4.8.2 is not affected; I was mislead by the fact that Debian is shipping as gcc-4.8_4.8.2-21 an svn snapshot that's actually post-4.8.2. So 4.9.0 seems to be the only official release that's affected.
[Bug c/61144] Invalid optimizations for extern vars with local weak definitions
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61144 --- Comment #9 from Jody Lee Bruchon jody at jodybruchon dot com --- For my gcc versions (x86_64) compiled from release sources, I have the following for this testcase, with and without static, using -O2: === gcc 4.8.2, with and without static === $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-4.8.2/configure --prefix=/usr --mandir=/usr/man --libexecdir=/usr/lib --enable-languages=c,c++,objc --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-shared --disable-nls --with-x=no --with-system-zlib --disable-multilib --disable-bootstrap --disable-debug Thread model: posix gcc version 4.8.2 (GCC) $ objdump -dr test.o test.o: file format elf64-x86-64 Disassembly of section .text: bar: 0: 8b 15 00 00 00 00 mov0x0(%rip),%edx# 6 bar+0x6 2: R_X86_64_PC32foo-0x4 6: 31 c0 xor%eax,%eax 8: 85 d2 test %edx,%edx a: 0f 95 c0setne %al d: c3 retq === gcc 4.9.0 === $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-4.9.0/configure --prefix=/usr --mandir=/usr/man --libexecdir=/usr/lib --enable-languages=c,c++,objc --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-shared --disable-nls --with-x=no --with-system-zlib --disable-multilib --disable-debug Thread model: posix gcc version 4.9.0 (GCC) === With static (4.9.0) === $ objdump -dr test.o test.o: file format elf64-x86-64 Disassembly of section .text: bar: 0: 31 c0 xor%eax,%eax 2: c3 retq === Without static (4.9.0) === $ objdump -dr test.o test.o: file format elf64-x86-64 Disassembly of section .text: bar: 0: 8b 15 00 00 00 00 mov0x0(%rip),%edx# 6 bar+0x6 2: R_X86_64_PC32foo-0x4 6: 31 c0 xor%eax,%eax 8: 85 d2 test %edx,%edx a: 0f 95 c0setne %al d: c3 retq
[Bug c/61144] Invalid optimizations for extern vars with local weak definitions
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61144 --- Comment #10 from James Cloos cloos at jhcloos dot com --- My tests on debian sid with GCC: (Debian 4.8.2-21) 4.8.2 do not replicate the bug. On debian sid, only 4.9 and gcc-snapshot (the 4.10 branch) show the bug.
[Bug c/61144] Invalid optimizations for extern vars with local weak definitions
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61144 --- Comment #11 from Rich Felker bugdal at aerifal dot cx --- Adding __attribute__((__used__)) to the static object suppresses the symptom in case that helps to isolate what's causing it.
[Bug c/61144] Invalid optimizations for extern vars with local weak definitions
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61144 --- Comment #12 from Rich Felker bugdal at aerifal dot cx --- Furthermore, __builtin_constant_p(dummy) wrongly returns 1, even though dummy is modifiable externally via foo (assuming foo is not replaced by a strong definition elsewhere). Perhaps this should be filed as a separate bug since it's also user-visible, but I think the cause is the same. On the other hand, according to my tests on gcc.godbolt.org, the incorrect value for __builtin_constant_p predates the optimization bug. This could mean they're separate bugs, but I suspect the later changes that cause the optimization bug were correct except that they're using the wrong concept of is this expression constant? from the earlier bug.
[Bug c/61144] Invalid optimizations for extern vars with local weak definitions
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61144 --- Comment #13 from Rich Felker bugdal at aerifal dot cx --- I've added the related issue 61159.
[Bug c/61144] Invalid optimizations for extern vars with local weak definitions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61144 --- Comment #14 from Marc Glisse glisse at gcc dot gnu.org --- This seems related to PR 59948 where Honza says the code is really broken.
[Bug c/61144] Invalid optimizations for extern vars with local weak definitions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61144 --- Comment #15 from Rich Felker bugdal at aerifal dot cx --- Can you clarify? As far as I can tell, the other bug is a missed optimization and this is an overly-aggressive, incorrect optimization.