[llvm-bugs] [Bug 52538] New: Emitted binary code changes when -g is enabled at -O1 -m64

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 17 17:56:21 PST 2021


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

            Bug ID: 52538
           Summary: Emitted binary code changes when -g is enabled at -O1
                    -m64
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: tlwang at uwaterloo.ca
                CC: cnsun at uwaterloo.ca, llvm-bugs at lists.llvm.org
            Blocks: 37728

The .text section for the following program
(transformed_program0_preprocessed.c 
) changes after toggling the -g flag. I think the extra add instruction is the
reason why there's a difference.

$ clang-trunk -v
clang version 14.0.0 (https://github.com/llvm/llvm-project.git
82fc4cc60bec6d0eacad7e8575f404dcdf5144c5)
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 transformed_program0_preprocessed.c
long d, e, h;
int a, g;
int *b;
char c;
long f[];
long(i)(j) { return d && j ? d : d + j; }
short l() {
  char *k = &c;
  a = 1;
  for (;; a++) {
    int m = -9L;
    e = 1;
    for (; e <= 7; e++)
      for (; g <= 7; g++) {
        h = f[g + a];
        if (h)
          return 3;
      }
    *k = i(m) < *b;
  }
}
//void main() {}
$ clang-trunk -w -c -m64 -O1 transformed_program0_preprocessed.c -o a.out
$ objdump --disassemble --section=.text a.out > no_g.txt
$ clang-trunk -w -c -m64 -O1 -g3 transformed_program0_preprocessed.c -o a.out
$ objdump --disassemble --section=.text a.out > g.txt
$ diff no_g.txt g.txt
28,90c28,87
<   37: 4c 8d 04 08             lea    (%rax,%rcx,1),%r8
<   3b: 49 83 c0 f7             add    $0xfffffffffffffff7,%r8
<   3f: 41 ba 01 00 00 00       mov    $0x1,%r10d
<   45: 41 bb 00 00 00 00       mov    $0x0,%r11d
<   4b: 4c 8b 0d 00 00 00 00    mov    0x0(%rip),%r9        # 52 <l+0x32>
<   52: 66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
<   59: 00 00 00
<   5c: 0f 1f 40 00             nopl   0x0(%rax)
<   60: 44 89 15 00 00 00 00    mov    %r10d,0x0(%rip)        # 67 <l+0x47>
<   67: 41 b6 01                mov    $0x1,%r14b
<   6a: bf 01 00 00 00          mov    $0x1,%edi
<   6f: eb 24                   jmp    95 <l+0x75>
<   71: 66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
<   78: 00 00 00
<   7b: 0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)
<   80: 48 83 ff 07             cmp    $0x7,%rdi
<   84: 48 8d 47 01             lea    0x1(%rdi),%rax
<   88: 41 0f 92 c6             setb   %r14b
<   8c: 48 89 c7                mov    %rax,%rdi
<   8f: 48 83 f8 08             cmp    $0x8,%rax
<   93: 74 7d                   je     112 <l+0xf2>
<   95: 48 63 05 00 00 00 00    movslq 0x0(%rip),%rax        # 9c <l+0x7c>
<   9c: 48 83 f8 07             cmp    $0x7,%rax
<   a0: 7f de                   jg     80 <l+0x60>
<   a2: 49 8d 34 c3             lea    (%r11,%rax,8),%rsi
<   a6: b9 08 00 00 00          mov    $0x8,%ecx
<   ab: 48 29 c1                sub    %rax,%rcx
<   ae: 8d 50 01                lea    0x1(%rax),%edx
<   b1: 31 c0                   xor    %eax,%eax
<   b3: 66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
<   ba: 00 00 00
<   bd: 0f 1f 00                nopl   (%rax)
<   c0: 48 8b 1c c6             mov    (%rsi,%rax,8),%rbx
<   c4: 48 85 db                test   %rbx,%rbx
<   c7: 75 27                   jne    f0 <l+0xd0>
<   c9: 8d 2c 02                lea    (%rdx,%rax,1),%ebp
<   cc: 89 2d 00 00 00 00       mov    %ebp,0x0(%rip)        # d2 <l+0xb2>
<   d2: 48 83 c0 01             add    $0x1,%rax
<   d6: 48 39 c1                cmp    %rax,%rcx
<   d9: 75 e5                   jne    c0 <l+0xa0>
<   db: 48 89 1d 00 00 00 00    mov    %rbx,0x0(%rip)        # e2 <l+0xc2>
<   e2: eb 9c                   jmp    80 <l+0x60>
<   e4: 66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
<   eb: 00 00 00
<   ee: 66 90                   xchg   %ax,%ax
<   f0: 48 89 3d 00 00 00 00    mov    %rdi,0x0(%rip)        # f7 <l+0xd7>
<   f7: 48 89 1d 00 00 00 00    mov    %rbx,0x0(%rip)        # fe <l+0xde>
<   fe: 49 83 c2 01             add    $0x1,%r10
<  102: 49 83 c3 08             add    $0x8,%r11
<  106: 41 f6 c6 01             test   $0x1,%r14b
<  10a: 0f 84 50 ff ff ff       je     60 <l+0x40>
<  110: eb 1a                   jmp    12c <l+0x10c>
<  112: 48 c7 05 00 00 00 00    movq   $0x8,0x0(%rip)        # 11d <l+0xfd>
<  119: 08 00 00 00
<  11d: 49 63 01                movslq (%r9),%rax
<  120: 49 39 c0                cmp    %rax,%r8
<  123: 0f 9c 05 00 00 00 00    setl   0x0(%rip)        # 12a <l+0x10a>
<  12a: eb d2                   jmp    fe <l+0xde>
<  12c: 66 b8 03 00             mov    $0x3,%ax
<  130: 5b                      pop    %rbx
<  131: 41 5e                   pop    %r14
<  133: 5d                      pop    %rbp
<  134: c3                      retq
---
>   37:	4c 8d 44 08 f7       	lea    -0x9(%rax,%rcx,1),%r8
>   3c:	41 ba 01 00 00 00    	mov    $0x1,%r10d
>   42:	41 bb 00 00 00 00    	mov    $0x0,%r11d
>   48:	4c 8b 0d 00 00 00 00 	mov    0x0(%rip),%r9        # 4f <l+0x2f>
>   4f:	90                   	nop
>   50:	44 89 15 00 00 00 00 	mov    %r10d,0x0(%rip)        # 57 <l+0x37>
>   57:	41 b6 01             	mov    $0x1,%r14b
>   5a:	bf 01 00 00 00       	mov    $0x1,%edi
>   5f:	eb 24                	jmp    85 <l+0x65>
>   61:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
>   68:	00 00 00
>   6b:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)
>   70:	48 83 ff 07          	cmp    $0x7,%rdi
>   74:	48 8d 47 01          	lea    0x1(%rdi),%rax
>   78:	41 0f 92 c6          	setb   %r14b
>   7c:	48 89 c7             	mov    %rax,%rdi
>   7f:	48 83 f8 08          	cmp    $0x8,%rax
>   83:	74 7d                	je     102 <l+0xe2>
>   85:	48 63 05 00 00 00 00 	movslq 0x0(%rip),%rax        # 8c <l+0x6c>
>   8c:	48 83 f8 07          	cmp    $0x7,%rax
>   90:	7f de                	jg     70 <l+0x50>
>   92:	49 8d 34 c3          	lea    (%r11,%rax,8),%rsi
>   96:	b9 08 00 00 00       	mov    $0x8,%ecx
>   9b:	48 29 c1             	sub    %rax,%rcx
>   9e:	8d 50 01             	lea    0x1(%rax),%edx
>   a1:	31 c0                	xor    %eax,%eax
>   a3:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
>   aa:	00 00 00
>   ad:	0f 1f 00             	nopl   (%rax)
>   b0:	48 8b 1c c6          	mov    (%rsi,%rax,8),%rbx
>   b4:	48 85 db             	test   %rbx,%rbx
>   b7:	75 27                	jne    e0 <l+0xc0>
>   b9:	8d 2c 02             	lea    (%rdx,%rax,1),%ebp
>   bc:	89 2d 00 00 00 00    	mov    %ebp,0x0(%rip)        # c2 <l+0xa2>
>   c2:	48 83 c0 01          	add    $0x1,%rax
>   c6:	48 39 c1             	cmp    %rax,%rcx
>   c9:	75 e5                	jne    b0 <l+0x90>
>   cb:	48 89 1d 00 00 00 00 	mov    %rbx,0x0(%rip)        # d2 <l+0xb2>
>   d2:	eb 9c                	jmp    70 <l+0x50>
>   d4:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
>   db:	00 00 00
>   de:	66 90                	xchg   %ax,%ax
>   e0:	48 89 3d 00 00 00 00 	mov    %rdi,0x0(%rip)        # e7 <l+0xc7>
>   e7:	48 89 1d 00 00 00 00 	mov    %rbx,0x0(%rip)        # ee <l+0xce>
>   ee:	49 83 c2 01          	add    $0x1,%r10
>   f2:	49 83 c3 08          	add    $0x8,%r11
>   f6:	41 f6 c6 01          	test   $0x1,%r14b
>   fa:	0f 84 50 ff ff ff    	je     50 <l+0x30>
>  100:	eb 1a                	jmp    11c <l+0xfc>
>  102:	48 c7 05 00 00 00 00 	movq   $0x8,0x0(%rip)        # 10d <l+0xed>
>  109:	08 00 00 00
>  10d:	49 63 01             	movslq (%r9),%rax
>  110:	49 39 c0             	cmp    %rax,%r8
>  113:	0f 9c 05 00 00 00 00 	setl   0x0(%rip)        # 11a <l+0xfa>
>  11a:	eb d2                	jmp    ee <l+0xce>
>  11c:	66 b8 03 00          	mov    $0x3,%ax
>  120:	5b                   	pop    %rbx
>  121:	41 5e                	pop    %r14
>  123:	5d                   	pop    %rbp
>  124:	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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211118/72516fc9/attachment-0001.html>


More information about the llvm-bugs mailing list