[compiler-rt] 1464b8e - Revert "Move interceptors for libresolv functions to MSan (#119071)"

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 15 11:05:19 PST 2024


Author: Nico Weber
Date: 2024-12-15T14:04:56-05:00
New Revision: 1464b8ec8a675fd11dc7280db1c56aac03771b0a

URL: https://github.com/llvm/llvm-project/commit/1464b8ec8a675fd11dc7280db1c56aac03771b0a
DIFF: https://github.com/llvm/llvm-project/commit/1464b8ec8a675fd11dc7280db1c56aac03771b0a.diff

LOG: Revert "Move interceptors for libresolv functions to MSan (#119071)"

This reverts commit f5f965058a5f9b835382f96bd4041bc7e608ece0.
Breaks a test on some bots, see
https://github.com/llvm/llvm-project/pull/119071#issuecomment-2544000926

Added: 
    compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp
    compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp

Modified: 
    clang/lib/Driver/ToolChains/CommonArgs.cpp
    clang/test/Driver/sanitizer-ld.c
    compiler-rt/lib/msan/msan_interceptors.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Removed: 
    compiler-rt/test/msan/Linux/dn_expand.cpp


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 3c78b12b0741e0..ca675c117418cb 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1443,7 +1443,7 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-      !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())
+      !TC.getTriple().isMusl())
     CmdArgs.push_back("-lresolv");
 }
 

diff  --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
index 877a01c3de3047..c83066a334001a 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -15,7 +15,7 @@
 // CHECK-ASAN-LINUX: "-lpthread"
 // CHECK-ASAN-LINUX: "-lrt"
 // CHECK-ASAN-LINUX: "-ldl"
-// CHECK-ASAN-LINUX-NOT: "-lresolv"
+// CHECK-ASAN-LINUX: "-lresolv"
 
 // RUN: %clang -fsanitize=address -fno-sanitize-link-runtime -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -143,7 +143,7 @@
 // CHECK-ASAN-LINUX-CXX: "-lpthread"
 // CHECK-ASAN-LINUX-CXX: "-lrt"
 // CHECK-ASAN-LINUX-CXX: "-ldl"
-// CHECK-ASAN-LINUX-CXX-NOT: "-lresolv"
+// CHECK-ASAN-LINUX-CXX: "-lresolv"
 
 // RUN: %clang -### %s -o /dev/null -fsanitize=address \
 // RUN:     --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform \
@@ -292,7 +292,7 @@
 // CHECK-TSAN-LINUX-CXX: "-lpthread"
 // CHECK-TSAN-LINUX-CXX: "-lrt"
 // CHECK-TSAN-LINUX-CXX: "-ldl"
-// CHECK-TSAN-LINUX-CXX-NOT: "-lresolv"
+// CHECK-TSAN-LINUX-CXX: "-lresolv"
 
 // RUN: %clang -fsanitize=thread -fno-sanitize-link-runtime -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -365,7 +365,7 @@
 // CHECK-UBSAN-LINUX-NOT: libclang_rt.ubsan_standalone_cxx
 // CHECK-UBSAN-LINUX-NOT: "-lstdc++"
 // CHECK-UBSAN-LINUX: "-lpthread"
-// CHECK-UBSAN-LINUX-NOT: "-lresolv"
+// CHECK-UBSAN-LINUX: "-lresolv"
 
 // RUN: %clang -fsanitize=undefined -fno-sanitize-link-runtime -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -438,7 +438,7 @@
 // CHECK-UBSAN-LINUX-CXX: "-lstdc++"
 // CHECK-UBSAN-LINUX-CXX-NOT: libclang_rt.asan
 // CHECK-UBSAN-LINUX-CXX: "-lpthread"
-// CHECK-UBSAN-LINUX-CXX-NOT: "-lresolv"
+// CHECK-UBSAN-LINUX-CXX: "-lresolv"
 
 // RUN: %clang -fsanitize=undefined -fsanitize-minimal-runtime -### %s 2>&1 \
 // RUN:     --target=i386-unknown-linux -fuse-ld=ld \
@@ -448,7 +448,7 @@
 // CHECK-UBSAN-MINIMAL-LINUX: "{{.*}}ld{{(.exe)?}}"
 // CHECK-UBSAN-MINIMAL-LINUX: "--whole-archive" "{{.*}}libclang_rt.ubsan_minimal.a" "--no-whole-archive"
 // CHECK-UBSAN-MINIMAL-LINUX: "-lpthread"
