https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104237

            Bug ID: 104237
           Summary: Emitted binary code changes when -g is enabled at -O1
                    -flto
           Product: gcc
           Version: 12.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_transformed_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/12.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /tmp/tmp.scGtRTj8uf-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 12.0.1 20220125 (experimental) [master -gf4ee27d32] (GCC)
$ cat attributes_transformed_program0_preprocessed.c
# 6 ""
short a;
__attribute__((optimize(0))) int b();
__attribute__((always_inline)) signed char c();
int b() {
  char e = c();
  return a;
}
signed char c(f) {
  d();
# 7 "attributes_transformed_program0.c"
  int g;
# 6
  return f;
}
void d() {}
int main() {}
$ gcc-trunk -w -O1 -flto attributes_transformed_program0_preprocessed.c -o
a.out
$ objdump --disassemble --section=.text a.out > no_debug.txt
$ gcc-trunk -w -O1 -flto -g attributes_transformed_program0_preprocessed.c -o
a.out
$ objdump --disassemble --section=.text a.out > debug.txt
$ diff debug.txt no_debug.txt
18c18
<   401041:     48 c7 c7 1e 11 40 00    mov    $0x40111e,%rdi
---
>   401041:     48 c7 c7 1d 11 40 00    mov    $0x40111d,%rdi
88,91c88,91
<   40110d:     90                      nop
<   40110e:     88 45 ff                mov    %al,-0x1(%rbp)
<   401111:     0f b7 05 ec 0e 00 00    movzwl 0xeec(%rip),%eax        # 402004
<a>
<   401118:     98                      cwtl
---
>   40110d:     88 45 ff                mov    %al,-0x1(%rbp)
>   401110:     0f b7 05 ed 0e 00 00    movzwl 0xeed(%rip),%eax        # 402004 
> <a>
>   401117:     98                      cwtl
>   401118:     90                      nop
93,95c93,94
<   40111a:     90                      nop
<   40111b:     5d                      pop    %rbp
<   40111c:     c3                      retq
---
>   40111a:     5d                      pop    %rbp
>   40111b:     c3                      retq
97,98c96,97
< 000000000040111d <d>:
<   40111d:     c3                      retq
---
> 000000000040111c <d>:
>   40111c:     c3                      retq
100,105c99,104
< 000000000040111e <main>:
<   40111e:     b8 00 00 00 00          mov    $0x0,%eax
<   401123:     c3                      retq
<   401124:     66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
<   40112b:     00 00 00
<   40112e:     66 90                   xchg   %ax,%ax
---
> 000000000040111d <main>:
>   40111d:     b8 00 00 00 00          mov    $0x0,%eax
>   401122:     c3                      retq
>   401123:     66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
>   40112a:     00 00 00
>   40112d:     0f 1f 00                nopl   (%rax)

Reply via email to