Skip to content

Emitted binary code changes when -g is enabled at -O1 #49924

@theo-lw

Description

@theo-lw
Bugzilla Link 50580
Resolution FIXED
Resolved on Jul 02, 2021 09:10
Version trunk
OS Linux
Blocks #37076
CC @predator5047,@dwblaikie,@pogo59
Fixed by commit(s) e90c6f5

Extended Description

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

$ cat program.c
short a;
int b, c;
long d, e;
long f() {
long g = ({ d == 0 ? c : c / d; }), h = e;
int i = b & g;
if (i) {
a = 0;
return b;
}
return h;
}
int main() {}
$
$ clang-trunk -v
clang version 13.0.0 (https://github.com/llvm/llvm-project.git 8a96993)
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 -O1 -w program.c ; objdump --disassemble a.out > "no-g.txt"
$ clang-trunk -O1 -g -w program.c ; objdump --disassemble a.out > "g.txt"
$ diff no-g.txt g.txt
113,115c113,116
< 401141: 48 8b 05 f8 2e 00 00 mov 0x2ef8(%rip),%rax # 404040
< 401148: c3 retq
< 401149: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)

401141: 48 8b 0d f8 2e 00 00 mov 0x2ef8(%rip),%rcx # 404040
401148: 48 89 c8 mov %rcx,%rax
40114b: c3 retq
40114c: 0f 1f 40 00 nopl 0x0(%rax)

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