summaryrefslogtreecommitdiff
path: root/lib/asan/asan_linux.cc
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2014-04-02 13:09:22 +0000
committerAlexey Samsonov <samsonov@google.com>2014-04-02 13:09:22 +0000
commit2686e6405ef2d5f6755efc511bc455c3a82d4a2c (patch)
treed0903331317bde3be0c2ccbad45494e0fe9ba4fb /lib/asan/asan_linux.cc
parent6580609fe2d8910025db6efb6be7033a1a2671cd (diff)
[ASan] Fix incompatible runtimes check: don't iterate /proc/self/maps on every call to __asan_init
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@205418 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan/asan_linux.cc')
-rw-r--r--lib/asan/asan_linux.cc39
1 files changed, 22 insertions, 17 deletions
diff --git a/lib/asan/asan_linux.cc b/lib/asan/asan_linux.cc
index 8ad9de781..777cb43bf 100644
--- a/lib/asan/asan_linux.cc
+++ b/lib/asan/asan_linux.cc
@@ -96,6 +96,11 @@ static bool IsDynamicRTName(const char *libname) {
internal_strstr(libname, "libasan.so");
}
+static void ReportIncompatibleRT() {
+ Report("Your application is linked against incompatible ASan runtimes.\n");
+ Die();
+}
+
void AsanCheckDynamicRTPrereqs() {
// Ensure that dynamic RT is the first DSO in the list
const char *first_dso_name = 0;
@@ -113,27 +118,27 @@ void AsanCheckIncompatibleRT() {
if (__asan_rt_version == ASAN_RT_VERSION_UNDEFINED) {
__asan_rt_version = ASAN_RT_VERSION_DYNAMIC;
} else if (__asan_rt_version != ASAN_RT_VERSION_DYNAMIC) {
- Report("Your application is linked against "
- "incompatible ASan runtimes.\n");
- Die();
+ ReportIncompatibleRT();
}
} else {
- // Ensure that dynamic runtime is not present. We should detect it
- // as early as possible, otherwise ASan interceptors could bind to
- // the functions in dynamic ASan runtime instead of the functions in
- // system libraries, causing crashes later in ASan initialization.
- MemoryMappingLayout proc_maps(/*cache_enabled*/true);
- char filename[128];
- while (proc_maps.Next(0, 0, 0, filename, sizeof(filename), 0)) {
- if (IsDynamicRTName(filename)) {
- Report("Your application is linked against "
- "incompatible ASan runtimes.\n");
- Die();
+ if (__asan_rt_version == ASAN_RT_VERSION_UNDEFINED) {
+ // Ensure that dynamic runtime is not present. We should detect it
+ // as early as possible, otherwise ASan interceptors could bind to
+ // the functions in dynamic ASan runtime instead of the functions in
+ // system libraries, causing crashes later in ASan initialization.
+ MemoryMappingLayout proc_maps(/*cache_enabled*/true);
+ char filename[128];
+ while (proc_maps.Next(0, 0, 0, filename, sizeof(filename), 0)) {
+ if (IsDynamicRTName(filename)) {
+ Report("Your application is linked against "
+ "incompatible ASan runtimes.\n");
+ Die();
+ }
}
+ __asan_rt_version = ASAN_RT_VERSION_STATIC;
+ } else if (__asan_rt_version != ASAN_RT_VERSION_STATIC) {
+ ReportIncompatibleRT();
}
-
- CHECK_NE(__asan_rt_version, ASAN_RT_VERSION_DYNAMIC);
- __asan_rt_version = ASAN_RT_VERSION_STATIC;
}
}
#endif // SANITIZER_ANDROID