Skip to content

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

@theo-lw

Description

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

Extended Description

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

$ cat program.c
struct a {
int b[100];
} c, d;
attribute((noinline)) struct a e() { return d; }
int main() { c = e(); }
$
$ clang-trunk -v
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 3890ce7)
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 -c -m32 -O1 program.c ; objdump --disassemble --section=.text program.o > no_g.txt
$ clang-trunk -c -m32 -O1 -g program.c ; objdump --disassemble --section=.text program.o > g.txt
$ diff no_g.txt g.txt
26,39c26,40
< 31: 81 ec a4 01 00 00 sub $0x1a4,%esp
< 37: 8d 74 24 14 lea 0x14(%esp),%esi
< 3b: 56 push %esi
< 3c: e8 fc ff ff ff call 3d <main+0xd>
< 41: 83 c4 08 add $0x8,%esp
< 44: 68 90 01 00 00 push $0x190
< 49: 56 push %esi
< 4a: 68 00 00 00 00 push $0x0
< 4f: e8 fc ff ff ff call 50 <main+0x20>
< 54: 83 c4 10 add $0x10,%esp
< 57: 31 c0 xor %eax,%eax
< 59: 81 c4 98 01 00 00 add $0x198,%esp
< 5f: 5e pop %esi
< 60: c3 ret

31: 81 ec 98 01 00 00 sub $0x198,%esp
37: 83 ec 0c sub $0xc,%esp
3a: 8d 74 24 14 lea 0x14(%esp),%esi
3e: 56 push %esi
3f: e8 fc ff ff ff call 40 <main+0x10>
44: 83 c4 08 add $0x8,%esp
47: 68 90 01 00 00 push $0x190
4c: 56 push %esi
4d: 68 00 00 00 00 push $0x0
52: e8 fc ff ff ff call 53 <main+0x23>
57: 83 c4 10 add $0x10,%esp
5a: 31 c0 xor %eax,%eax
5c: 81 c4 98 01 00 00 add $0x198,%esp
62: 5e pop %esi
63: c3 ret

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