Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
theo-lw opened this issue Jul 23, 2021 · 3 comments
Closed

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

theo-lw opened this issue Jul 23, 2021 · 3 comments
Labels
bugzilla Issues migrated from bugzilla llvm:codegen

Comments

@theo-lw
Copy link
Contributor

theo-lw commented Jul 23, 2021

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>
@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@theo-lw
Copy link
Contributor Author

theo-lw commented Feb 4, 2022

I can still reproduce this bug on clang-trunk, although not on clang-13.

$ clang-trunk -v
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 73cfa982ba6380ee96c017d044f3f580eb8e18bd)
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-13 -v
clang version 13.0.0 (https://github.com/llvm/llvm-project.git ec1a49170129ddb62f268ff0b3f12b3d09987a7e)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /scratch/software/clang-trunk/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

@theo-lw
Copy link
Contributor Author

theo-lw commented Jun 3, 2022

No longer reproducible on clang-trunk

$ clang-trunk -v
clang version 15.0.0 (https://github.com/llvm/llvm-project.git ce820375efc04a4290f568ac0ba7a74486f598ad)
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
$ cat program.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 -flto=thin -O1 program.c ; objdump --disassemble --section=.text a.out > no_g.txt
$ clang-trunk -g -flto=thin -O1 program.c ; objdump --disassemble --section=.text a.out > g.txt
$ diff no_g.txt g.txt
$

@fhahn
Copy link
Contributor

fhahn commented Jun 6, 2022

Thanks for confirming, I'll close the issue for now.

@fhahn fhahn closed this as completed Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla llvm:codegen
Projects
None yet
Development

No branches or pull requests

2 participants