-// CHECK-UBSAN-MINIMAL-LINUX-NOT: "-lresolv"
+// CHECK-UBSAN-MINIMAL-LINUX: "-lresolv"
 
 // RUN: %clang -fsanitize=undefined -fsanitize-minimal-runtime -### %s 2>&1 \
 // RUN:     --target=x86_64-apple-darwin -fuse-ld=ld \
@@ -485,7 +485,7 @@
 // CHECK-ASAN-UBSAN-LINUX-NOT: libclang_rt.ubsan
 // CHECK-ASAN-UBSAN-LINUX-NOT: "-lstdc++"
 // CHECK-ASAN-UBSAN-LINUX: "-lpthread"
-// CHECK-ASAN-UBSAN-LINUX-NOT: "-lresolv"
+// CHECK-ASAN-UBSAN-LINUX: "-lresolv"
 
 // RUN: %clangxx -fsanitize=address,undefined -### %s 2>&1 \
 // RUN:     --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform \
@@ -498,7 +498,7 @@
 // CHECK-ASAN-UBSAN-LINUX-CXX-NOT: libclang_rt.ubsan
 // CHECK-ASAN-UBSAN-LINUX-CXX: "-lstdc++"
 // CHECK-ASAN-UBSAN-LINUX-CXX: "-lpthread"
-// CHECK-ASAN-UBSAN-LINUX-CXX-NOT: "-lresolv"
+// CHECK-ASAN-UBSAN-LINUX-CXX: "-lresolv"
 
 // RUN: %clangxx -fsanitize=memory,undefined -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -541,7 +541,7 @@
 // CHECK-LSAN-LINUX: libclang_rt.lsan.a"
 // CHECK-LSAN-LINUX: "-lpthread"
 // CHECK-LSAN-LINUX: "-ldl"
-// CHECK-LSAN-LINUX-NOT: "-lresolv"
+// CHECK-LSAN-LINUX: "-lresolv"
 
 // RUN: %clang -fsanitize=leak -fno-sanitize-link-runtime -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -564,7 +564,7 @@
 // CHECK-LSAN-COV-LINUX-NOT: libclang_rt.ubsan
 // CHECK-LSAN-COV-LINUX: "-lpthread"
 // CHECK-LSAN-COV-LINUX: "-ldl"
-// CHECK-LSAN-COV-LINUX-NOT: "-lresolv"
+// CHECK-LSAN-COV-LINUX: "-lresolv"
 
 // RUN: %clang -fsanitize=leak,address -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -586,7 +586,7 @@
 // CHECK-ASAN-COV-LINUX-NOT: libclang_rt.ubsan
 // CHECK-ASAN-COV-LINUX-NOT: "-lstdc++"
 // CHECK-ASAN-COV-LINUX: "-lpthread"
-// CHECK-ASAN-COV-LINUX-NOT: "-lresolv"
+// CHECK-ASAN-COV-LINUX: "-lresolv"
 
 // RUN: %clang -fsanitize=memory -fsanitize-coverage=func -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -610,7 +610,7 @@
 // CHECK-DFSAN-COV-LINUX-NOT: libclang_rt.ubsan
 // CHECK-DFSAN-COV-LINUX-NOT: "-lstdc++"
 // CHECK-DFSAN-COV-LINUX: "-lpthread"
-// CHECK-DFSAN-COV-LINUX-NOT: "-lresolv"
+// CHECK-DFSAN-COV-LINUX: "-lresolv"
 
 // RUN: %clang -fsanitize=undefined -fsanitize-coverage=func -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -621,7 +621,7 @@
 // CHECK-UBSAN-COV-LINUX: "--whole-archive" "{{.*}}libclang_rt.ubsan_standalone.a" "--no-whole-archive"
 // CHECK-UBSAN-COV-LINUX-NOT: "-lstdc++"
 // CHECK-UBSAN-COV-LINUX: "-lpthread"
-// CHECK-UBSAN-COV-LINUX-NOT: "-lresolv"
+// CHECK-UBSAN-COV-LINUX: "-lresolv"
 
 // RUN: %clang -fsanitize-coverage=func -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -632,7 +632,7 @@
 // CHECK-COV-LINUX: "--whole-archive" "{{.*}}libclang_rt.ubsan_standalone.a" "--no-whole-archive"
 // CHECK-COV-LINUX-NOT: "-lstdc++"
 // CHECK-COV-LINUX: "-lpthread"
