Skip to content

[nsan] Remove mallopt from nsan_interceptors #101055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2024

Conversation

Calandracas606
Copy link
Contributor

@Calandracas606 Calandracas606 commented Jul 29, 2024

Fixes a build failure on 19.1.0-rc1 when building on linux with musl as the libc

musl does not provide mallopt, whereas glibc does. mallopt has portability issues with other libc implementations. Just remove the use.

@llvmbot
Copy link
Member

llvmbot commented Jul 29, 2024

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

Author: Daniel Martinez (Calandracas606)

Changes

Fixes a build failure on 19.1.0-rc1 when building on linux with musl as the libc

musl does not provide mallopt, whereas glibc does


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

1 Files Affected:

  • (modified) compiler-rt/lib/nsan/nsan_interceptors.cpp (+2-2)
diff --git a/compiler-rt/lib/nsan/nsan_interceptors.cpp b/compiler-rt/lib/nsan/nsan_interceptors.cpp
index 544b44f53cc42..baa8185994113 100644
--- a/compiler-rt/lib/nsan/nsan_interceptors.cpp
+++ b/compiler-rt/lib/nsan/nsan_interceptors.cpp
@@ -21,7 +21,7 @@
 
 #include <wchar.h>
 
-#if SANITIZER_LINUX
+#if SANITIZER_LINUX && defined(__GLIBC__)
 extern "C" int mallopt(int param, int value);
 #endif
 
@@ -210,7 +210,7 @@ void __nsan::InitializeInterceptors() {
   CHECK(!initialized);
 
   // Instruct libc malloc to consume less memory.
-#if SANITIZER_LINUX
+#if SANITIZER_LINUX && defined(__GLIBC__)
   mallopt(1, 0);          // M_MXFAST
   mallopt(-3, 32 * 1024); // M_MMAP_THRESHOLD
 #endif

@MaskRay
Copy link
Member

MaskRay commented Jul 29, 2024

Perhaps we should just remove mallopt. Other sanitizers don't use mallopt. musl doesn't provide mallopt. tcmalloc ignores mallopt. Param 1 conflicts with Android M_INIT_ZYGOTE_CHILD_PROFILING

@Calandracas606
Copy link
Contributor Author

I could update the PR to remove mallopt if prefered

@alexander-shaposhnikov
Copy link
Collaborator

Yeah, i think it should be easier to remove it

Other sanitizers don't use mallopt, musl doesn't provide mallopt,
and tcmalloc ignores mallopt. Its easiest jut to remove it
@Calandracas606 Calandracas606 changed the title don't use mallopt on musl remove mallopt from nsan_interceptors Jul 29, 2024
@MaskRay MaskRay changed the title remove mallopt from nsan_interceptors [nsan] Remove mallopt from nsan_interceptors Jul 29, 2024
@MaskRay MaskRay merged commit 2c3eb8d into llvm:main Jul 29, 2024
6 checks passed
@Calandracas606 Calandracas606 deleted the mallopt-musl branch July 29, 2024 22:22
llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 29, 2024
Fixes a build failure on 19.1.0-rc1 when building on linux with musl as
the libc

musl does not provide mallopt, whereas glibc does. mallopt has
portability issues with other libc implementations. Just remove the use.

Co-authored-by: Daniel Martinez <danielmartinez@cock.li>
(cherry picked from commit 2c3eb8d)
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 30, 2024
Fixes a build failure on 19.1.0-rc1 when building on linux with musl as
the libc

musl does not provide mallopt, whereas glibc does. mallopt has
portability issues with other libc implementations. Just remove the use.

Co-authored-by: Daniel Martinez <danielmartinez@cock.li>
(cherry picked from commit 2c3eb8d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants