Skip to content

Commit 020801b

Browse files
author
George Karpenkov
authored
Update -sanitize=fuzzer option to take into account new libFuzzer location. (#11595)
1 parent ef9dffa commit 020801b

File tree

4 files changed

+18
-50
lines changed

4 files changed

+18
-50
lines changed

cmake/modules/SwiftComponents.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
# * clang-resource-dir-symlink -- install a symlink to the Clang resource
5454
# directory (which contains builtin headers) under 'lib/swift/clang'. This is
5555
# useful when Clang and Swift are installed side-by-side.
56-
# * llvm-resource-dir-symlink -- install a symlink to the LLVM resource directory.
5756
# * stdlib -- the Swift standard library.
5857
# * stdlib-experimental -- the Swift standard library module for experimental
5958
# APIs.
@@ -67,7 +66,7 @@
6766
# * toolchain-dev-tools -- install development tools useful in a shared toolchain
6867
# * dev -- headers and libraries required to use Swift compiler as a library.
6968
set(_SWIFT_DEFINED_COMPONENTS
70-
"autolink-driver;compiler;clang-builtin-headers;clang-resource-dir-symlink;llvm-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;stdlib;stdlib-experimental;swift-syntax;sdk-overlay;editor-integration;tools;testsuite-tools;toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers")
69+
"autolink-driver;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;stdlib;stdlib-experimental;swift-syntax;sdk-overlay;editor-integration;tools;testsuite-tools;toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers")
7170

7271
macro(swift_configure_components)
7372
# Set the SWIFT_INSTALL_COMPONENTS variable to the default value if it is not passed in via -D

lib/Driver/ToolChains.cpp

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,10 +1063,13 @@ getDarwinLibraryNameSuffixForTriple(const llvm::Triple &triple) {
10631063
}
10641064

10651065
static std::string
1066-
getSanitizerRuntimeLibNameForDarwin(StringRef Sanitizer, const llvm::Triple &Triple) {
1066+
getSanitizerRuntimeLibNameForDarwin(StringRef Sanitizer,
1067+
const llvm::Triple &Triple,
1068+
bool shared = true) {
10671069
return (Twine("libclang_rt.")
10681070
+ Sanitizer + "_"
1069-
+ getDarwinLibraryNameSuffixForTriple(Triple) + "_dynamic.dylib").str();
1071+
+ getDarwinLibraryNameSuffixForTriple(Triple)
1072+
+ (shared ? "_dynamic.dylib" : ".a")).str();
10701073
}
10711074

10721075
static std::string
@@ -1141,16 +1144,19 @@ addLinkRuntimeLibForLinux(const ArgList &Args, ArgStringList &Arguments,
11411144
static void
11421145
addLinkSanitizerLibArgsForDarwin(const ArgList &Args,
11431146
ArgStringList &Arguments,
1144-
StringRef Sanitizer, const ToolChain &TC) {
1147+
StringRef Sanitizer,
1148+
const ToolChain &TC,
1149+
bool shared = true
1150+
) {
11451151
// Sanitizer runtime libraries requires C++.
11461152
Arguments.push_back("-lc++");
11471153
// Add explicit dependency on -lc++abi, as -lc++ doesn't re-export
11481154
// all RTTI-related symbols that are used.
11491155
Arguments.push_back("-lc++abi");
11501156

11511157
addLinkRuntimeLibForDarwin(Args, Arguments,
1152-
getSanitizerRuntimeLibNameForDarwin(Sanitizer, TC.getTriple()),
1153-
/*AddRPath=*/ true, TC);
1158+
getSanitizerRuntimeLibNameForDarwin(Sanitizer, TC.getTriple(), shared),
1159+
/*AddRPath=*/ shared, TC);
11541160
}
11551161

11561162
static void
@@ -1175,40 +1181,6 @@ addLinkSanitizerLibArgsForLinux(const ArgList &Args,
11751181
Arguments.push_back("-ldl");
11761182
}
11771183

