summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2018-08-28 08:10:27 +0000
committerHans Wennborg <hans@hanshq.net>2018-08-28 08:10:27 +0000
commit21c4b64a79ecd95e020ef7a083fa046c3b777bcf (patch)
treec02d45184f3774fd63fc669e280dc04344a0bb90
parent35d20abb3eda4a6f259a5517ca76e382d470107c (diff)
Merging r340758 and r340769:
------------------------------------------------------------------------ r340758 | vitalybuka | 2018-08-27 19:26:28 +0200 (Mon, 27 Aug 2018) | 5 lines Revert "[lsan] Do not check for leaks in the forked process" Users need leak reports in forks. This reverts commit r334036. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r340769 | vitalybuka | 2018-08-27 21:15:05 +0200 (Mon, 27 Aug 2018) | 3 lines [lsan] Check that leak sanitizer works in the forked process Regression test for PR38698 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/branches/release_70@340801 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/lsan/lsan_common.cc9
-rw-r--r--test/lsan/TestCases/Linux/fork_and_leak.cc23
-rw-r--r--test/lsan/TestCases/Linux/fork_with_threads.cc35
3 files changed, 23 insertions, 44 deletions
diff --git a/lib/lsan/lsan_common.cc b/lib/lsan/lsan_common.cc
index 012a673c3..eaa5cadc8 100644
--- a/lib/lsan/lsan_common.cc
+++ b/lib/lsan/lsan_common.cc
@@ -100,8 +100,6 @@ static SuppressionContext *GetSuppressionContext() {
static InternalMmapVector<RootRegion> *root_regions;
-static uptr initialized_for_pid;
-
InternalMmapVector<RootRegion> const *GetRootRegions() { return root_regions; }
void InitializeRootRegions() {
@@ -115,7 +113,6 @@ const char *MaybeCallLsanDefaultOptions() {
}
void InitCommonLsan() {
- initialized_for_pid = internal_getpid();
InitializeRootRegions();
if (common_flags()->detect_leaks) {
// Initialization which can fail or print warnings should only be done if
@@ -571,12 +568,6 @@ static void CheckForLeaksCallback(const SuspendedThreadsList &suspended_threads,
static bool CheckForLeaks() {
if (&__lsan_is_turned_off && __lsan_is_turned_off())
return false;
- if (initialized_for_pid != internal_getpid()) {
- // If process was forked and it had threads we fail to detect references
- // from other threads.
- Report("WARNING: LeakSanitizer is disabled in forked process.\n");
- return false;
- }
EnsureMainThreadIDIsCorrect();
CheckForLeaksParam param;
param.success = false;
diff --git a/test/lsan/TestCases/Linux/fork_and_leak.cc b/test/lsan/TestCases/Linux/fork_and_leak.cc
new file mode 100644
index 000000000..d7427ce3e
--- /dev/null
+++ b/test/lsan/TestCases/Linux/fork_and_leak.cc
@@ -0,0 +1,23 @@
+// Test that leaks detected after forking without exec().
+// RUN: %clangxx_lsan %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+int main() {
+ pid_t pid = fork();
+ assert(pid >= 0);
+ if (pid > 0) {
+ int status = 0;
+ waitpid(pid, &status, 0);
+ assert(WIFEXITED(status));
+ return WEXITSTATUS(status);
+ } else {
+ malloc(1337);
+ // CHECK: LeakSanitizer: detected memory leaks
+ }
+ return 0;
+}
+
diff --git a/test/lsan/TestCases/Linux/fork_with_threads.cc b/test/lsan/TestCases/Linux/fork_with_threads.cc
deleted file mode 100644
index 221c5d249..000000000
--- a/test/lsan/TestCases/Linux/fork_with_threads.cc
+++ /dev/null
@@ -1,35 +0,0 @@
-// Test forked process does not run lsan.
-// RUN: %clangxx_lsan %s -o %t && %run %t 2>&1 | FileCheck %s
-
-#include <pthread.h>
-#include <stdlib.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-static pthread_barrier_t barrier;
-
-// CHECK-NOT: SUMMARY: {{(Leak|Address)}}Sanitizer:
-static void *thread_func(void *arg) {
- void *buffer = malloc(1337);
- pthread_barrier_wait(&barrier);
- for (;;)
- pthread_yield();
- return 0;
-}
-
-int main() {
- pthread_barrier_init(&barrier, 0, 2);
- pthread_t tid;
- int res = pthread_create(&tid, 0, thread_func, 0);
- pthread_barrier_wait(&barrier);
- pthread_barrier_destroy(&barrier);
-
- pid_t pid = fork();
- if (pid > 0) {
- int status = 0;
- waitpid(pid, &status, 0);
- }
- return 0;
-}
-
-// CHECK: WARNING: LeakSanitizer is disabled in forked process