-// CHECK-COV-LINUX-NOT: "-lresolv"
+// CHECK-COV-LINUX: "-lresolv"
 
 // RUN: %clang -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -fuse-ld=ld -fsanitize=numerical \
@@ -644,8 +644,7 @@
 // CHECK-NSAN-LINUX-NOT: "-lc"
 // CHECK-NSAN-LINUX-NOT: libclang_rt.ubsan
 // CHECK-NSAN-LINUX: libclang_rt.nsan.a"
-// CHECK-NSAN-LINUX: "-lpthread" "-lrt" "-lm" "-ldl"
-// CHECK-NSAN-LINUX-NOT: "-lresolv"
+// CHECK-NSAN-LINUX: "-lpthread" "-lrt" "-lm" "-ldl" "-lresolv"
 
 // RUN: %clang -### %s 2>&1 --target=x86_64-unknown-linux -fuse-ld=ld -fsanitize=numerical -shared-libsan \
 // RUN:     -resource-dir=%S/Inputs/resource_dir \
@@ -758,7 +757,7 @@
 // CHECK-SAFESTACK-LINUX: libclang_rt.safestack.a"
 // CHECK-SAFESTACK-LINUX: "-lpthread"
 // CHECK-SAFESTACK-LINUX: "-ldl"
-// CHECK-SAFESTACK-LINUX-NOT: "-lresolv"
+// CHECK-SAFESTACK-LINUX: "-lresolv"
 
 // RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -958,7 +957,7 @@
 // CHECK-SCUDO-LINUX-NOT: "-lstdc++"
 // CHECK-SCUDO-LINUX: "-lpthread"
 // CHECK-SCUDO-LINUX: "-ldl"
-// CHECK-SCUDO-LINUX-NOT: "-lresolv"
+// CHECK-SCUDO-LINUX: "-lresolv"
 
 // RUN: %clang -### %s -o %t.so -shared 2>&1 \
 // RUN:     --target=i386-unknown-linux -fuse-ld=ld -fsanitize=scudo -shared-libsan \
@@ -1019,7 +1018,7 @@
 // CHECK-HWASAN-X86-64-LINUX: "-lpthread"
 // CHECK-HWASAN-X86-64-LINUX: "-lrt"
 // CHECK-HWASAN-X86-64-LINUX: "-ldl"
-// CHECK-HWASAN-X86-64-LINUX-NOT: "-lresolv"
+// CHECK-HWASAN-X86-64-LINUX: "-lresolv"
 
 // RUN: %clang -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress \
@@ -1068,7 +1067,7 @@
 // CHECK-HWASAN-AARCH64-LINUX: "-lpthread"
 // CHECK-HWASAN-AARCH64-LINUX: "-lrt"
 // CHECK-HWASAN-AARCH64-LINUX: "-ldl"
-// CHECK-HWASAN-AARCH64-LINUX-NOT: "-lresolv"
+// CHECK-HWASAN-AARCH64-LINUX: "-lresolv"
 
 // RUN: %clang -### %s 2>&1 \
 // RUN:     --target=aarch64-unknown-linux -fuse-ld=ld -fsanitize=hwaddress \

