Skip to content

Commit

Permalink
Only run the irel checks if the libc function is found
Browse files Browse the repository at this point in the history
This just saves a bit of unneeded computation.
  • Loading branch information
hainest committed Jan 26, 2023
1 parent 5c6eae0 commit 6896ff0
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions dyninstAPI/src/parse-x86.C
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ bool BinaryEdit::doStaticBinarySpecialCases() {

AddressSpace::patch(this);


/* Special Case 1C: Instrument irel handlers
*
* Replace the irel handler with our extended version, since they hard-code
Expand All @@ -327,35 +326,35 @@ bool BinaryEdit::doStaticBinarySpecialCases() {
* irel handlers are not instrumented on the other architectures. We leave this
* here for posterity.
*/
func_instance *globalIrelHandler = findOnlyOneFunction(LIBC_IREL_HANDLER);
func_instance *dyninstIrelHandler = findOnlyOneFunction(DYNINST_IREL_HANDLER);
int_symbol irelStart;
int_symbol irelEnd;
bool irs_found = false;
bool ire_found = false;
for (auto rtlib_it = rtlib.begin(); rtlib_it != rtlib.end(); ++rtlib_it) {
if( (*rtlib_it)->getSymbolInfo(DYNINST_IREL_START, irelStart) ) {
irs_found = true;
}

if( (*rtlib_it)->getSymbolInfo(DYNINST_IREL_END, irelEnd) ) {
ire_found = true;
if(auto *globalIrelHandler = findOnlyOneFunction(LIBC_IREL_HANDLER)) {
func_instance *dyninstIrelHandler = findOnlyOneFunction(DYNINST_IREL_HANDLER);
int_symbol irelStart;
int_symbol irelEnd;
bool irs_found = false;
bool ire_found = false;
for (auto rtlib_it = rtlib.begin(); rtlib_it != rtlib.end(); ++rtlib_it) {
if( (*rtlib_it)->getSymbolInfo(DYNINST_IREL_START, irelStart) ) {
irs_found = true;
}

if( (*rtlib_it)->getSymbolInfo(DYNINST_IREL_END, irelEnd) ) {
ire_found = true;
}
if (irs_found && ire_found) break;
}
if (irs_found && ire_found) break;
}
if (globalIrelHandler) {
assert(dyninstIrelHandler);
assert(irs_found);
assert(ire_found);
std::vector<std::pair<int_symbol *, string> > tmp;
tmp.push_back(make_pair(&irelStart, SYMTAB_IREL_START));
tmp.push_back(make_pair(&irelEnd, SYMTAB_IREL_END));
if (!replaceHandler(globalIrelHandler, dyninstIrelHandler, tmp)) {
return false;
if (globalIrelHandler) {
assert(dyninstIrelHandler);
assert(irs_found);
assert(ire_found);
std::vector<std::pair<int_symbol *, string> > tmp;
tmp.push_back(make_pair(&irelStart, SYMTAB_IREL_START));
tmp.push_back(make_pair(&irelEnd, SYMTAB_IREL_END));
if (!replaceHandler(globalIrelHandler, dyninstIrelHandler, tmp)) {
return false;
}
}
}


/*
* Special Case 2: Issue a warning if attempting to link pthreads into a binary
* that originally did not support it or into a binary that is stripped. This
Expand Down

0 comments on commit 6896ff0

Please sign in to comment.