Skip to content

Commit b724d05

Browse files
committed
Add -OCFR-hacks option to help -OCFR
This is for binaries such as Firefox that use non-standard relocations (ELF hacks).
1 parent efe97e1 commit b724d05

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

doc/e9patch.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ the rewritten binary much faster, but may introduce rewriting
4949
bugs if the built-in CRF analysis is inaccurate.
5050
.br
5151
Default: \fBfalse\fR (disabled)
52+
.IP "\fB\-OCFR-hacks\fR[=\fI\,false\/\fR]" 4
53+
Makes -OCFR even more conservative. This may help some
54+
binaries that use non-standard relocations.
55+
.br
56+
Default: \fBfalse\fR (disabled)
5257
.IP "\fB\-Oepilogue\fR=\fI\,N\/\fR" 4
5358
Append a epilogue of up to N instructions to the end of each
5459
trampoline. This may enhance \fB\-Opeephole\fR.

src/e9patch/e9CFR.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ void targetAnalysis(Binary *B)
404404
}
405405
}
406406
}
407-
if (!pic)
407+
if (!pic || option_OCFR_hacks)
408408
{
409409
// Non-PIC code pointers & jump tables
410410
for (unsigned i = 0; i < phnum; i++)

src/e9patch/e9patch.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ bool option_tactic_T2 = true;
4848
bool option_tactic_T3 = true;
4949
bool option_tactic_backward_T3 = true;
5050
bool option_OCFR = false;
51+
bool option_OCFR_hacks = false;
5152
unsigned option_Oepilogue = 0;
5253
unsigned option_Oepilogue_size = 64;
5354
bool option_Oorder = false;
@@ -238,6 +239,11 @@ static void usage(FILE *stream, const char *progname)
238239
"\t\tbugs if the built-in CRF analysis is inaccurate.\n"
239240
"\t\tDefault: false (disabled)\n"
240241
"\n"
242+
"\t-OCFR-hacks[=false]\n"
243+
"\t\tMakes -OCFR even more conservative. This may help some\n"
244+
"\t\tbinaries that use non-standard relocations.\n"
245+
"\t\tDefault: false (disabled)\n"
246+
"\n"
241247
"\t-Oepilogue=N\n"
242248
"\t\tAppend a epilogue of up to N instructions to the end of each\n"
243249
"\t\ttrampoline. This may enhance -Opeephole.\n"
@@ -401,6 +407,7 @@ enum Option
401407
OPTION_MEM_REBASE,
402408
OPTION_MEM_UB,
403409
OPTION_OCFR,
410+
OPTION_OCFR_HACKS,
404411
OPTION_OEPILOGUE,
405412
OPTION_OEPILOGUE_SIZE,
406413
OPTION_OORDER,
@@ -435,6 +442,7 @@ void parseOptions(char * const argv[], bool api)
435442
static const struct option long_options[] =
436443
{
437444
{"OCFR", opt_arg, nullptr, OPTION_OCFR},
445+
{"OCFR-hacks", opt_arg, nullptr, OPTION_OCFR_HACKS},
438446
{"Oepilogue", req_arg, nullptr, OPTION_OEPILOGUE},
439447
{"Oepilogue-size", req_arg, nullptr, OPTION_OEPILOGUE_SIZE},
440448
{"Oorder", opt_arg, nullptr, OPTION_OORDER},
@@ -506,7 +514,10 @@ void parseOptions(char * const argv[], bool api)
506514
option_input = optarg;
507515
break;
508516
case OPTION_OCFR:
509-
option_OCFR = (unsigned)parseBoolOptArg("-OCFR", optarg);
517+
option_OCFR = parseBoolOptArg("-OCFR", optarg);
518+
break;
519+
case OPTION_OCFR_HACKS:
520+
option_OCFR_hacks = parseBoolOptArg("-OCFR-hacks", optarg);
510521
break;
511522
case OPTION_OEPILOGUE:
512523
option_Oepilogue =

src/e9patch/e9patch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ extern bool option_is_tty;
593593
extern bool option_debug;
594594
extern bool option_batch;
595595
extern bool option_OCFR;
596+
extern bool option_OCFR_hacks;
596597
extern unsigned option_Oepilogue;
597598
extern unsigned option_Oepilogue_size;
598599
extern bool option_Oorder;

0 commit comments

Comments
 (0)