diff  --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index f0b1dc905678b1..76255cdb742a39 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -1358,79 +1358,6 @@ INTERCEPTOR(int, forkpty, int *aparent, char *name, const void *termp,
 #define MSAN_MAYBE_INTERCEPT_FORKPTY
 #endif
 
-#if SANITIZER_LINUX && !SANITIZER_ANDROID
-INTERCEPTOR(int, __b64_ntop, unsigned char const *src, SIZE_T srclength,
-            char *target, SIZE_T targsize) {
-  ENSURE_MSAN_INITED();
-  CHECK_UNPOISONED(src, srclength);
-  InterceptorScope interceptor_scope;
-  int res = REAL(__b64_ntop)(src, srclength, target, targsize);
-  if (res >= 0)
-    __msan_unpoison(target, res + 1);
-  return res;
-}
-INTERCEPTOR(int, __b64_pton, char const *src, char *target, SIZE_T targsize) {
-  ENSURE_MSAN_INITED();
-  CHECK_UNPOISONED(src, internal_strlen(src) + 1);
-  InterceptorScope interceptor_scope;
-  int res = REAL(__b64_pton)(src, target, targsize);
-  if (res >= 0)
-    __msan_unpoison(target, res);
-  return res;
-}
-#  define MSAN_MAYBE_INTERCEPT___B64_TO \
-    MSAN_INTERCEPT_FUNC(__b64_ntop);    \
-    COMMON_INTERCEPT_FUNCTION(__b64_pton);
-#else
-#  define MSAN_MAYBE_INTERCEPT___B64_TO
-#endif
-
-#if SANITIZER_LINUX && !SANITIZER_ANDROID
-#  if __GLIBC_PREREQ(2, 34)
-// Changed with https://sourceware.org/git/?p=glibc.git;h=640bbdf
-#    define DN_COMP_INTERCEPTOR_NAME dn_comp
-#    define DN_EXPAND_INTERCEPTOR_NAME dn_expand
-#  else
-#    define DN_COMP_INTERCEPTOR_NAME __dn_comp
-#    define DN_EXPAND_INTERCEPTOR_NAME __dn_expand
-#  endif
-INTERCEPTOR(int, DN_COMP_INTERCEPTOR_NAME, unsigned char *exp_dn,
-            unsigned char *comp_dn, int length, unsigned char **dnptrs,
-            unsigned char **lastdnptr) {
-  ENSURE_MSAN_INITED();
-  InterceptorScope interceptor_scope;
-  int res = REAL(DN_COMP_INTERCEPTOR_NAME)(exp_dn, comp_dn, length, dnptrs,
-                                           lastdnptr);
-  if (res >= 0) {
-    __msan_unpoison(comp_dn, res);
-    if (dnptrs && lastdnptr) {
-      unsigned char **p = dnptrs;
-      for (; p != lastdnptr && *p; ++p);
-      if (p != lastdnptr)
-        ++p;
-      __msan_unpoison(dnptrs, (p - dnptrs) * sizeof(*p));
-    }
-  }
-  return res;
-}
-INTERCEPTOR(int, DN_EXPAND_INTERCEPTOR_NAME, unsigned char const *base,
-            unsigned char const *end, unsigned char const *src, char *dest,
-            int space) {
-  ENSURE_MSAN_INITED();
-  // TODO: add read check if __dn_comp intercept added
-  InterceptorScope interceptor_scope;
-  int res = REAL(DN_EXPAND_INTERCEPTOR_NAME)(base, end, src, dest, space);
-  if (res >= 0)
-    __msan_unpoison(dest, internal_strlen(dest) + 1);
-  return res;
-}
-#  define MSAN_MAYBE_INTERCEPT_DN_COMP_EXPAND      \
-    MSAN_INTERCEPT_FUNC(DN_COMP_INTERCEPTOR_NAME); \
-    MSAN_INTERCEPT_FUNC(DN_EXPAND_INTERCEPTOR_NAME);
-#else
-#  define MSAN_MAYBE_INTERCEPT_DN_COMP_EXPAND
-#endif
-
 struct MSanInterceptorContext {
   bool in_interceptor_scope;
 };
@@ -1989,9 +1916,6 @@ void InitializeInterceptors() {
   MSAN_MAYBE_INTERCEPT_OPENPTY;
   MSAN_MAYBE_INTERCEPT_FORKPTY;
 
-  MSAN_MAYBE_INTERCEPT___B64_TO;
-  MSAN_MAYBE_INTERCEPT_DN_COMP_EXPAND;
-
   inited = 1;
 }
 } // namespace __msan

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 133eec755bfa59..47436a6cd20f0b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -2538,6 +2538,82 @@ INTERCEPTOR(int, glob64, const char *pattern, int flags,
 #define INIT_GLOB64
 #endif  // SANITIZER_INTERCEPT_GLOB64
 
+#if SANITIZER_INTERCEPT___B64_TO
+INTERCEPTOR(int, __b64_ntop, unsigned char const *src, SIZE_T srclength,
+            char *target, SIZE_T targsize) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, __b64_ntop, src, srclength, target, targsize);
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, src, srclength);
+  int res = REAL(__b64_ntop)(src, srclength, target, targsize);
+  if (res >= 0)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, target, res + 1);
+  return res;
+}
+INTERCEPTOR(int, __b64_pton, char const *src, char *target, SIZE_T targsize) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, __b64_pton, src, target, targsize);
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, src, internal_strlen(src) + 1);
+  int res = REAL(__b64_pton)(src, target, targsize);
+  if (res >= 0)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, target, res);
+  return res;
+}
+#define INIT___B64_TO                      \
+    COMMON_INTERCEPT_FUNCTION(__b64_ntop); \
+    COMMON_INTERCEPT_FUNCTION(__b64_pton);
+#else  // SANITIZER_INTERCEPT___B64_TO
+#define INIT___B64_TO
+#endif  // SANITIZER_INTERCEPT___B64_TO
+
+#if SANITIZER_INTERCEPT_DN_COMP_EXPAND
+#  if __GLIBC_PREREQ(2, 34)
+// Changed with https://sourceware.org/git/?p=glibc.git;h=640bbdf
+#    define DN_COMP_INTERCEPTOR_NAME dn_comp
+#    define DN_EXPAND_INTERCEPTOR_NAME dn_expand
+#  else
+#    define DN_COMP_INTERCEPTOR_NAME __dn_comp
+#    define DN_EXPAND_INTERCEPTOR_NAME __dn_expand
+#  endif
+INTERCEPTOR(int, DN_COMP_INTERCEPTOR_NAME, unsigned char *exp_dn,
+            unsigned char *comp_dn, int length, unsigned char **dnptrs,
+            unsigned char **lastdnptr) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, DN_COMP_INTERCEPTOR_NAME, exp_dn, comp_dn,
+                           length, dnptrs, lastdnptr);
+  int res = REAL(DN_COMP_INTERCEPTOR_NAME)(exp_dn, comp_dn, length, dnptrs,
+                                           lastdnptr);
+  if (res >= 0) {
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, comp_dn, res);
+    if (dnptrs && lastdnptr) {
+      unsigned char **p = dnptrs;
+      for (; p != lastdnptr && *p; ++p)
+        ;
+      if (p != lastdnptr)
+        ++p;
+      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dnptrs, (p - dnptrs) * sizeof(*p));
+    }
+  }
+  return res;
+}
+INTERCEPTOR(int, DN_EXPAND_INTERCEPTOR_NAME, unsigned char const *base,
+            unsigned char const *end, unsigned char const *src, char *dest,
+            int space) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, DN_EXPAND_INTERCEPTOR_NAME, base, end, src,
+                           dest, space);
+  // TODO: add read check if __dn_comp intercept added
+  int res = REAL(DN_EXPAND_INTERCEPTOR_NAME)(base, end, src, dest, space);
+  if (res >= 0)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, internal_strlen(dest) + 1);
+  return res;
+}
+#  define INIT_DN_COMP_EXPAND                            \
+    COMMON_INTERCEPT_FUNCTION(DN_COMP_INTERCEPTOR_NAME); \
+    COMMON_INTERCEPT_FUNCTION(DN_EXPAND_INTERCEPTOR_NAME);
+#else  // SANITIZER_INTERCEPT_DN_COMP_EXPAND
+#  define INIT_DN_COMP_EXPAND
+#endif  // SANITIZER_INTERCEPT_DN_COMP_EXPAND
+
 #if SANITIZER_INTERCEPT_POSIX_SPAWN
 
 template <class RealSpawnPtr>
