Skip to content

Commit

Permalink
In dynamic instrumentation for PIE, finding variables's locations nee…
Browse files Browse the repository at this point in the history
…ds to add the load base of the PIE.

Get rid of wrong, special handling of finding the load base of PIE.
  • Loading branch information
mxz297 committed Feb 14, 2019
1 parent c371022 commit 4aa8702
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 89 deletions.
6 changes: 3 additions & 3 deletions dyninstAPI/src/BPatch_snippet.C
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ BPatch_variableExpr::BPatch_variableExpr(BPatch_addressSpace *in_addSpace,
if (!type)
type = BPatch::bpatch->type_Untyped;

//Address baseAddr = scp->getFunction()->lowlevel_func()->obj()->codeBase();
Address baseAddr = scp->getFunction()->lowlevel_func()->obj()->codeBase();
vector<AstNodePtr> variableASTs;
vector<pair<Offset, Offset> > *ranges = new vector<pair<Offset, Offset> >;
vector<Dyninst::VariableLocation> &locs = lv->getSymtabVar()->getLocationLists();
Expand Down Expand Up @@ -1307,8 +1307,8 @@ BPatch_variableExpr::BPatch_variableExpr(BPatch_addressSpace *in_addSpace,
hi = (Address) -1;
}
else {
low = locs[i].lowPC;
hi = locs[i].hiPC;
low = locs[i].lowPC + baseAddr;
hi = locs[i].hiPC + baseAddr;
}

ranges->push_back(pair<Address, Address>(low, hi));
Expand Down
2 changes: 0 additions & 2 deletions dyninstAPI/src/dynProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,6 @@ class PCProcess : public AddressSpace {
void debugSuicide();
bool dumpImage(std::string outFile);

Address setAOutLoadAddress(fileDescriptor &desc); // platform-specific

// Stackwalking internals
bool walkStack(pdvector<Frame> &stackWalk, PCThread *thread);
bool getActiveFrame(Frame &frame, PCThread *thread);
Expand Down
16 changes: 0 additions & 16 deletions dyninstAPI/src/mapped_object.C
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,6 @@ mapped_object *mapped_object::createMappedObject(fileDescriptor &desc,
desc.setData(new_load_addr);
}
#endif
if (!desc.isSharedObject()) {
//We've seen a case where the a.out is a shared object (RHEL4's
// version of ssh). Check if the shared object flag is set in the
// binary (which is different from the isSharedObject()) call above.
// If so, we need to update the load address.
if (p->proc() &&
(img->getObject()->getObjectType() == SymtabAPI::obj_SharedLib)) {
//Executable is a shared lib
p->proc()->setAOutLoadAddress(desc);
}

// Used to search for main here and enable system call tracing to find out
// when libc.so is loaded -- this is unnecessary now that we use ProcControlAPI
//
// This is now done on-demand when libc is loaded and main has yet to be found
}

// Adds exported functions and variables..
startup_printf("%s[%d]: creating mapped object\n", FILE__, __LINE__);
Expand Down
6 changes: 0 additions & 6 deletions dyninstAPI/src/pdwinnt.C
Original file line number Diff line number Diff line change
Expand Up @@ -885,12 +885,6 @@ bool PCProcess::hideDebugger()
return true;
}

Address PCProcess::setAOutLoadAddress(fileDescriptor &desc)
{
assert(0);
return 0;
}

bool PCEventMuxer::useCallback(Dyninst::ProcControlAPI::EventType et)
{
// This switch statement can be derived from the EventTypes and Events
Expand Down
61 changes: 0 additions & 61 deletions dyninstAPI/src/unix.C
Original file line number Diff line number Diff line change
Expand Up @@ -928,66 +928,5 @@ void BinaryEdit::makeInitAndFiniIfNeeded()
}
}

Address PCProcess::setAOutLoadAddress(fileDescriptor &desc) {
//The load address of the a.out isn't correct. We can't read a
// correct one out of ld-x.x.x.so because it may not be initialized yet,
// and it won't be initialized until we reach main. But we need the load
// address to find main. Darn.
//
//Instead we'll read the entry out of /proc/pid/maps, and try to make a good
// effort to correctly match the fileDescriptor to an entry. Unfortunately,
// symlinks can complicate this, so we'll stat the files and compare inodes

struct stat aout, maps_entry;
map_entries *maps = NULL;
unsigned maps_size = 0, i;
char proc_path[128];
int result;
Address loadAddr = 0;

//Get the inode for the a.out
startup_printf("[%s:%u] - a.out is a shared library, computing load addr\n",
FILE__, __LINE__);
memset(&aout, 0, sizeof(aout));
result = stat(pcProc_->libraries().getExecutable()->getAbsoluteName().c_str(), &aout);
if (result == -1) {
startup_printf("[%s:%u] - setAOutLoadAddress couldn't stat %s: %s\n",
FILE__, __LINE__, proc_path, strerror(errno));
goto done;
}

//Get the maps
maps = getVMMaps(getPid(), maps_size);
if (!maps) {
startup_printf("[%s:%u] - setAOutLoadAddress, getVMMaps return NULL\n",
FILE__, __LINE__);
goto done;
}

//Compare the inode of each map entry to the a.out's
for (i=0; i<maps_size; i++) {
memset(&maps_entry, 0, sizeof(maps_entry));
result = stat(maps[i].path, &maps_entry);
if (result == -1) {
startup_printf("[%s:%u] - setAOutLoadAddress couldn't stat %s: %s\n",
FILE__, __LINE__, maps[i].path, strerror(errno));
continue;
}
if (maps_entry.st_dev == aout.st_dev && maps_entry.st_ino == aout.st_ino)
{
//We have a match

desc.setLoadAddr(maps[i].start);
loadAddr = maps[i].start;
}
}

done:
if (maps)
free(maps);

return loadAddr;
}

#endif

1 change: 0 additions & 1 deletion dyninstAPI/src/vxworks.C
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,6 @@ bool process::hasBeenBound(const SymtabAPI::relocationEntry &,
// In process.C:
// bool process::stop_(bool waitUntilStop) { assert(0); return false; }
// bool process::continueProc_(int sig) { assert(0); return false; }
// Address process::setAOutLoadAddress(fileDescriptor &desc) { assert(0); return 0; }
// bool process::detachForDebugger(const EventRecord &/*crash_event*/) { assert(0); return false; }

#if defined(cap_binary_rewriter)
Expand Down

0 comments on commit 4aa8702

Please sign in to comment.