1178-
static void
1179-
addLinkFuzzerLibArgsForDarwin(const ArgList &Args,
1180-
ArgStringList &Arguments,
1181-
const ToolChain &TC) {
1182-
1183-
// libFuzzer requires C++.
1184-
Arguments.push_back("-lc++");
1185-
1186-
// Link libfuzzer.
1187-
SmallString<128> Dir;
1188-
getRuntimeLibraryPath(Dir, Args, TC);
1189-
llvm::sys::path::remove_filename(Dir);
1190-
llvm::sys::path::append(Dir, "llvm", "libLLVMFuzzer.a");
1191-
SmallString<128> P(Dir);
1192-
1193-
Arguments.push_back(Args.MakeArgString(P));
1194-
}
1195-
1196-
static void
1197-
addLinkFuzzerLibArgsForLinux(const ArgList &Args,
1198-
ArgStringList &Arguments,
1199-
const ToolChain &TC) {
1200-
Arguments.push_back("-lstdc++");
1201-
1202-
// Link libfuzzer.
1203-
SmallString<128> Dir;
1204-
getRuntimeLibraryPath(Dir, Args, TC);
1205-
llvm::sys::path::remove_filename(Dir);
1206-
llvm::sys::path::append(Dir, "llvm", "libLLVMFuzzer.a");
1207-
SmallString<128> P(Dir);
1208-
1209-
Arguments.push_back(Args.MakeArgString(P));
1210-
}
1211-
12121184
ToolChain::InvocationInfo
12131185
toolchains::Darwin::constructInvocation(const LinkJobAction &job,
12141186
const JobContext &context) const {
@@ -1348,7 +1320,8 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job,
13481320
// Only link in libFuzzer for executables.
13491321
if (job.getKind() == LinkKind::Executable &&
13501322
(context.OI.SelectedSanitizers & SanitizerKind::Fuzzer))
1351-
addLinkFuzzerLibArgsForDarwin(context.Args, Arguments, *this);
1323+
addLinkSanitizerLibArgsForDarwin(
1324+
context.Args, Arguments, "fuzzer", *this, /*shared=*/false);
13521325

13531326
if (context.Args.hasArg(options::OPT_embed_bitcode,
13541327
options::OPT_embed_bitcode_marker)) {
@@ -1724,7 +1697,9 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
17241697
addLinkSanitizerLibArgsForLinux(context.Args, Arguments, "tsan", *this);
17251698

17261699
if (context.OI.SelectedSanitizers & SanitizerKind::Fuzzer)
1727-
addLinkFuzzerLibArgsForLinux(context.Args, Arguments, *this);
1700+
addLinkRuntimeLibForLinux(context.Args, Arguments,
1701+
getSanitizerRuntimeLibNameForLinux(
1702+
"fuzzer", this->getTriple()), *this);
17281703
}
17291704
}
17301705

stdlib/public/SwiftShims/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,6 @@ swift_install_symlink_component(clang-resource-dir-symlink
156156
TARGET ../clang/${CLANG_VERSION}
157157
DESTINATION "lib/swift")
158158

159-
# Adding link to "llvm" at install time.
160-
swift_install_symlink_component(llvm-resource-dir-symlink
161-
LINK_NAME llvm
162-
TARGET ../
163-
DESTINATION "lib/swift")
164-
165159
# Possibly install Clang headers under Clang's resource directory in case we
166160
# need to use a different version of the headers than the installed Clang. This
167161
# should be used in conjunction with clang-resource-dir-symlink.

test/Driver/fuzzer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %swiftc_driver -driver-print-jobs -sanitize=fuzzer,address %s | %FileCheck -check-prefix=LIBFUZZER %s
22

3-
// LIBFUZZER: libLLVMFuzzer.a
3+
// LIBFUZZER: libclang_rt.fuzzer
44
@_cdecl("LLVMFuzzerTestOneInput") public func fuzzOneInput(Data: UnsafePointer<CChar>, Size: CLong) -> CInt {
55
return 0;
66
}

0 commit comments

Comments
 (0)