@@ -10270,6 +10346,8 @@ static void InitializeCommonInterceptors() {
   INIT_TIMESPEC_GET;
   INIT_GLOB;
   INIT_GLOB64;
+  INIT___B64_TO;
+  INIT_DN_COMP_EXPAND;
   INIT_POSIX_SPAWN;
   INIT_WAIT;
   INIT_WAIT4;

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index b4940b66da9717..190cad7cf7c3f7 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -266,6 +266,8 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_TIMESPEC_GET SI_LINUX
 #define SANITIZER_INTERCEPT_GLOB (SI_GLIBC || SI_SOLARIS)
 #define SANITIZER_INTERCEPT_GLOB64 SI_GLIBC
+#define SANITIZER_INTERCEPT___B64_TO SI_LINUX_NOT_ANDROID
+#define SANITIZER_INTERCEPT_DN_COMP_EXPAND SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT_POSIX_SPAWN SI_POSIX
 #define SANITIZER_INTERCEPT_WAIT SI_POSIX
 #define SANITIZER_INTERCEPT_INET SI_POSIX

diff  --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp
new file mode 100644
index 00000000000000..96fd0138648b34
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp
@@ -0,0 +1,42 @@
+// RUN: %clangxx %s -o %t && %run %t %p
+
+#include <assert.h>
+#include <resolv.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+int main(int iArgc, char *szArgv[]) {
+  // Check NTOP writing
+  const char *src = "base64 test data";
+  size_t src_len = strlen(src);
+  size_t dst_len = ((src_len + 2) / 3) * 4 + 1;
+  char dst[dst_len];
+  int res = b64_ntop(reinterpret_cast<const unsigned char *>(src), src_len, dst,
+                     dst_len);
+  assert(res >= 0);
+  assert(strcmp(dst, "YmFzZTY0IHRlc3QgZGF0YQ==") == 0);
+
+  // Check PTON writing
+  unsigned char target[dst_len];
+  res = b64_pton(dst, target, dst_len);
+  assert(res >= 0);
+  assert(strncmp(reinterpret_cast<const char *>(target), src, res) == 0);
+
+  // Check NTOP writing for zero length src
+  src = "";
+  src_len = strlen(src);
+  assert(((src_len + 2) / 3) * 4 + 1 < dst_len);
+  res = b64_ntop(reinterpret_cast<const unsigned char *>(src), src_len, dst,
+                 dst_len);
+  assert(res >= 0);
+  assert(strcmp(dst, "") == 0);
+
+  // Check PTON writing for zero length src
+  dst[0] = '\0';
+  res = b64_pton(dst, target, dst_len);
+  assert(res >= 0);
+  assert(strncmp(reinterpret_cast<const char *>(target), src, res) == 0);
+
+  return 0;
+}

