Skip to content

Commit 8ef9e2b

Browse files
committed
Revert "[libFuzzer] Link libFuzzer's own interceptors when other compiler runtimes are not linked."
This causes binaries linked with this runtime to crash on startup if dlsym uses any of the intercepted functions. (For example, that happens when using tcmalloc as the allocator: dlsym attempts to allocate memory with malloc, and tcmalloc uses strncmp within its implementation.) Also revert dependent commit "[libFuzzer] Disable implicit builtin knowledge about memcmp-like functions when -fsanitize=fuzzer-no-link is given." This reverts commit f78d9fc and 12d1124.
1 parent f6275ca commit 8ef9e2b

File tree

10 files changed

+3
-232
lines changed

10 files changed

+3
-232
lines changed

clang/include/clang/Driver/SanitizerArgs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class SanitizerArgs {
7474
!Sanitizers.has(SanitizerKind::Address) &&
7575
!Sanitizers.has(SanitizerKind::HWAddress);
7676
}
77-
bool needsFuzzerInterceptors() const;
7877
bool needsUbsanRt() const;
7978
bool requiresMinimalRuntime() const { return MinimalRuntime; }
8079
bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,6 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
240240
return TrappingKinds;
241241
}
242242

243-
bool SanitizerArgs::needsFuzzerInterceptors() const {
244-
return needsFuzzer() && !needsAsanRt() && !needsTsanRt() && !needsMsanRt();
245-
}
246-
247243
bool SanitizerArgs::needsUbsanRt() const {
248244
// All of these include ubsan.
249245
if (needsAsanRt() || needsMsanRt() || needsHwasanRt() || needsTsanRt() ||
@@ -1088,22 +1084,6 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
10881084
Sanitizers.has(SanitizerKind::Address))
10891085
CmdArgs.push_back("-fno-assume-sane-operator-new");
10901086

1091-
// libFuzzer wants to intercept calls to certain library functions, so the
1092-
// following -fno-builtin-* flags force the compiler to emit interposable
1093-
// libcalls to these functions. Other sanitizers effectively do the same thing
1094-
// by marking all library call sites with NoBuiltin attribute in their LLVM
1095-
// pass. (see llvm::maybeMarkSanitizerLibraryCallNoBuiltin)
1096-
if (Sanitizers.has(SanitizerKind::FuzzerNoLink)) {
1097-
CmdArgs.push_back("-fno-builtin-memcmp");
1098-
CmdArgs.push_back("-fno-builtin-strncmp");
1099-
CmdArgs.push_back("-fno-builtin-strcmp");
1100-
CmdArgs.push_back("-fno-builtin-strncasecmp");
1101-
CmdArgs.push_back("-fno-builtin-strcasecmp");
1102-
CmdArgs.push_back("-fno-builtin-strstr");
1103-
CmdArgs.push_back("-fno-builtin-strcasestr");
1104-
CmdArgs.push_back("-fno-builtin-memmem");
1105-
}
1106-
11071087
// Require -fvisibility= flag on non-Windows when compiling if vptr CFI is
11081088
// enabled.
11091089
if (Sanitizers.hasOneOf(CFIClasses) && !TC.getTriple().isOSWindows() &&

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,6 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
784784
!Args.hasArg(options::OPT_shared)) {
785785

786786
addSanitizerRuntime(TC, Args, CmdArgs, "fuzzer", false, true);
787-
if (SanArgs.needsFuzzerInterceptors())
788-
addSanitizerRuntime(TC, Args, CmdArgs, "fuzzer_interceptors", false,
789-
true);
790787
if (!Args.hasArg(clang::driver::options::OPT_nostdlibxx))
791788
TC.AddCXXStdlibLibArgs(Args, CmdArgs);
792789
}

compiler-rt/lib/fuzzer/CMakeLists.txt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@ add_compiler_rt_object_libraries(RTfuzzer_main
9999
CFLAGS ${LIBFUZZER_CFLAGS}
100100
DEPS ${LIBFUZZER_DEPS})
101101

102-
add_compiler_rt_object_libraries(RTfuzzer_interceptors
103-
OS ${FUZZER_SUPPORTED_OS}
104-
ARCHS ${FUZZER_SUPPORTED_ARCH}
105-
SOURCES FuzzerInterceptors.cpp
106-
CFLAGS ${LIBFUZZER_CFLAGS}
107-
DEPS ${LIBFUZZER_DEPS})
108-
109102
add_compiler_rt_runtime(clang_rt.fuzzer
110103
STATIC
111104
OS ${FUZZER_SUPPORTED_OS}
@@ -122,14 +115,6 @@ add_compiler_rt_runtime(clang_rt.fuzzer_no_main
122115
CFLAGS ${LIBFUZZER_CFLAGS}
123116
PARENT_TARGET fuzzer)
124117

125-
add_compiler_rt_runtime(clang_rt.fuzzer_interceptors
126-
STATIC
127-
OS ${FUZZER_SUPPORTED_OS}
128-
ARCHS ${FUZZER_SUPPORTED_ARCH}
129-
OBJECT_LIBS RTfuzzer_interceptors
130-
CFLAGS ${LIBFUZZER_CFLAGS}
131-
PARENT_TARGET fuzzer)
132-
133118
if(OS_NAME MATCHES "Linux|Fuchsia" AND
134119
COMPILER_RT_LIBCXX_PATH AND
135120
COMPILER_RT_LIBCXXABI_PATH)
@@ -163,10 +148,7 @@ if(OS_NAME MATCHES "Linux|Fuchsia" AND
163148
add_dependencies(RTfuzzer.${arch} libcxx_fuzzer_${arch}-build)
164149
target_compile_options(RTfuzzer_main.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
165150
add_dependencies(RTfuzzer_main.${arch} libcxx_fuzzer_${arch}-build)
166-
target_compile_options(RTfuzzer_interceptors.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
167-
add_dependencies(RTfuzzer_interceptors.${arch} libcxx_fuzzer_${arch}-build)
168151
partially_link_libcxx(fuzzer_no_main ${LIBCXX_${arch}_PREFIX} ${arch})
169-
partially_link_libcxx(fuzzer_interceptors ${LIBCXX_${arch}_PREFIX} ${arch})
170152
partially_link_libcxx(fuzzer ${LIBCXX_${arch}_PREFIX} ${arch})
171153
endforeach()
172154
endif()

compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp

Lines changed: 0 additions & 170 deletions
This file was deleted.

compiler-rt/test/fuzzer/memcmp.test

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
UNSUPPORTED: freebsd
22
RUN: %cpp_compiler %S/MemcmpTest.cpp -o %t-MemcmpTest
33
RUN: not %run %t-MemcmpTest -seed=1 -runs=10000000 2>&1 | FileCheck %s
4-
5-
RUN: %cpp_compiler -fno-sanitize=address %S/MemcmpTest.cpp -o %t-NoAsanMemcmpTest
6-
RUN: not %run %t-MemcmpTest -seed=1 -runs=10000000 2>&1 | FileCheck %s
7-
84
CHECK: BINGO

compiler-rt/test/fuzzer/memcmp64.test

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
UNSUPPORTED: freebsd
22
RUN: %cpp_compiler %S/Memcmp64BytesTest.cpp -o %t-Memcmp64BytesTest
33
RUN: not %run %t-Memcmp64BytesTest -seed=1 -runs=1000000 2>&1 | FileCheck %s
4-
5-
RUN: %cpp_compiler -fno-sanitize=address %S/Memcmp64BytesTest.cpp -o %t-NoAsanMemcmp64BytesTest
6-
RUN: not %run %t-Memcmp64BytesTest -seed=1 -runs=1000000 2>&1 | FileCheck %s
7-
84
CHECK: BINGO

compiler-rt/test/fuzzer/strcmp.test

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
UNSUPPORTED: freebsd
22
RUN: %cpp_compiler %S/StrcmpTest.cpp -o %t-StrcmpTest
33
RUN: not %run %t-StrcmpTest -seed=1 -runs=2000000 2>&1 | FileCheck %s
4-
5-
RUN: %cpp_compiler -fno-sanitize=address %S/StrcmpTest.cpp -o %t-NoAsanStrcmpTest
6-
RUN: not %run %t-StrcmpTest -seed=1 -runs=2000000 2>&1 | FileCheck %s
7-
84
CHECK: BINGO
5+

compiler-rt/test/fuzzer/strncmp.test

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
UNSUPPORTED: freebsd
22
RUN: %cpp_compiler %S/StrncmpTest.cpp -o %t-StrncmpTest
33
RUN: not %run %t-StrncmpTest -seed=2 -runs=10000000 2>&1 | FileCheck %s
4-
5-
RUN: %cpp_compiler -fno-sanitize=address %S/StrncmpTest.cpp -o %t-NoAsanStrncmpTest
6-
RUN: not %run %t-StrncmpTest -seed=2 -runs=10000000 2>&1 | FileCheck %s
7-
84
CHECK: BINGO
5+

compiler-rt/test/fuzzer/strstr.test

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
UNSUPPORTED: freebsd
22
RUN: %cpp_compiler %S/StrstrTest.cpp -o %t-StrstrTest
33
RUN: not %run %t-StrstrTest -seed=1 -runs=2000000 2>&1 | FileCheck %s
4-
5-
RUN: %cpp_compiler -fno-sanitize=address %S/StrstrTest.cpp -o %t-NoAsanStrstrTest
6-
RUN: not %run %t-StrstrTest -seed=1 -runs=2000000 2>&1 | FileCheck %s
7-
84
CHECK: BINGO
5+

0 commit comments

Comments
 (0)