bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug gas/28699] New: Bad interaction between .loc, .byte causes incorrec


From: keno at juliacomputing dot com
Subject: [Bug gas/28699] New: Bad interaction between .loc, .byte causes incorrect DWARF line table, causes corruption under gdb
Date: Wed, 15 Dec 2021 08:18:06 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=28699

            Bug ID: 28699
           Summary: Bad interaction between .loc, .byte causes incorrect
                    DWARF line table, causes corruption under gdb
           Product: binutils
           Version: 2.38 (HEAD)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gas
          Assignee: unassigned at sourceware dot org
          Reporter: keno at juliacomputing dot com
  Target Milestone: ---

Consider the following code which is reduced from wine:

minimal.c
```
void *wine_ntdll_get_thread_data() {
    void *teb;
    __asm__(".byte 0x65\n\tmovq (0x30),%0" : "=r" (teb));
    return teb;
}
```

gcc -g3 -S -o minimal.S minimal.c
```
[snip]

        .loc 1 3 5
#APP
# 3 "minimal.c" 1
        .byte 0x65
        movq (0x30),%rax
# 0 "" 2
#NO_APP

[snip]
```

$ as minimal.S -o minimal.o

objdump -d minimal.o
```
Disassembly of section .text:

0000000000000000 <wine_ntdll_get_thread_data>:
   0:   f3 0f 1e fa             endbr64 
   4:   55                      push   %rbp
   5:   48 89 e5                mov    %rsp,%rbp
   8:   65 48 8b 04 25 30 00    mov    %gs:0x30,%rax
   f:   00 00 
  11:   48 89 45 f8             mov    %rax,-0x8(%rbp)
  15:   48 8b 45 f8             mov    -0x8(%rbp),%rax
  19:   5d                      pop    %rbp
  1a:   c3                      retq   
```

objdump --dwarf=line minimal.o
```
 Line Number Statements:
  [0x00000048]  Set column to 36
  [0x0000004a]  Extended opcode 2: set Address to 0x0
  [0x00000055]  Copy
  [0x00000056]  Set column to 5
  [0x00000058]  Special opcode 133: advance Address by 9 to 0x9 and Line by 2
to 3
  [0x00000059]  Set column to 12
  [0x0000005b]  Special opcode 174: advance Address by 12 to 0x15 and Line by 1
to 4
  [0x0000005c]  Set column to 1
  [0x0000005e]  Special opcode 62: advance Address by 4 to 0x19 and Line by 1
to 5
  [0x0000005f]  Advance PC by 2 to 0x1b
  [0x00000061]  Extended opcode 1: End of Sequence

```

Note that the line table has an entry at address `0x9` which is
in the middle of the instruction at `0x8`. Because of this,
GDB will set a breakpoint there and subsequently execute
the instruction without the gs prefix causing crashes.
I believe GAS is wrong here to have put 0x9 as the line
table entry and instead should have put it before the `.byte`
at 0x8.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]