HexHive / retrowrite

RetroWrite -- Retrofitting compiler passes through binary rewriting
Other
664 stars 77 forks source link

C++ Support: Can't rebuild output of retrowrite on g++ Hello World #26

Open ScoreUnder opened 3 years ago

ScoreUnder commented 3 years ago

Background

Input file

hello.cpp

#include <iostream>

int main() {
    std::cout << "Hello, world!" << std::endl;
}

Repro

  1. g++ -pie -o hello hello.cpp
  2. ./retro/bin/retrowrite hello hello.s

    noting output:

    [*] Relocations for a section that's not loaded: .rela.dyn
    [*] Relocations for a section that's not loaded: .rela.plt
    [x] Could not replace value in .init_array
    [x] Couldn't find valid section 3db0
    [x] Couldn't find valid section 3fc8
    [x] Couldn't find valid section 3fd0
    [x] Couldn't find valid section 3fd8
    [x] Couldn't find valid section 3fe0
    [x] Couldn't find valid section 3fe8
    [x] Couldn't find valid section 3ff0
    [x] Couldn't find valid section 3ff8
  3. g++ hello.s

    fails with output:

    hello.s: Assembler messages:
    hello.s:76: Error: unrecognized symbol type "GLIBCXX_3.4_4080"
    hello.s:76: Error: junk at end of line, first unrecognized character is `,'
    hello.s:77: Error: junk at end of line, first unrecognized character is `@'
    hello.s:78: Error: invalid character '@' in mnemonic

It looks like it has generated some syntax that as doesn't like. Cleaning that up (not sure of the consequences but I just removed it), it then fails on an undefined label:

$ g++ hello.s
/usr/bin/ld: /tmp/ccaM02YR.o:(.init_array+0x0): undefined reference to `.LC1160'
collect2: error: ld returned 1 exit status

.LC1160 seems to be necessary for something (otherwise the program segfaults at startup), but I can't tell what it needs to point to.

diagprov commented 3 years ago

Hi, thanks for your report.

The problem here is that you are using C++ - and at the moment retrowrite doesn't support it (we support well behaved (i.e. compiled with a compiler) C PIE binaries and shared libraries and kernel modules at the moment). However, we are working on C++ support. I can't give an ETA publicly for when this will be released, but we'd like to do it as soon as we can :)

I'll leave this open and we'll post back once we have working C++ support you can use.