Skip to content

Commit 429a293

Browse files
committed
Remove path searching
1 parent ab9cd92 commit 429a293

11 files changed

+47
-82
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_aix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ uptr ReadBinaryName(char *buf, uptr buf_len) {
384384
}
385385

386386
// Find the binary in the env PATH.
387-
if ((path = FindPathToBinaryOrLibrary(binary_name)) != nullptr)
387+
if ((path = FindPathToBinary(binary_name)) != nullptr)
388388
return internal_snprintf(buf, buf_len, "%s", path);
389389

390390
return 0;

compiler-rt/lib/sanitizer_common/sanitizer_common.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,6 @@ const char *GetProcessName() {
275275
return process_name_cache_str;
276276
}
277277

278-
const char *GetBinaryName() {
279-
if (binary_name_cache_str[0] == '\0')
280-
ReadBinaryName(binary_name_cache_str, sizeof(binary_name_cache_str));
281-
return binary_name_cache_str;
282-
}
283-
284278
static uptr ReadProcessName(/*out*/ char *buf, uptr buf_len) {
285279
ReadLongProcessName(buf, buf_len);
286280
char *s = const_cast<char *>(StripModuleName(buf));

compiler-rt/lib/sanitizer_common/sanitizer_common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ uptr ReadBinaryNameCached(/*out*/char *buf, uptr buf_len);
290290
uptr ReadBinaryDir(/*out*/ char *buf, uptr buf_len);
291291
uptr ReadLongProcessName(/*out*/ char *buf, uptr buf_len);
292292
const char *GetProcessName();
293-
const char *GetBinaryName();
294293
void UpdateProcessName();
295294
void CacheBinaryName();
296295
void DisableCoreDumperIfNecessary();

compiler-rt/lib/sanitizer_common/sanitizer_file.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ bool ReadFileToVector(const char *file_name,
203203

204204
static const char kPathSeparator = SANITIZER_WINDOWS ? ';' : ':';
205205

206-
char *FindPathToBinaryOrLibrary(const char *name, const char *env_string) {
206+
char *FindPathToBinary(const char *name, const char *env_string) {
207207
if (FileExists(name)) {
208208
return internal_strdup(name);
209209
}
210210

211-
const char *path = GetEnv(env_string);
211+
const char *path = GetEnv("PATH");
212212
if (!path)
213213
return nullptr;
214214
uptr name_len = internal_strlen(name);

compiler-rt/lib/sanitizer_common/sanitizer_file.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ bool SupportsColoredOutput(fd_t fd);
7979
const char *GetPwd();
8080
bool FileExists(const char *filename);
8181
bool DirExists(const char *path);
82-
char *FindPathToBinaryOrLibrary(const char *name,
83-
const char *env_string = "PATH");
82+
char *FindPathToBinary(const char *name);
8483
bool IsPathSeparator(const char c);
8584
bool IsAbsolutePath(const char *path);
8685
// Returns true on success, false on failure.

compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class MemoryMappedSegment {
4040
public:
4141
explicit MemoryMappedSegment(char *buff = nullptr, uptr size = 0)
4242
: filename(buff), filename_size(size), data_(nullptr) {}
43+
explicit MemoryMappedSegment(char *buff, uptr size, char *display_buff, uptr display_size)
44+
: filename(buff), filename_size(size), displayname(display_buff),
45+
displayname_size(display_size), data_(nullptr) {}
4346
~MemoryMappedSegment() {}
4447

4548
bool IsReadable() const { return protection & kProtectionRead; }
@@ -54,6 +57,8 @@ class MemoryMappedSegment {
5457
uptr offset;
5558
char *filename; // owned by caller
5659
uptr filename_size;
60+
char *displayname;
61+
uptr displayname_size;
5762
uptr protection;
5863
ModuleArch arch;
5964
u8 uuid[kModuleUUIDSize];

compiler-rt/lib/sanitizer_common/sanitizer_procmaps_aix.cpp

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -102,68 +102,24 @@ bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
102102
segment->protection |= kProtectionShared;
103103

104104
if (segment->filename && mapIter->pr_pathoff) {
105-
if (type == MA_MAINDATA || type == MA_MAINEXEC) {
106-
// AIX procmap does not print full name for the binary, however when using
107-
// llvm-symbolizer, it requires the binary must be with full name.
108-
const char *BinaryName = GetBinaryName();
109-
uptr len =
110-
Min((uptr)(internal_strlen(BinaryName)), segment->filename_size - 1);
111-
internal_strncpy(segment->filename, BinaryName, len);
112-
segment->filename[len] = 0;
113-
} else {
114-
// AIX library may exist as xxx.a[yyy.o], to find the path to xxx.a,
115-
// the [yyy.o] part needs to be removed.
116-
117-
// TODO FIXME
118-
const char *pathPtr = data_.proc_self_maps.data + mapIter->pr_pathoff;
119-
uptr len = Min((uptr)internal_strlen(pathPtr),
120-
segment->filename_size - 1);
121-
internal_strncpy(segment->filename, pathPtr, len);
122-
segment->filename[len] = 0;
123-
// AIX procmap does not print full name for user's library , however when
124-
// use llvm-symbolizer, it requires the library must be with full name.
125-
if ((type == MA_SLIBTEXT || type == MA_PLIBDATA) &&
126-
segment->filename[0] != '/') {
127-
// First check if the library is in the directory where the binary is
128-
// executed. On AIX, there is no need to put library in same dir with
129-
// the binary to path search envs.
130-
char *path = nullptr;
131-
char buf[kMaxPathLength];
132-
unsigned buf_len = kMaxPathLength;
133-
bool found = false;
134-
if ((path = internal_getcwd(buf, buf_len)) != nullptr) {
135-
// if the path is too long, don't do other search either.
136-
if (internal_strlen(path) > segment->filename_size - 1)
137-
found = true;
138-
else {
139-
internal_snprintf(
140-
buf + internal_strlen(path),
141-
segment->filename_size - 1 - internal_strlen(path), "/%s",
142-
segment->filename);
143-
if (FileExists(buf)) {
144-
uptr len =
145-
Min((uptr)(internal_strlen(buf)), segment->filename_size - 1);
146-
internal_strncpy(segment->filename, buf, len);
147-
segment->filename[len] = 0;
148-
found = true;
149-
}
150-
}
151-
}
152-
if (!found) {
153-
const char *LibName =
154-
FindPathToBinaryOrLibrary(segment->filename, "LIBPATH");
155-
CHECK(LibName);
156-
uptr len =
157-
Min((uptr)(internal_strlen(LibName)), segment->filename_size - 1);
158-
internal_strncpy(segment->filename, LibName, len);
159-
segment->filename[len] = 0;
160-
found = true;
161-
}
162-
CHECK(found);
163-
}
164-
}
105+
uptr len;
106+
constexpr unsigned BUFFER_SIZE = 128;
107+
char objPath[BUFFER_SIZE] = {};
108+
// Use path /proc/<pid>/object/<object_id> to pass to the symbolizer.
109+
internal_snprintf(objPath, BUFFER_SIZE, "/proc/%d/object/%s", internal_getpid(), mapIter->pr_mapname);
110+
len = Min((uptr)internal_strlen(objPath), segment->filename_size - 1);
111+
internal_strncpy(segment->filename, objPath, len);
112+
segment->filename[len] = 0;
113+
114+
// We don't have the full path to user libraries, so we use what we have available as the
115+
// display name.
116+
const char *displayPath = data_.proc_self_maps.data + mapIter->pr_pathoff;
117+
len = Min((uptr)internal_strlen(displayPath), segment->displayname_size - 1);
118+
internal_strncpy(segment->displayname, displayPath, len);
119+
segment->displayname[len] = 0;
165120
} else if (segment->filename) {
166121
segment->filename[0] = 0;
122+
segment->displayname[0] = 0;
167123
}
168124

169125
assert(mapIter->pr_off == 0 && "expect a zero offset into module.");

compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,21 @@ void MemoryMappingLayout::DumpListOfModules(
121121
InternalMmapVectorNoCtor<LoadedModule> *modules) {
122122
Reset();
123123
InternalMmapVector<char> module_name(kMaxPathLength);
124+
#if SANITIZER_AIX
125+
InternalMmapVector<char> module_displayname(kMaxPathLength);
126+
MemoryMappedSegment segment(module_name.data(), module_name.size(),
127+
module_displayname.data(), module_displayname.size());
128+
#else
124129
MemoryMappedSegment segment(module_name.data(), module_name.size());
130+
#endif
125131
for (uptr i = 0; Next(&segment); i++) {
132+
// On AIX, filename contains /proc/<pid>/object/<object_id> to pass to the symbolizer, so we use displayname to
133+
// contain the real path to present to users
134+
#if SANITIZER_AIX
135+
const char *cur_name = segment.displayname;
136+
#else
126137
const char *cur_name = segment.filename;
138+
#endif
127139
if (cur_name[0] == '\0')
128140
continue;
129141
// Don't subtract 'cur_beg' from the first entry:

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,17 +472,17 @@ static SymbolizerTool *ChooseExternalSymbolizer(LowLevelAllocator *allocator) {
472472
// Otherwise symbolizer program is unknown, let's search $PATH
473473
CHECK(path == nullptr);
474474
#if SANITIZER_APPLE
475-
if (const char *found_path = FindPathToBinaryOrLibrary("atos")) {
475+
if (const char *found_path = FindPathToBinary("atos")) {
476476
VReport(2, "Using atos found at: %s\n", found_path);
477477
return new(*allocator) AtosSymbolizer(found_path, allocator);
478478
}
479479
#endif // SANITIZER_APPLE
480-
if (const char *found_path = FindPathToBinaryOrLibrary("llvm-symbolizer")) {
480+
if (const char *found_path = FindPathToBinary("llvm-symbolizer")) {
481481
VReport(2, "Using llvm-symbolizer found at: %s\n", found_path);
482482
return new(*allocator) LLVMSymbolizer(found_path, allocator);
483483
}
484484
if (common_flags()->allow_addr2line) {
485-
if (const char *found_path = FindPathToBinaryOrLibrary("addr2line")) {
485+
if (const char *found_path = FindPathToBinary("addr2line")) {
486486
VReport(2, "Using addr2line found at: %s\n", found_path);
487487
return new(*allocator) Addr2LinePool(found_path, allocator);
488488
}

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static void ChooseSymbolizerTools(IntrusiveList<SymbolizerTool> *list,
289289
}
290290

291291
const char *path =
292-
user_path ? user_path : FindPathToBinaryOrLibrary("llvm-symbolizer.exe");
292+
user_path ? user_path : FindPathToBinary("llvm-symbolizer.exe");
293293
if (path) {
294294
if (user_path && user_path[0] == '\0') {
295295
VReport(2, "External symbolizer is explicitly disabled.\n");

compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,20 +325,20 @@ INSTANTIATE_TEST_SUITE_P(SortAndDedupTest, SortAndDedupTest,
325325
::testing::ValuesIn(kSortAndDedupTests));
326326

327327
#if SANITIZER_LINUX && !SANITIZER_ANDROID
328-
TEST(SanitizerCommon, FindPathToBinaryOrLibrary) {
329-
char *true_path = FindPathToBinaryOrLibrary("true");
328+
TEST(SanitizerCommon, FindPathToBinary) {
329+
char *true_path = FindPathToBinary("true");
330330
EXPECT_NE((char*)0, internal_strstr(true_path, "/bin/true"));
331331
InternalFree(true_path);
332-
EXPECT_EQ(0, FindPathToBinaryOrLibrary("unexisting_binary.ergjeorj"));
332+
EXPECT_EQ(0, FindPathToBinary("unexisting_binary.ergjeorj"));
333333
}
334334
#elif SANITIZER_WINDOWS
335-
TEST(SanitizerCommon, FindPathToBinaryOrLibrary) {
335+
TEST(SanitizerCommon, FindPathToBinary) {
336336
// ntdll.dll should be on PATH in all supported test environments on all
337337
// supported Windows versions.
338-
char *ntdll_path = FindPathToBinaryOrLibrary("ntdll.dll");
338+
char *ntdll_path = FindPathToBinary("ntdll.dll");
339339
EXPECT_NE((char*)0, internal_strstr(ntdll_path, "ntdll.dll"));
340340
InternalFree(ntdll_path);
341-
EXPECT_EQ(0, FindPathToBinaryOrLibrary("unexisting_binary.ergjeorj"));
341+
EXPECT_EQ(0, FindPathToBinary("unexisting_binary.ergjeorj"));
342342
}
343343
#endif
344344

0 commit comments

Comments
 (0)