https://bugs.llvm.org/show_bug.cgi?id=51196

            Bug ID: 51196
           Summary: Emitted binary code changes when -g is enabled at -O2
                    with -flto
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
            Blocks: 37728

Note: this might be a duplicate of https://bugs.llvm.org/show_bug.cgi?id=51110,
but I'm not sure because the programs look different.

The .text section for the following program (program0.c) changes after toggling
the -g flag.

$ cat program0.c
int a, f;
short b, d;
char c[3];
char e[2];
int main() {
  d = ({
    int g = &e[1] == &c[2];
    b;
  });
  a = a ^ c[2];
  for (; f < 2; f++)
    a = e[1];
}
$
$ clang-trunk -v
clang version 13.0.0 (https://github.com/llvm/llvm-project.git
ab5ac659c81a453a3f58df94f39fe8ba3cd35918)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/cnsun/usr/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
$
$ clang-trunk -O2 -flto program0.c ; objdump --disassemble --section=.text >
no_g.txt
$ clang-trunk -g -O2 -flto program0.c ; objdump --disassemble --section=.text >
g.txt
$ diff no_g.txt g.txt
16,17c16,17
<   401033:     49 c7 c0 a0 11 40 00    mov    $0x4011a0,%r8
<   40103a:     48 c7 c1 30 11 40 00    mov    $0x401130,%rcx
---
>   401033:     49 c7 c0 b0 11 40 00    mov    $0x4011b0,%r8
>   40103a:     48 c7 c1 40 11 40 00    mov    $0x401140,%rcx
88,136c88,132
<   401110:     80 3d 15 2f 00 00 00    cmpb   $0x0,0x2f15(%rip)        #
40402c <f>
<   401117:     75 07                   jne    401120 <main+0x10>
<   401119:     c6 05 0c 2f 00 00 01    movb   $0x1,0x2f0c(%rip)        #
40402c <f>
<   401120:     31 c0                   xor    %eax,%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)
<
< 0000000000401130 <__libc_csu_init>:
<   401130:     f3 0f 1e fa             endbr64
<   401134:     41 57                   push   %r15
<   401136:     4c 8d 3d 13 2d 00 00    lea    0x2d13(%rip),%r15        #
403e50 <__frame_dummy_init_array_entry>
<   40113d:     41 56                   push   %r14
<   40113f:     49 89 d6                mov    %rdx,%r14
<   401142:     41 55                   push   %r13
<   401144:     49 89 f5                mov    %rsi,%r13
<   401147:     41 54                   push   %r12
<   401149:     41 89 fc                mov    %edi,%r12d
<   40114c:     55                      push   %rbp
<   40114d:     48 8d 2d 04 2d 00 00    lea    0x2d04(%rip),%rbp        #
403e58 <__do_global_dtors_aux_fini_array_entry>
<   401154:     53                      push   %rbx
<   401155:     4c 29 fd                sub    %r15,%rbp
<   401158:     48 83 ec 08             sub    $0x8,%rsp
<   40115c:     e8 9f fe ff ff          callq  401000 <_init>
<   401161:     48 c1 fd 03             sar    $0x3,%rbp
<   401165:     74 1f                   je     401186 <__libc_csu_init+0x56>
<   401167:     31 db                   xor    %ebx,%ebx
<   401169:     0f 1f 80 00 00 00 00    nopl   0x0(%rax)
<   401170:     4c 89 f2                mov    %r14,%rdx
<   401173:     4c 89 ee                mov    %r13,%rsi
<   401176:     44 89 e7                mov    %r12d,%edi
<   401179:     41 ff 14 df             callq  *(%r15,%rbx,8)
<   40117d:     48 83 c3 01             add    $0x1,%rbx
<   401181:     48 39 dd                cmp    %rbx,%rbp
<   401184:     75 ea                   jne    401170 <__libc_csu_init+0x40>
<   401186:     48 83 c4 08             add    $0x8,%rsp
<   40118a:     5b                      pop    %rbx
<   40118b:     5d                      pop    %rbp
<   40118c:     41 5c                   pop    %r12
<   40118e:     41 5d                   pop    %r13
<   401190:     41 5e                   pop    %r14
<   401192:     41 5f                   pop    %r15
<   401194:     c3                      retq
<   401195:     66 66 2e 0f 1f 84 00    data16 nopw %cs:0x0(%rax,%rax,1)
<   40119c:     00 00 00 00
<
< 00000000004011a0 <__libc_csu_fini>:
<   4011a0:     f3 0f 1e fa             endbr64
---
>   401110:     0f be 05 16 2f 00 00    movsbl 0x2f16(%rip),%eax        # 
> 40402d <c+0x2>
>   401117:     31 05 13 2f 00 00       xor    %eax,0x2f13(%rip)        # 
> 404030 <a>
>   40111d:     80 3d 10 2f 00 00 00    cmpb   $0x0,0x2f10(%rip)        # 
> 404034 <f>
>   401124:     75 14                   jne    40113a <main+0x2a>
>   401126:     0f be 05 fd 2e 00 00    movsbl 0x2efd(%rip),%eax        # 
> 40402a <e+0x1>
>   40112d:     89 05 fd 2e 00 00       mov    %eax,0x2efd(%rip)        # 
> 404030 <a>
>   401133:     c6 05 fa 2e 00 00 01    movb   $0x1,0x2efa(%rip)        # 
> 404034 <f>
>   40113a:     31 c0                   xor    %eax,%eax
>   40113c:     c3                      retq
>   40113d:     0f 1f 00                nopl   (%rax)
>
> 0000000000401140 <__libc_csu_init>:
>   401140:     f3 0f 1e fa             endbr64
>   401144:     41 57                   push   %r15
>   401146:     4c 8d 3d 03 2d 00 00    lea    0x2d03(%rip),%r15        # 
> 403e50 <__frame_dummy_init_array_entry>
>   40114d:     41 56                   push   %r14
>   40114f:     49 89 d6                mov    %rdx,%r14
>   401152:     41 55                   push   %r13
>   401154:     49 89 f5                mov    %rsi,%r13
>   401157:     41 54                   push   %r12
>   401159:     41 89 fc                mov    %edi,%r12d
>   40115c:     55                      push   %rbp
>   40115d:     48 8d 2d f4 2c 00 00    lea    0x2cf4(%rip),%rbp        # 
> 403e58 <__do_global_dtors_aux_fini_array_entry>
>   401164:     53                      push   %rbx
>   401165:     4c 29 fd                sub    %r15,%rbp
>   401168:     48 83 ec 08             sub    $0x8,%rsp
>   40116c:     e8 8f fe ff ff          callq  401000 <_init>
>   401171:     48 c1 fd 03             sar    $0x3,%rbp
>   401175:     74 1f                   je     401196 <__libc_csu_init+0x56>
>   401177:     31 db                   xor    %ebx,%ebx
>   401179:     0f 1f 80 00 00 00 00    nopl   0x0(%rax)
>   401180:     4c 89 f2                mov    %r14,%rdx
>   401183:     4c 89 ee                mov    %r13,%rsi
>   401186:     44 89 e7                mov    %r12d,%edi
>   401189:     41 ff 14 df             callq  *(%r15,%rbx,8)
>   40118d:     48 83 c3 01             add    $0x1,%rbx
>   401191:     48 39 dd                cmp    %rbx,%rbp
>   401194:     75 ea                   jne    401180 <__libc_csu_init+0x40>
>   401196:     48 83 c4 08             add    $0x8,%rsp
>   40119a:     5b                      pop    %rbx
>   40119b:     5d                      pop    %rbp
>   40119c:     41 5c                   pop    %r12
>   40119e:     41 5d                   pop    %r13
>   4011a0:     41 5e                   pop    %r14
>   4011a2:     41 5f                   pop    %r15
137a134,139
>   4011a5:     66 66 2e 0f 1f 84 00    data16 nopw %cs:0x0(%rax,%rax,1)
>   4011ac:     00 00 00 00
>
> 00000000004011b0 <__libc_csu_fini>:
>   4011b0:     f3 0f 1e fa             endbr64
>   4011b4:     c3                      retq


Referenced Bugs:

https://bugs.llvm.org/show_bug.cgi?id=37728
[Bug 37728] [meta] Make llvm passes debug info invariant
-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to