From 2fa42a7a7c0f6125b9c1f2ab0552cfde1bc1b6b5 Mon Sep 17 00:00:00 2001 From: Han Dai Date: Mon, 12 Feb 2024 00:38:10 -0500 Subject: [PATCH] include .rodata in function patches --- src/patcherex2/components/compilers/compiler.py | 7 ++++++- src/patcherex2/components/compilers/llvm_recomp.py | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/patcherex2/components/compilers/compiler.py b/src/patcherex2/components/compilers/compiler.py index 7d58d6d..81132f3 100644 --- a/src/patcherex2/components/compilers/compiler.py +++ b/src/patcherex2/components/compilers/compiler.py @@ -28,7 +28,12 @@ def compile(self, code, base=0, symbols=None, extra_compiler_flags=None, **kwarg _symbols.update(self.p.binary_analyzer.get_all_symbols()) _symbols.update(symbols) linker_script = ( - "SECTIONS { .text : SUBALIGN(0) { . = " + hex(base) + "; *(.text) " + "SECTIONS { .text : SUBALIGN(0) { . = " + + hex(base) + # TODO: shouldn't put .rodata in .text, but otherwise switch case jump table won't work + # Note that even we don't include .rodata here, cle might still include it if there is + # no gap between .text and .rodata + + "; *(.text) *(.rodata) " ) for name, addr in _symbols.items(): linker_script += name + " = " + hex(addr) + ";" diff --git a/src/patcherex2/components/compilers/llvm_recomp.py b/src/patcherex2/components/compilers/llvm_recomp.py index 1c2f1fb..75b8b98 100644 --- a/src/patcherex2/components/compilers/llvm_recomp.py +++ b/src/patcherex2/components/compilers/llvm_recomp.py @@ -42,7 +42,9 @@ def compile( _symbols.update(self.p.binary_analyzer.get_all_symbols()) _symbols.update(symbols) linker_script = ( - "SECTIONS { .text : SUBALIGN(0) { . = " + hex(base) + "; *(.text) " + "SECTIONS { .text : SUBALIGN(0) { . = " + + hex(base) + + "; *(.text) *(.rodata) " ) for name, addr in _symbols.items(): linker_script += name + " = " + hex(addr) + ";"