diff  --git a/compiler-rt/test/msan/Linux/dn_expand.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp
similarity index 79%
rename from compiler-rt/test/msan/Linux/dn_expand.cpp
rename to compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp
index a37da83df00223..8fdfa7a6cc1a4c 100644
--- a/compiler-rt/test/msan/Linux/dn_expand.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp
@@ -1,10 +1,10 @@
-// RUN: %clangxx_msan %s -o %t && %run %t %p
+// RUN: %clangxx %s -o %t && %run %t %p
 
 #include <assert.h>
 #include <resolv.h>
 #include <string.h>
 
-#include <sanitizer/msan_interface.h>
+#include "sanitizer_common/sanitizer_specific.h"
 
 void testWrite() {
   char unsigned input[] = {0xff, 0xc5, 0xf7, 0xff, 0x00, 0x00, 0xff, 0x0a, 0x00,
@@ -18,7 +18,7 @@ void testWrite() {
 
   assert(res == 12);
   assert(strcmp(output, "google\\.com") == 0);
-  __msan_check_mem_is_initialized(output, strlen(output) + 1);
+  check_mem_is_good(output, strlen(output) + 1);
 }
 
 void testWriteZeroLength() {
@@ -33,7 +33,7 @@ void testWriteZeroLength() {
 
   assert(res == 1);
   assert(strcmp(output, "") == 0);
-  __msan_check_mem_is_initialized(output, strlen(output) + 1);
+  check_mem_is_good(output, strlen(output) + 1);
 }
 
 void testComp() {
@@ -49,17 +49,17 @@ void testComp() {
   char unsigned *n1 = mb;
   int res = dn_comp("llvm.org", mb, me - mb, pb, pe);
   assert(res == 10);
-  __msan_check_mem_is_initialized(mb, res);
+  check_mem_is_good(mb, res);
   // pb is [msg, llvm.org, nullptr]
-  __msan_check_mem_is_initialized(pb, sizeof(*pb) * 3);
+  check_mem_is_good(pb, sizeof(*pb) * 3);
   mb += res;
 
   char unsigned *n2 = mb;
   res = dn_comp("lab.llvm.org", mb, me - mb, pb, pe);
   assert(res == 6);
-  __msan_check_mem_is_initialized(mb, res);
+  check_mem_is_good(mb, res);
   // pb is [msg, llvm.org, lab.llvm.org, nullptr]
-  __msan_check_mem_is_initialized(pb, sizeof(*pb) * 4);
+  check_mem_is_good(pb, sizeof(*pb) * 4);
   mb += res;
 
   {
@@ -69,7 +69,7 @@ void testComp() {
     fprintf(stderr, "%d\n", res);
     assert(res == 10);
     assert(strcmp(output, "llvm.org") == 0);
-    __msan_check_mem_is_initialized(output, strlen(output) + 1);
+    check_mem_is_good(output, strlen(output) + 1);
   }
 
   {
@@ -78,7 +78,7 @@ void testComp() {
 
     assert(res == 6);
     assert(strcmp(output, "lab.llvm.org") == 0);
-    __msan_check_mem_is_initialized(output, strlen(output) + 1);
+    check_mem_is_good(output, strlen(output) + 1);
   }
 }
 


        


More information about the llvm-commits mailing list