Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1716,11 +1716,17 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
CmdArgs.push_back(Args.MakeArgString(S));
}

// Add shared runtimes before adding fuzzer and its dependencies.
for (auto RT : SharedRuntimes)
addSanitizerRuntime(TC, Args, CmdArgs, RT, true, false);

// Inject libfuzzer dependencies.
bool FuzzerNeedsSanitizerDeps = false;
if (SanArgs.needsFuzzer() && SanArgs.linkRuntimes() &&
!Args.hasArg(options::OPT_shared)) {

addSanitizerRuntime(TC, Args, CmdArgs, "fuzzer", false, true);
FuzzerNeedsSanitizerDeps = true;
if (SanArgs.needsFuzzerInterceptors())
addSanitizerRuntime(TC, Args, CmdArgs, "fuzzer_interceptors", false,
true);
Expand All @@ -1735,8 +1741,6 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
}
}

for (auto RT : SharedRuntimes)
addSanitizerRuntime(TC, Args, CmdArgs, RT, true, false);
for (auto RT : HelperStaticRuntimes)
addSanitizerRuntime(TC, Args, CmdArgs, RT, false, true);
bool AddExportDynamic = false;
Expand Down Expand Up @@ -1769,7 +1773,8 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
CmdArgs.push_back("--android-memtag-stack");
}

return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty();
return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty() ||
FuzzerNeedsSanitizerDeps;
}

bool tools::addXRayRuntime(const ToolChain&TC, const ArgList &Args, ArgStringList &CmdArgs) {
Expand Down
8 changes: 7 additions & 1 deletion clang/test/Driver/fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// CHECK-NOLIB-NOT: libclang_rt.libfuzzer
// CHECK-COV: -fsanitize-coverage-inline-8bit-counters

// Check that we respect whether thes tandard library should be linked
// Check that we respect whether the standard library should be linked.
// statically.
//
// RUN: %clang -fsanitize=fuzzer --target=i386-unknown-linux -stdlib=libstdc++ %s -### 2>&1 | FileCheck --check-prefixes=CHECK-LIBSTDCXX-DYNAMIC %s
Expand All @@ -43,6 +43,12 @@
// RUN: %clang -fsanitize=fuzzer --target=i386-unknown-linux -stdlib=libc++ -static-libstdc++ %s -### 2>&1 | FileCheck --check-prefixes=CHECK-LIBCXX-STATIC %s
// CHECK-LIBCXX-STATIC: "-Bstatic" "-lc++"

// Check that we add required sanitizer dependencies when dynamically linking
// the sanitizer runtime (e.g. libFuzzer uses ceilf in libm).
//
// RUN: %clang -fsanitize=fuzzer -shared-libsan --target=x86_64-linux-gnu %s -### 2>&1 | FileCheck --check-prefixes=CHECK-SHARED-LIBSAN %s
// CHECK-SHARED-LIBSAN: -lm

int LLVMFuzzerTestOneInput(const char *Data, long Size) {
return 0;
}
8 changes: 8 additions & 0 deletions clang/test/Driver/sanitizer-ld.c
Original file line number Diff line number Diff line change
Expand Up @@ -1393,3 +1393,11 @@
// RUN: | %{filecheck} --check-prefix=CHECK-RELOCATABLE-LINK-TSAN-RTLIB
//
// CHECK-RELOCATABLE-LINK-TSAN-RTLIB-NOT: "{{.*}}tsan{{.*}}"

// RUN: %clang -fsanitize=fuzzer,address -shared-libsan -### %s 2>&1 \
// RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
// RUN: | FileCheck %s --check-prefix=CHECK-FUZZER-WITH-SHARED-ASAN-ORDER
//
// CHECK-FUZZER-WITH-SHARED-ASAN-ORDER: "{{.*}}libclang_rt.asan.so" "--whole-archive" "{{.*}}libclang_rt.fuzzer.a" "--no-whole-archive" "-lstdc++"