[PATCH] D14510: [tsan] Implement `IsGlobalVar` for Darwin
Ismail Pazarbasi via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 9 13:00:54 PST 2015
ismailp created this revision.
ismailp added reviewers: kubabrecka, glider, samsonov, dvyukov, kcc.
ismailp added subscribers: llvm-commits, zaks.anna.
This is one of the oldest patches made for TSan on Darwin.
It could be wrong, and possibly missing some cases.
http://reviews.llvm.org/D14510
Files:
lib/tsan/rtl/tsan_platform_mac.cc
Index: lib/tsan/rtl/tsan_platform_mac.cc
===================================================================
--- lib/tsan/rtl/tsan_platform_mac.cc
+++ lib/tsan/rtl/tsan_platform_mac.cc
@@ -39,6 +39,11 @@
#include <unistd.h>
#include <errno.h>
#include <sched.h>
+#include <mach-o/dyld.h>
+#include <dlfcn.h>
+#include <mach-o/loader.h>
+#include <mach-o/getsect.h>
+#include <mach/mach.h>
namespace __tsan {
@@ -98,6 +103,37 @@
}
#endif
+static bool IsInSegmentRange(uptr addr, mach_header_64 *mh,
+ const char *segname, const char *sectname) {
+ const section_64 *sect = getsectbynamefromheader_64(mh, segname, sectname);
+ if (!sect)
+ return false;
+ return addr >= sect->addr && addr < (sect->addr + sect->size);
+}
+
+static bool IsInitedGlobal(uptr addr, mach_header_64 *mh) {
+ return IsInSegmentRange(addr, mh, SEG_DATA, SECT_DATA);
+}
+
+static bool IsUninitedGlobal(uptr addr, mach_header_64 *mh) {
+ return IsInSegmentRange(addr, mh, SEG_DATA, SECT_COMMON);
+}
+
+static bool IsStringLiteral(uptr addr, mach_header_64 *mh) {
+ return IsInSegmentRange(addr, mh, SEG_TEXT, "__cstring");
+}
+
+
+static bool IsInitedConst(uptr addr, mach_header_64 *mh) {
+ return IsInSegmentRange(addr, mh, SEG_TEXT, "__const");
+}
+
+static bool IsByteLiteral(uptr addr, mach_header_64 *mh, unsigned bytes) {
+ CHECK(bytes == 4 || bytes == 8);
+ return IsInSegmentRange(addr, mh, SEG_TEXT,
+ bytes == 4 ? "__literal4" : "__literal8");
+}
+
uptr GetShadowMemoryConsumption() {
return 0;
}
@@ -179,7 +215,13 @@
#endif
bool IsGlobalVar(uptr addr) {
- return false;
+ Dl_info info;
+ if (!dladdr((void*)addr, &info))
+ return false;
+ mach_header_64 *mh = reinterpret_cast<mach_header_64*>(info.dli_fbase);
+ return IsUninitedGlobal(addr, mh) || IsInitedGlobal(addr, mh) ||
+ IsStringLiteral(addr, mh) || IsInitedConst(addr, mh) ||
+ IsByteLiteral(addr, mh, 4) || IsByteLiteral(addr, mh, 8);
}
} // namespace __tsan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14510.39741.patch
Type: text/x-patch
Size: 2014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151109/36447859/attachment.bin>
More information about the llvm-commits
mailing list