[llvm-bugs] [Bug 52540] New: Emitted binary code changes when -g is enabled at -O1 -m32 (interestingly, this behaviour disappears after preprocessing)

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 17 19:47:20 PST 2021


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

            Bug ID: 52540
           Summary: Emitted binary code changes when -g is enabled at -O1
                    -m32 (interestingly, this behaviour disappears after
                    preprocessing)
           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.c) changes
after toggling the -g flag. However, this behaviour goes away after running
transformed_program0.c through the preprocessor.

$ 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.c
#include "csmith.h" //
https://github.com/csmith-project/csmith/blob/master/runtime/csmith.h
struct a {
  int32_t b;
} c;
struct {
  uint64_t d;
} i;
int e, f;
int volatile g;
long h[1][3];
struct a volatile j[1][1][1];
void l() {
  int k[1];
  int o;
  int *m = &o;
  int *n[][1] = {k, k, k, k, m};
  uint32_t p;
  int32_t q;
  for (;;) {
    int32_t *r = n[4];
    for (p = 0; p <= 1; p++)
      for (c.b = 7; c.b; c.b--) {
        int32_t **s = n[4];
        if ((*s = n[0][4]) == &o)
          if (h[e][0])
            break;
        for (i.d = 0; i.d <= 4; i.d++) {
          uint16_t *aa = l;
          q &= *aa = h[p][e + 1], j[i.d][e][p], f || g;
        }
      }
    *r = 0;
  }
}
int main() {}
$ clang-trunk -I /usr/local/include/csmith -w -c -m32 -O1
transformed_program0.c -o a.out; objdump --disassemble --section=.text a.out >
no_g.txt
$ clang-trunk -I /usr/local/include/csmith -w -c -m32 -O1 -g
transformed_program0.c -o a.out; objdump --disassemble --section=.text a.out >
g.txt
$ diff no_g.txt g.txt
37,42c37,42
<   65: 8d 04 88                lea    (%eax,%ecx,4),%eax
<   68: 05 00 00 00 00          add    $0x0,%eax
<   6d: 89 44 24 0c             mov    %eax,0xc(%esp)
<   71: c7 05 00 00 00 00 07    movl   $0x7,0x0
<   78: 00 00 00
<   7b: b9 07 00 00 00          mov    $0x7,%ecx
---
>   65:	8d 84 88 00 00 00 00 	lea    0x0(%eax,%ecx,4),%eax
>   6c:	89 44 24 0c          	mov    %eax,0xc(%esp)
>   70:	c7 05 00 00 00 00 07 	movl   $0x7,0x0
>   77:	00 00 00
>   7a:	b9 07 00 00 00       	mov    $0x7,%ecx
>   7f:	90                   	nop
$

This change in the emitted binary doesn't occur if we preprocess the program.

$ clang -E -I /usr/local/include/csmith transformed_program0.c -o
transformed_program0_preprocessed.c
$ clang-trunk -w -c -m32 -O1 transformed_program0_preprocessed.c -o a.out;
objdump --disassemble --section=.text a.out > no_g.txt
$ clang-trunk -w -c -m32 -O1 -g transformed_program0_preprocessed.c -o a.out;
objdump --disassemble --section=.text a.out > g.txt
$ diff no_g.txt g.txt
$


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/8d00774f/attachment.html>


More information about the llvm-bugs mailing list