GrammaTech / ddisasm

A fast and accurate disassembler
https://grammatech.github.io/ddisasm/
GNU Affero General Public License v3.0
663 stars 62 forks source link

gnu linker script? #62

Closed Cofflag closed 1 year ago

Cofflag commented 1 year ago

can ddisasm generate a gnu linker script to ensure the reassembled binary is the same as the old one?

adamjseitz commented 1 year ago

gtirb-pprinter (which is the component responsible for generating assembly and other artifacts for re-assembly, e.g., symbol version scripts - emitting an IR from ddisasm and using gtirb-pprinter directly gives some more options than ddisasm's --asm option) does not currently support generating linker scripts.

Is the idea of generating a linker script intended to ensure each section retains the original address? Or are there additional problems that it would solve?

https://github.com/GrammaTech/ddisasm/issues/59 is a related issue, which has a bit more discussion of additional challenges with regenerating binaries identical to the original (in particular, this comment from aeflores).

aeflores commented 1 year ago

Generating linker scripts could help with some of the discrepancies, and we have considered implementing this functionality (in gtirb-pprinter), but as @adamjseitz said, this is not yet supported. If want to implement it yourself, please take a look at our contributors guide https://github.com/GrammaTech/gtirb-pprinter/blob/master/CONTRIBUTING.md

Cofflag commented 1 year ago

does not currently support generating linker scripts.

I see. Thanks.

Is the idea of generating a linker script intended to ensure each section retains the original address?

Mostly yes. And it enables users to inject code to where they want without using pure address in assembly(which is not easy to modify)

If want to implement it yourself, please take a look at our contributors guide

Thanks.

Cofflag commented 1 year ago

Is the idea of generating a linker script intended to ensure each section retains the original address?

Oh, this also prevent gcc from using its default linker script which removes vanilla sections of the elf.