https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107030
Bug ID: 107030
Summary: Emitted binary code changes when -g is enabled at -O2
-flto and optimize attribute
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: lto
Assignee: unassigned at gcc dot gnu.org
Reporter: tlwang at uwaterloo dot ca
CC: marxin at gcc dot gnu.org
Target Milestone: ---
This occurs when compiling attributes_program0_preprocessed.c as shown below:
$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/scratch/software/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /tmp/tmp.O2a2UsOhYi-gcc-builder/gcc/configure
--enable-languages=c,c++,lto --enable-checking-yes --enable-multiarch
--prefix=/scratch/software/gcc-trunk --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.0.0 20220924 (experimental) [master -g4afaeaab5] (GCC)
$ cat attributes_program0_preprocessed.c
int a;
union {
char b;
long c;
} d = {0};
void e(f) { g(d.b); }
__attribute__((optimize(0))) static short h() {
e(d.c);
int i = a;
}
void g(j) {}
int main() {}
$ gcc-trunk -w -flto -O2 attributes_program0_preprocessed.c -o a.out; objdump
--disassemble --section=.text a.out > no_dbg.txt
$ gcc-trunk -w -flto -O2 attributes_program0_preprocessed.c -g -o a.out;
objdump --disassemble --section=.text a.out > dbg.txt
$ diff no_dbg.txt dbg.txt
96c96
< 401124: 8b 05 de 0e 00 00 mov 0xede(%rip),%eax # 402008
<a>
---
> 401124: 8b 05 da 0e 00 00 mov 0xeda(%rip),%eax # 402004
> <a>