[clang] [compiler-rt] [rtsan] Enable RealtimeSanitizer for FreeBSD (PR #125389)

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 10 13:09:34 PST 2025


================
@@ -864,11 +864,18 @@ INTERCEPTOR(void *, pvalloc, size_t size) {
 #define RTSAN_MAYBE_INTERCEPT_PVALLOC
 #endif
 
+#if !SANITIZER_FREEBSD
+// enabling this interception on freebsd leads to infinite recursion
+// on pthread lib initialization
----------------
davidtrevelyan wrote:

@devnexen sorry - I meant the other end of the stack, not the point at which the segfault happens. Could you set a breakpoint in `pthread_once`, maybe, and share the backtrace again, so we can see the full initiating function call stack?

This is what I mean:

```lldb
⏺ build ❯ lldb ./projects/compiler-rt/lib/rtsan/tests/Rtsan-arm64-Test
(lldb) target create "./projects/compiler-rt/lib/rtsan/tests/Rtsan-arm64-Test"
Current executable set to '/Users/david/Repositories/rtsan/llvm-project/build/projects/compiler-rt/lib/rtsan/tests/Rtsan-arm64-Test' (arm64).
(lldb) br se -n pthread_once
Breakpoint 1: where = libsystem_pthread.dylib`pthread_once, address = 0x000000018044aff4
(lldb) pr la
Process 67543 launched: '/Users/david/Repositories/rtsan/llvm-project/build/projects/compiler-rt/lib/rtsan/tests/Rtsan-arm64-Test' (arm64)
Process 67543 stopped
* thread #1, stop reason = breakpoint 1.1
    frame #0: 0x000000018d10eff4 libsystem_pthread.dylib`pthread_once
libsystem_pthread.dylib`pthread_once:
->  0x18d10eff4 <+0>:  pacibsp
    0x18d10eff8 <+4>:  sub    sp, sp, #0x40
    0x18d10effc <+8>:  stp    x22, x21, [sp, #0x10]
    0x18d10f000 <+12>: stp    x20, x19, [sp, #0x20]
Target 0: (Rtsan-arm64-Test) stopped.
(lldb) bt
* thread #1, stop reason = breakpoint 1.1
  * frame #0: 0x000000018d10eff4 libsystem_pthread.dylib`pthread_once
    frame #1: 0x00000001002958b4 libclang_rt.rtsan_osx_dynamic.dylib`__rtsan::GetContextForThisThread() [inlined] GetContextForThisThreadImpl() at rtsan_context.cpp:34:3 [opt]
    frame #2: 0x00000001002958a0 libclang_rt.rtsan_osx_dynamic.dylib`__rtsan::GetContextForThisThread() at rtsan_context.cpp:62:10 [opt]
    frame #3: 0x000000010029545c libclang_rt.rtsan_osx_dynamic.dylib`__rtsan_notify_intercepted_call(func_name="shm_open") at rtsan.cpp:140:21 [opt]
    frame #4: 0x0000000100297364 libclang_rt.rtsan_osx_dynamic.dylib`wrap_shm_open(name="com.apple.featureflags.shm", oflag=0, mode=16832) at rtsan_interceptors_posix.cpp:973:3 [opt]
    frame #5: 0x000000018cfa41e8 libsystem_featureflags.dylib`_os_feature_table_once + 40
    frame #6: 0x000000018d1455e0 libsystem_platform.dylib`_os_once_callout + 32
    frame #7: 0x000000018cfa41bc libsystem_featureflags.dylib`_os_feature_table + 80
    frame #8: 0x000000018cfa51cc libsystem_featureflags.dylib`_os_feature_enabled_simple_impl + 44
    frame #9: 0x000000018cf29a10 libsystem_malloc.dylib`__malloc_init + 104
    frame #10: 0x000000019abd2604 libSystem.B.dylib`libSystem_initializer + 204
    frame #11: 0x000000018cda7d54 dyld`invocation function for block in dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 276
    frame #12: 0x000000018cde64d0 dyld`invocation function for block in dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 340
    frame #13: 0x000000018cdd9c38 dyld`invocation function for block in dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 496
    frame #14: 0x000000018cd8c2dc dyld`dyld3::MachOFile::forEachLoadCommand(Diagnostics&, void (load_command const*, bool&) block_pointer) const + 300
    frame #15: 0x000000018cdd8bcc dyld`dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 192
    frame #16: 0x000000018cde5fe4 dyld`dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 516
    frame #17: 0x000000018cda7bb4 dyld`dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 176
    frame #18: 0x000000018cdb2be8 dyld`dyld4::PrebuiltLoader::runInitializers(dyld4::RuntimeState&) const + 44
    frame #19: 0x000000018cdc78b8 dyld`dyld4::APIs::runAllInitializersForMain() + 84
    frame #20: 0x000000018cd918c8 dyld`dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3268
    frame #21: 0x000000018cd90bc0 dyld`dyld4::start(dyld4::KernelArgs*, void*, void*)::$_0::operator()() const + 544
    frame #22: 0x000000018cd9005c dyld`start + 2304
```

https://github.com/llvm/llvm-project/pull/125389


More information about the cfe-commits mailing list