Skip to content

Emitted binary code changes when -g is enabled at -O1 with -flto=thin #50539

@theo-lw

Description

@theo-lw
Bugzilla Link 51195
Version trunk
OS Linux
Blocks #37076
CC @chengniansun,@dwblaikie,@pogo59

Extended Description

This might be related to #50454 , but I'm not sure because the programs look rather different.

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

$ cat transformed_program0.c
int d, g;
union a {
  unsigned b;
} c[54] = {{1}};
void h() {
  union a *e = &c[9];
  int f = e != 0;
}
int main() {
  d = d ^ c[g].b;
  g = 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 -flto=thin -O1 transformed_program0.c ; objdump --disassemble --section=.text a.out > no_g.txt
$ clang-trunk -g -flto=thin -O1 transformed_program0.c ; objdump --disassemble --section=.text a.out > g.txt
$ diff no_g.txt g.txt
31,32c31,32
<   401060:	b8 28 40 40 00       	mov    $0x404028,%eax
<   401065:	48 3d 28 40 40 00    	cmp    $0x404028,%rax
---
>   401060:	b8 08 41 40 00       	mov    $0x404108,%eax
>   401065:	48 3d 08 41 40 00    	cmp    $0x404108,%rax
37c37
<   401077:	bf 28 40 40 00       	mov    $0x404028,%edi
---
>   401077:	bf 08 41 40 00       	mov    $0x404108,%edi
46,47c46,47
<   401090:	be 28 40 40 00       	mov    $0x404028,%esi
<   401095:	48 81 ee 28 40 40 00 	sub    $0x404028,%rsi
---
>   401090:	be 08 41 40 00       	mov    $0x404108,%esi
>   401095:	48 81 ee 08 41 40 00 	sub    $0x404108,%rsi
57c57
<   4010b9:	bf 28 40 40 00       	mov    $0x404028,%edi
---
>   4010b9:	bf 08 41 40 00       	mov    $0x404108,%edi
66c66
<   4010d4:	80 3d 4d 2f 00 00 00 	cmpb   $0x0,0x2f4d(%rip)        # 404028 <__TMC_END__>
---
>   4010d4:	80 3d 2d 30 00 00 00 	cmpb   $0x0,0x302d(%rip)        # 404108 <__TMC_END__>
71c71
<   4010e6:	c6 05 3b 2f 00 00 01 	movb   $0x1,0x2f3b(%rip)        # 404028 <__TMC_END__>
---
>   4010e6:	c6 05 1b 30 00 00 01 	movb   $0x1,0x301b(%rip)        # 404108 <__TMC_END__>
88,91c88,91
<   401110:	0f b6 05 19 2f 00 00 	movzbl 0x2f19(%rip),%eax        # 404030 <g>
<   401117:	8b 04 85 10 20 40 00 	mov    0x402010(,%rax,4),%eax
<   40111e:	31 05 08 2f 00 00    	xor    %eax,0x2f08(%rip)        # 40402c <d>
<   401124:	c6 05 05 2f 00 00 01 	movb   $0x1,0x2f05(%rip)        # 404030 <g>
---
>   401110:	0f b6 05 f9 2f 00 00 	movzbl 0x2ff9(%rip),%eax        # 404110 <g>
>   401117:	8b 04 85 30 40 40 00 	mov    0x404030(,%rax,4),%eax
>   40111e:	31 05 e8 2f 00 00    	xor    %eax,0x2fe8(%rip)        # 40410c <d>
>   401124:	c6 05 e5 2f 00 00 01 	movb   $0x1,0x2fe5(%rip)        # 404110 <g>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions