Skip to content

Commit 3c9e3af

Browse files
iluuu1994ju1ius
andcommitted
Disable LSan tls
LSan crashes a lot recently, and it seems to be caused by tls. Since we're not actually making use of C11s _Thread_local we can set the use_tls=0 option. This causes a false positive in dlopen() that apprently uses thread locals. We suppress this with __lsan_disable()/__lsan_enable(). Co-authored-by: ju1ius <[email protected]>
1 parent ee82c94 commit 3c9e3af

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

Zend/zend_portability.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,31 @@
153153
# define PHP_RTLD_MODE RTLD_LAZY
154154
# endif
155155

156+
# ifdef __SANITIZE_ADDRESS__
157+
# include "sanitizer/lsan_interface.h"
158+
# endif
159+
160+
/* dl uses a thread local variable internally. Due to LSan crashing we're setting use_tls=0, which
161+
* will report a leak inside dlopen() that we need to suppress. */
162+
static inline void *zend_dlopen(const char *file, int mode)
163+
{
164+
# ifdef __SANITIZE_ADDRESS__
165+
__lsan_disable();
166+
# endif
167+
void *ptr = dlopen(file, mode);
168+
# ifdef __SANITIZE_ADDRESS__
169+
__lsan_enable();
170+
# endif
171+
return ptr;
172+
}
156173
# if defined(RTLD_GROUP) && defined(RTLD_WORLD) && defined(RTLD_PARENT)
157-
# define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL | RTLD_GROUP | RTLD_WORLD | RTLD_PARENT)
174+
# define DL_LOAD(libname) zend_dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL | RTLD_GROUP | RTLD_WORLD | RTLD_PARENT)
158175
# elif defined(RTLD_DEEPBIND) && !defined(__SANITIZE_ADDRESS__) && !__has_feature(memory_sanitizer)
159-
# define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL | RTLD_DEEPBIND)
176+
# define DL_LOAD(libname) zend_dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL | RTLD_DEEPBIND)
160177
# else
161-
# define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL)
178+
# define DL_LOAD(libname) zend_dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL)
162179
# endif
180+
163181
# define DL_UNLOAD dlclose
164182
# if defined(DLSYM_NEEDS_UNDERSCORE)
165183
# define DL_FETCH_SYMBOL(h,s) dlsym((h), "_" s)

run-tests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ function main(): void
586586
$lsanSuppressions = __DIR__ . '/.github/lsan-suppressions.txt';
587587
if (file_exists($lsanSuppressions)) {
588588
$environment['LSAN_OPTIONS'] = 'suppressions=' . $lsanSuppressions
589-
. ':print_suppressions=0';
589+
. ':print_suppressions=0:use_tls=0';
590590
}
591591
break;
592592
case '--repeat':

0 commit comments

Comments
 (0)