Issue 144798
Summary clang encodes an invalid DWARF register number for sub-registers.
Labels clang
Assignees
Reporter amsen20
    There is a [mapping](https://dwarfstd.org/doc/DWARF5.pdf) from each target register to a DWARF register number, which is used to refer to different registers within the debug information. Sub-registers are [not defined](https://refspecs.linuxfoundation.org/elf/x86_64-abi-0.95.pdf) in this mapping and they should be either considered to have the same DWARF register number as their super registers or as invalid input. However, in LLVM, they are considered different registers with different and incorrect DWARF register numbers (e.g. unsigned -1).

Example `a.s`:
```asm
.text
 .type   _start,@function
        .globl  _start
        .hidden _start
_start:
        .cfi_sections .eh_frame, .debug_frame
 .cfi_startproc

        .cfi_same_value %rax
        .cfi_same_value %eax

        retq

        .cfi_endproc
.Ltmp0:
        .size _start, .Ltmp0-_start
        .text
``` 

If you run `clang` on it, it compiles it successfully and the `objdump` output is:
```
$ clang -c -g b.s -o a.o && llvm-objdump --dwarf=frames a.o
a.o:    file format elf64-x86-64

.debug_frame contents:

00000000 00000014 ffffffff CIE
 Format:                DWARF32
  Version:               4
  Augmentation: ""
  Address size:          8
  Segment desc size:     0
  Code alignment factor: 1
  Data alignment factor: -8
  Return address column: 16

  DW_CFA_def_cfa: reg7 +8
  DW_CFA_offset: reg16 -8
  DW_CFA_nop:
 DW_CFA_nop:
  DW_CFA_nop:
  DW_CFA_nop:

  CFA=reg7+8: reg16=[CFA-8]

00000018 0000001c 00000000 FDE cie=00000000 pc=00000000...00000001
  Format:       DWARF32
  DW_CFA_same_value: reg0
 DW_CFA_same_value: reg4294967294

  0x0: CFA=reg7+8: reg0=same, reg16=[CFA-8], reg4294967294=same


.eh_frame contents:

00000000 00000014 00000000 CIE
  Format:                DWARF32
  Version: 1
  Augmentation:          "zR"
  Code alignment factor: 1
  Data alignment factor: -8
  Return address column: 16
  Augmentation data: 1B

  DW_CFA_def_cfa: reg7 +8
  DW_CFA_offset: reg16 -8
  DW_CFA_nop:
 DW_CFA_nop:

  CFA=reg7+8: reg16=[CFA-8]

00000018 0000001c 0000001c FDE cie=00000000 pc=00000000...00000001
  Format:       DWARF32
 DW_CFA_same_value: reg0
  DW_CFA_same_value: reg4294967294
  DW_CFA_nop:
 DW_CFA_nop:
  DW_CFA_nop:
  DW_CFA_nop:
  DW_CFA_nop:
  DW_CFA_nop:
 DW_CFA_nop:

  0x0: CFA=reg7+8: reg0=same, reg16=[CFA-8], reg4294967294=same
```
As you can see, `eax` is mapped to `reg4294967294` which is incorrect and does not exist.
On the other hand, if you input the same code to gnu as, the following error happens:
```
$ as -g a.s -o a.o
a.s: Assembler messages:
a.s:10: Error: bad register _expression_
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to