[compiler-rt] r198012 - [Sanitizer] Use different MemoryMappingLayout::DumpListOfModules on Linux and Mac.
Alexey Samsonov
samsonov at google.com
Wed Dec 25 03:29:19 PST 2013
Author: samsonov
Date: Wed Dec 25 05:29:19 2013
New Revision: 198012
URL: http://llvm.org/viewvc/llvm-project?rev=198012&view=rev
Log:
[Sanitizer] Use different MemoryMappingLayout::DumpListOfModules on Linux and Mac.
Make a unit test added in r198004 more robust.
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_posix.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc?rev=198012&r1=198011&r2=198012&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc Wed Dec 25 05:29:19 2013
@@ -13,6 +13,7 @@
#include "sanitizer_platform.h"
#if SANITIZER_LINUX
#include "sanitizer_common.h"
+#include "sanitizer_placement_new.h"
#include "sanitizer_procmaps.h"
namespace __sanitizer {
@@ -199,6 +200,30 @@ bool MemoryMappingLayout::GetObjectNameA
protection);
}
+uptr MemoryMappingLayout::DumpListOfModules(LoadedModule *modules,
+ uptr max_modules,
+ string_predicate_t filter) {
+ Reset();
+ uptr cur_beg, cur_end;
+ InternalScopedBuffer<char> module_name(kMaxPathLength);
+ uptr n_modules = 0;
+ for (uptr i = 0; n_modules < max_modules &&
+ Next(&cur_beg, &cur_end, 0, module_name.data(),
+ module_name.size(), 0);
+ i++) {
+ const char *cur_name = module_name.data();
+ if (cur_name[0] == '\0')
+ continue;
+ if (filter && !filter(cur_name))
+ continue;
+ void *mem = &modules[n_modules];
+ LoadedModule *cur_module = new(mem) LoadedModule(cur_name, cur_beg);
+ cur_module->addAddressRange(cur_beg, cur_end);
+ n_modules++;
+ }
+ return n_modules;
+}
+
void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size) {
char *smaps = 0;
uptr smaps_cap = 0;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_mac.cc?rev=198012&r1=198011&r2=198012&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_mac.cc Wed Dec 25 05:29:19 2013
@@ -13,6 +13,7 @@
#include "sanitizer_platform.h"
#if SANITIZER_MAC
#include "sanitizer_common.h"
+#include "sanitizer_placement_new.h"
#include "sanitizer_procmaps.h"
#include <mach-o/dyld.h>
@@ -160,6 +161,36 @@ bool MemoryMappingLayout::GetObjectNameA
protection);
}
+uptr MemoryMappingLayout::DumpListOfModules(LoadedModule *modules,
+ uptr max_modules,
+ string_predicate_t filter) {
+ Reset();
+ uptr cur_beg, cur_end;
+ InternalScopedBuffer<char> module_name(kMaxPathLength);
+ uptr n_modules = 0;
+ for (uptr i = 0; n_modules < max_modules &&
+ Next(&cur_beg, &cur_end, 0, module_name.data(),
+ module_name.size(), 0);
+ i++) {
+ const char *cur_name = module_name.data();
+ if (cur_name[0] == '\0')
+ continue;
+ if (filter && !filter(cur_name))
+ continue;
+ LoadedModule *cur_module = 0;
+ if (n_modules > 0 &&
+ 0 == internal_strcmp(cur_name, modules[n_modules - 1].full_name())) {
+ cur_module = &modules[n_modules - 1];
+ } else {
+ void *mem = &modules[n_modules];
+ cur_module = new(mem) LoadedModule(cur_name, cur_beg);
+ n_modules++;
+ }
+ cur_module->addAddressRange(cur_beg, cur_end);
+ }
+ return n_modules;
+}
+
} // namespace __sanitizer
#endif // SANITIZER_MAC
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_posix.cc?rev=198012&r1=198011&r2=198012&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_posix.cc Wed Dec 25 05:29:19 2013
@@ -13,7 +13,6 @@
#include "sanitizer_platform.h"
#if SANITIZER_POSIX
#include "sanitizer_common.h"
-#include "sanitizer_placement_new.h"
#include "sanitizer_procmaps.h"
namespace __sanitizer {
@@ -48,36 +47,6 @@ bool MemoryMappingLayout::IterateForObje
return false;
}
-uptr MemoryMappingLayout::DumpListOfModules(LoadedModule *modules,
- uptr max_modules,
- string_predicate_t filter) {
- Reset();
- uptr cur_beg, cur_end, cur_offset;
- InternalScopedBuffer<char> module_name(kMaxPathLength);
- uptr n_modules = 0;
- for (uptr i = 0; n_modules < max_modules &&
- Next(&cur_beg, &cur_end, &cur_offset, module_name.data(),
- module_name.size(), 0);
- i++) {
- const char *cur_name = module_name.data();
- if (cur_name[0] == '\0')
- continue;
- if (filter && !filter(cur_name))
- continue;
- LoadedModule *cur_module = 0;
- if (n_modules > 0 &&
- 0 == internal_strcmp(cur_name, modules[n_modules - 1].full_name())) {
- cur_module = &modules[n_modules - 1];
- } else {
- void *mem = &modules[n_modules];
- cur_module = new(mem) LoadedModule(cur_name, cur_beg);
- n_modules++;
- }
- cur_module->addAddressRange(cur_beg, cur_end);
- }
- return n_modules;
-}
-
} // namespace __sanitizer
#endif // SANITIZER_POSIX
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc?rev=198012&r1=198011&r2=198012&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc Wed Dec 25 05:29:19 2013
@@ -15,6 +15,9 @@
#include <stdlib.h>
+static void noop() {}
+extern const char *argv0;
+
namespace __sanitizer {
#if SANITIZER_LINUX && !SANITIZER_ANDROID
@@ -27,11 +30,11 @@ TEST(MemoryMappingLayout, CodeRange) {
}
#endif
-static void noop() {}
-
TEST(MemoryMappingLayout, DumpListOfModules) {
+ const char *last_slash = strrchr(argv0, '/');
+ const char *binary_name = last_slash ? last_slash + 1 : argv0;
MemoryMappingLayout memory_mapping(false);
- const uptr kMaxModules = 10;
+ const uptr kMaxModules = 100;
LoadedModule *modules =
(LoadedModule *)malloc(kMaxModules * sizeof(LoadedModule));
uptr n_modules = memory_mapping.DumpListOfModules(modules, kMaxModules, 0);
@@ -40,7 +43,7 @@ TEST(MemoryMappingLayout, DumpListOfModu
for (uptr i = 0; i < n_modules; ++i) {
if (modules[i].containsAddress((uptr)&noop)) {
// Verify that the module name is sane.
- if (strstr(modules[i].full_name(), "Sanitizer") != 0)
+ if (strstr(modules[i].full_name(), binary_name) != 0)
found = true;
}
}
Modified: compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test.cc?rev=198012&r1=198011&r2=198012&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test.cc (original)
+++ compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test.cc Wed Dec 25 05:29:19 2013
@@ -45,6 +45,9 @@ int run_tests(int argc, char **argv) {
return res;
}
+const char *argv0;
+
int main(int argc, char **argv) {
+ argv0 = argv[0];
return run_tests(argc, argv);
}
More information about the llvm-commits
mailing list