GrammaTech / gtirb-rewriting

Python API for rewriting GTIRB files
GNU General Public License v3.0
15 stars 3 forks source link

Reference external symbols from static library (PE binaries) #14

Open avncharlie opened 3 months ago

avncharlie commented 3 months ago

I'm attempting to write instrumentation that calls a function in a static library that I want to link while pretty-printing the instrumented IR. So far I've managed to do it like so:

  1. insert the symbol by referencing a fake library: rewriting_ctx.get_or_insert_extern_symbol('external_call', 'dummy.lib')
  2. Call gtirb-pprinter as such: gtirb-pprinter instrumented.gtirb --binary out.exe --compiler-args /link /FORCE:MULTIPLE C:\path\to\mylibrary.lib

Is there a better way to do this?

jranieri-grammatech commented 1 week ago

Unfortunately I don't think so. This is about how I would go about doing the same thing on Linux for static libraries, FWIW.

We have internal transforms that disassemble the static library to GTIRB IR, then stitches that into the target IR but in my experience that's much more hassle than it's worth (you have to deal with merging different symbol types and references, COMDATs, etc).