Skip to content

Conversation

@Enna1
Copy link
Contributor

@Enna1 Enna1 commented Aug 18, 2025

Header "lsan/lsan_common.h" is not included, CAN_SANITIZE_LEAKS macro is expanded to 0, so suppression of leaks from dlsym doesn't take effect.

Header "lsan/lsan_common.h" is not included, CAN_SANITIZE_LEAKS macro is expanded to 0, so suppression of leaks from dlsym doesn't take effect.
@Enna1 Enna1 requested a review from vitalybuka August 18, 2025 08:13
@llvmbot
Copy link
Member

llvmbot commented Aug 18, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Mingjie Xu (Enna1)

Changes

Header "lsan/lsan_common.h" is not included, CAN_SANITIZE_LEAKS macro is expanded to 0, so suppression of leaks from dlsym doesn't take effect.


Full diff: https://github.com/llvm/llvm-project/pull/154073.diff

1 Files Affected:

  • (modified) compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp (+1)
diff --git a/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp b/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp index 25ca0a3b0b68e..7609e6cd65b7a 100644 --- a/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp +++ b/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp @@ -14,6 +14,7 @@ #include "hwasan.h" #include "interception/interception.h" +#include "lsan/lsan_common.h" #include "sanitizer_common/sanitizer_allocator_dlsym.h" #include "sanitizer_common/sanitizer_allocator_interface.h" #include "sanitizer_common/sanitizer_mallinfo.h" 
Copy link
Contributor

@fmayer fmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test for this?

@Enna1
Copy link
Contributor Author

Enna1 commented Aug 20, 2025

Can we add a test for this?

Sorry, I don't have a test.

This issue is exposed when I add Wundef to compiler flags.

[12/21] Building CXX object compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases_dynamic.x86_64.dir/hwasan_allocation_functions.cpp.o
In file included from /data00/home/xumingjie.enna1/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:15:
In file included from /data00/home/xumingjie.enna1/llvm-project/compiler-rt/lib/hwasan/hwasan.h:17:
In file included from /data00/home/xumingjie.enna1/llvm-project/compiler-rt/lib/hwasan/hwasan_flags.h:15:
In file included from /data00/home/xumingjie.enna1/llvm-project/compiler-rt/lib/hwasan/../sanitizer_common/sanitizer_internal_defs.h:15:
/data00/home/xumingjie.enna1/llvm-project/compiler-rt/lib/hwasan/../sanitizer_common/sanitizer_platform.h:415:5: warning: 'SANITIZER_GO' is not defined, evaluates to 0 [-Wundef]
415 | #if SANITIZER_GO == 0
| ^
In file included from /data00/home/xumingjie.enna1/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:16:
/data00/home/xumingjie.enna1/llvm-project/compiler-rt/lib/hwasan/../interception/interception.h:171:7: warning: 'SANITIZER_AIX' is not defined, evaluates to 0 [-Wundef]
171 | #elif SANITIZER_AIX
| ^
/data00/home/xumingjie.enna1/llvm-project/compiler-rt/lib/hwasan/../interception/interception.h:380:5: warning: 'SANITIZER_AIX' is not defined, evaluates to 0 [-Wundef]
380 | #if SANITIZER_AIX
| ^
/data00/home/xumingjie.enna1/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:26:7: warning: 'CAN_SANITIZE_LEAKS' is not defined, evaluates to 0 [-Wundef]
26 | # if CAN_SANITIZE_LEAKS
| ^
/data00/home/xumingjie.enna1/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:33:7: warning: 'CAN_SANITIZE_LEAKS' is not defined, evaluates to 0 [-Wundef]
33 | # if CAN_SANITIZE_LEAKS
| ^
5 warnings generated.

@Enna1
Copy link
Contributor Author

Enna1 commented Aug 20, 2025

As you can see, there are other undefined marcos also evaluated to 0.
Maybe we should fix them and add -Wundef when compiling compiler-rt...

@vitalybuka
Copy link
Collaborator

This probably can be extended as test compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c
As is, it does not have consistent leaks, you can try to reproduce without your patch

Copy link
Collaborator

@vitalybuka vitalybuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With or without test it's LGTM
But it could be better with a test.

@vitalybuka
Copy link
Collaborator

vitalybuka commented Sep 10, 2025

As you can see, there are other undefined marcos also evaluated to 0. Maybe we should fix them and add -Wundef when compiling compiler-rt...

-Wundef would be nice, but not in this patch

@vitalybuka vitalybuka closed this Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 participants