HexHive / retrowrite

RetroWrite -- Retrofitting compiler passes through binary rewriting
Other
655 stars 78 forks source link

[BUG] RetroWrite does not symbolize RIP-relative addressing and omits the definition of labels #45

Open witbring opened 1 year ago

witbring commented 1 year ago

Describe the bug

  1. RetroWrite fails on symbolizing RIP-relative addressing. I observed that RetroWrite fails on recovering RIP-relative addressing. As an example, given instruction  ‘leaq fix_syms(%rip), %rsi’ found in addr2line of binutils, RetroWrite reassembled the instruction as ‘leaq 5(%rip), %rsi’.

fix_syms:
.cfi_startproc pushq %r14

- Binary

00000000000a663f <_bfd_fix_excluded_sec_syms>: a663f: mov %rdi,%rdx a6642: mov 0x28(%rsi),%rdi a6646: lea 0x5(%rip),%rsi # a6652 a664d: jmpq a3ec0

00000000000a6652 : a6652: push %r14


- Reassembler-generated assembly 

.LCa6646: leaq 5(%rip), %rsi



2. RetroWrite omits the definition of some labels. 
Also, I found that RetroWrite sometimes omits some definitions of labels. For example, given the data pointer 0x170c80, RetroWrite symbolized the pointer as '.LC170c80', but RetroWrite misses the definition of the label '.LC170c80'. As a result, it causes a compilation error. 

**Describe how to reproduce the bug**
1. Platform: x86-64.
2. Compiler: Clang v12.0 and GCC v7.5.0
3. Binary: addr2line in binutils-2.31.1