Skip to content

Commit

Permalink
i#4318 xarch memtrace: Make alt lib dir take precedence
Browse files Browse the repository at this point in the history
Moves the -alt_module_dir for finding binaries during trace
post-processing to take precedence over the recorded path, to allow
avoiding problems when an identical-seeming path exists on the
processing machine (e.g., system libraries) on UNIX where we have no
checksum or other library distinguisher.

Tested manually on a case where a system library in the same path as
on the recorded machine caused failure.

Issue: #4318
  • Loading branch information
derekbruening committed Jul 6, 2020
1 parent 9fddeb8 commit e623735
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion clients/drcachesim/common/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ droption_t<std::string> op_alt_module_dir(
DROPTION_SCOPE_FRONTEND, "alt_module_dir", "", "Alternate module search directory",
"Specifies a directory containing libraries referenced in -module_file for "
"analysis tools, or in the raw modules file for post-prcoessing of offline "
"raw trace files.");
"raw trace files. This directory takes precedence over the recorded path.");

droption_t<std::string> op_funclist_file(
DROPTION_SCOPE_ALL, "funclist_file", "",
Expand Down
3 changes: 2 additions & 1 deletion clients/drcachesim/tools/opcode_mix_launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ static droption_t<std::string> op_module_file(

static droption_t<std::string> op_alt_module_dir(
DROPTION_SCOPE_FRONTEND, "alt_module_dir", "", "Alternate module search directory",
"Specifies a directory containing libraries referenced in -module_file.");
"Specifies a directory containing libraries referenced in -module_file. "
"This directory takes precedence over the recorded path.");

droption_t<unsigned int> op_verbose(DROPTION_SCOPE_ALL, "verbose", 0, 0, 64,
"Verbosity level",
Expand Down
18 changes: 14 additions & 4 deletions clients/drcachesim/tracer/raw2trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,18 +346,28 @@ module_mapper_t::read_and_map_modules()
modvec_[info.containing_index].map_base, 0));
} else {
size_t map_size;
byte *base_pc =
dr_map_executable_file(info.path, DR_MAPEXE_SKIP_WRITABLE, &map_size);
if (base_pc == NULL && !alt_module_dir_.empty()) {
byte *base_pc = NULL;
if (!alt_module_dir_.empty()) {
// First try the specified module dir. It takes precedence to allow
// overriding the recorded path even when an identical-seeming path
// exists on the processing machine (e.g., system libraries).
// XXX: We should add a checksum on UNIX to match Windows and have
// a sanity check on the library version.
std::string basename(info.path);
size_t sep_index = basename.find_last_of(DIRSEP ALT_DIRSEP);
if (sep_index != std::string::npos)
basename = std::string(basename, sep_index + 1, std::string::npos);
std::string new_path = alt_module_dir_ + DIRSEP + basename;
VPRINT(1, "Failed to find %s; trying %s\n", info.path, new_path.c_str());
VPRINT(2, "Trying to map %s\n", new_path.c_str());
base_pc = dr_map_executable_file(new_path.c_str(),
DR_MAPEXE_SKIP_WRITABLE, &map_size);
}
if (base_pc == NULL) {
// Try the recorded path.
VPRINT(2, "Trying to map %s\n", info.path);
base_pc =
dr_map_executable_file(info.path, DR_MAPEXE_SKIP_WRITABLE, &map_size);
}
if (base_pc == NULL) {
// We expect to fail to map dynamorio.dll for x64 Windows as it
// is built /fixed. (We could try to have the map succeed w/o relocs,
Expand Down
2 changes: 1 addition & 1 deletion clients/drcachesim/tracer/raw2trace_launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static droption_t<std::string>
static droption_t<std::string> op_alt_module_dir(
DROPTION_SCOPE_FRONTEND, "alt_module_dir", "", "Alternate module search directory",
"Specifies a directory to look for binaries needed to post-process "
"the trace that are not found in the path recorded during tracing.");
"the trace. This directory takes precedence over the recorded path.");

static droption_t<unsigned int> op_verbose(DROPTION_SCOPE_FRONTEND, "verbose", 0,
"Verbosity level for diagnostic output",
Expand Down

0 comments on commit e623735

Please sign in to comment.