diff --git a/integration/rewrite_all.sh b/integration/rewrite_all.sh index e1717f03..d8ce8806 100755 --- a/integration/rewrite_all.sh +++ b/integration/rewrite_all.sh @@ -11,12 +11,7 @@ mkdir -p bins_rw for binary_full in ~/bins/*; do binary=$(basename $binary_full) [[ $binary =~ "ldecod" ]] && continue - [[ $binary =~ "imagick_r" ]] && continue - [[ $binary =~ "perlbench_r" ]] && continue - [[ $binary =~ "nab_r" ]] && continue - [[ $binary =~ "xz_r" ]] && continue - [[ $binary =~ "cpugcc_r" ]] && continue - [[ $binary =~ "lbm_r" ]] && continue + [[ $binary =~ "diffwrf" ]] && continue if [[ $1 == "nothing" ]]; then echo "Not touching ${binary}..." diff --git a/integration/run_test.py b/integration/run_test.py index 10330daa..c80be594 100644 --- a/integration/run_test.py +++ b/integration/run_test.py @@ -83,8 +83,9 @@ def run(command): if len(binary.split("_")) < 2: quit(f"{binary} wrong format") - if any(x in binary for x in ["perlbench", "cpugcc_r", "mcf_r", "lbm_r", "imagick_r", "nab_r", "xz_r"]): - continue + # skip those + # if any(x in binary for x in ["perlbench", "cpugcc_r", "mcf_r", "lbm_r", "imagick_r", "nab_r", "xz_r"]): + # continue binary_original_name = "_".join(binary.split("_")[:2]) diff --git a/librw_arm64/container.py b/librw_arm64/container.py index 45488cd3..a48b7156 100644 --- a/librw_arm64/container.py +++ b/librw_arm64/container.py @@ -21,7 +21,7 @@ ".data", ".rodata", ".init_array", - ".fini_array", + # ".fini_array", ".interp", ".data.rel.ro", ".noptrdata", diff --git a/librw_arm64/rw.py b/librw_arm64/rw.py index 4580739a..9b09ff2e 100644 --- a/librw_arm64/rw.py +++ b/librw_arm64/rw.py @@ -120,6 +120,7 @@ class Rewriter(): # DATASECTIONS = [".rodata", ".data", ".bss", ".data.rel.ro", ".init_array"] # DATASECTIONS = [".got", ".fini_array", ".rodata", ".data", ".bss", ".data.rel.ro", ".init_array"] # DATASECTIONS = [".got", ".rodata", ".data", ".bss", ".data.rel.ro", ".init_array"] + # DATASECTIONS = [".tm_clone_table", ".got", ".rodata", ".data", ".bss", ".data.rel.ro", ".init_array", ".fini_array", ".got.plt"] DATASECTIONS = [".tm_clone_table", ".got", ".rodata", ".data", ".bss", ".data.rel.ro", ".init_array", ".fini_array", ".got.plt"] CODESECTIONS = [".text", ".init", ".fini", ".plt"] diff --git a/rwtools_arm64/counter/instrument.py b/rwtools_arm64/counter/instrument.py index c5156921..ec78336c 100644 --- a/rwtools_arm64/counter/instrument.py +++ b/rwtools_arm64/counter/instrument.py @@ -19,37 +19,17 @@ def __init__(self, rewriter): if reg.general_purpose: self.regmap[reg.name] = reg.subregisters[0][0] - def count_two(self, instruction, idx, free): - enter_lbl = "COUNTER2_%x" % (instruction.address) - instrumentation = """ - stp x7, x8, [sp, -16]! // save x7, x8 - - // build a pointer in x8 to .counted - adrp x8, .counted2 - add x8, x8, :lo12:.counted2 - // add 1 to .counted2 - ldr x7, [x8] - add x7, x7, 1 - str x7, [x8] - - ldp x7, x8, [sp], 16 // load back x7 and x8 - """ - comment = "{}: ".format(str(instruction)) - return InstrumentedInstruction(instrumentation, enter_lbl, comment) - - - - def count_one(self, instruction, idx, free): + def count_x(self, instruction, idx, free, x): enter_lbl = "COUNTER_%x" % (instruction.address) - instrumentation = """ + instrumentation = f""" stp x7, x8, [sp, -16]! // save x7, x8 // build a pointer in x8 to .counted - adrp x8, .counted - add x8, x8, :lo12:.counted + adrp x8, .counted{x} + add x8, x8, :lo12:.counted{x} // add 1 to .counted ldr x7, [x8] @@ -61,28 +41,31 @@ def count_one(self, instruction, idx, free): comment = "{}: ".format(str(instruction)) return InstrumentedInstruction(instrumentation, enter_lbl, comment) - - def do_instrument(self): for faddr, fn in self.rewriter.container.functions.items(): for idx, instruction in enumerate(fn.cache): # if any("adrp" in str(x) for x in instruction.before): - if "br" in instruction.mnemonic: - iinstr = self.count_one(instruction, idx, None) + if "br" == instruction.mnemonic: + iinstr = self.count_x(instruction, idx, None, 0) instruction.instrument_before(iinstr) - if "blr" in instruction.mnemonic: - iinstr = self.count_two(instruction, idx, None) + elif "bl" == instruction.mnemonic: + iinstr = self.count_x(instruction, idx, None, 1) + instruction.instrument_before(iinstr) + + elif "blr" == instruction.mnemonic: + iinstr = self.count_x(instruction, idx, None, 2) instruction.instrument_before(iinstr) ds = Section(".counter", 0x100000, 0, None, flags="aw") content = """ .file: .string \"/tmp/countfile\" .perms: .string \"a\" - .format: .string \"br: %lld\\nblr: %lld\\n\" + .format: .string \"br: %lld\\nbl: %lld\\nblr: %lld\\n\" .align 3 - .counted: .quad 0x0 + .counted0: .quad 0x0 + .counted1: .quad 0x0 .counted2: .quad 0x0 """ ds.cache.append(DataCell.instrumented(content, 0)) @@ -105,11 +88,14 @@ def do_instrument(self): bl fopen // load .counted in x2 - adrp x2, .counted - ldr x2, [x2, :lo12:.counted] + adrp x2, .counted0 + ldr x2, [x2, :lo12:.counted0] // load .counted in x3 - adrp x3, .counted2 - ldr x3, [x3, :lo12:.counted2] + adrp x3, .counted1 + ldr x3, [x3, :lo12:.counted1] + + adrp x4, .counted2 + ldr x4, [x4, :lo12:.counted2] // build a pointer to .format adrp x1, .format