Skip to content

Commit 1abaadb

Browse files
committed
[clang][driver] Support HWASan in the Fuchsia toolchain
These contain clang driver changes for supporting HWASan on Fuchsia. This includes hwasan multilibs and the dylib path change. Differential Revision: https://reviews.llvm.org/D99361
1 parent 1c55dcb commit 1abaadb

File tree

6 files changed

+51
-4
lines changed

6 files changed

+51
-4
lines changed

clang/lib/Driver/ToolChains/Fuchsia.cpp

+27-4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA,
9595
std::string Dyld = D.DyldPrefix;
9696
if (SanArgs.needsAsanRt() && SanArgs.needsSharedRt())
9797
Dyld += "asan/";
98+
if (SanArgs.needsHwasanRt() && SanArgs.needsSharedRt())
99+
Dyld += "hwasan/";
98100
if (SanArgs.needsTsanRt() && SanArgs.needsSharedRt())
99101
Dyld += "tsan/";
100102
Dyld += "ld.so.1";
@@ -210,23 +212,41 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple,
210212
.flag("+fsanitize=address")
211213
.flag("-fexceptions")
212214
.flag("+fno-exceptions"));
215+
// HWASan has higher priority because we always want the instrumentated
216+
// version.
217+
Multilibs.push_back(
218+
Multilib("hwasan", {}, {}, 4).flag("+fsanitize=hwaddress"));
219+
// Use the hwasan+noexcept variant with HWASan and -fno-exceptions.
220+
Multilibs.push_back(Multilib("hwasan+noexcept", {}, {}, 5)
221+
.flag("+fsanitize=hwaddress")
222+
.flag("-fexceptions")
223+
.flag("+fno-exceptions"));
213224
// Use the relative vtables ABI.
214225
// TODO: Remove these multilibs once relative vtables are enabled by default
215226
// for Fuchsia.
216-
Multilibs.push_back(Multilib("relative-vtables", {}, {}, 4)
227+
Multilibs.push_back(Multilib("relative-vtables", {}, {}, 6)
217228
.flag("+fexperimental-relative-c++-abi-vtables"));
218-
Multilibs.push_back(Multilib("relative-vtables+noexcept", {}, {}, 5)
229+
Multilibs.push_back(Multilib("relative-vtables+noexcept", {}, {}, 7)
219230
.flag("+fexperimental-relative-c++-abi-vtables")
220231
.flag("-fexceptions")
221232
.flag("+fno-exceptions"));
222-
Multilibs.push_back(Multilib("relative-vtables+asan", {}, {}, 6)
233+
Multilibs.push_back(Multilib("relative-vtables+asan", {}, {}, 8)
223234
.flag("+fexperimental-relative-c++-abi-vtables")
224235
.flag("+fsanitize=address"));
225-
Multilibs.push_back(Multilib("relative-vtables+asan+noexcept", {}, {}, 7)
236+
Multilibs.push_back(Multilib("relative-vtables+asan+noexcept", {}, {}, 9)
226237
.flag("+fexperimental-relative-c++-abi-vtables")
227238
.flag("+fsanitize=address")
228239
.flag("-fexceptions")
229240
.flag("+fno-exceptions"));
241+
Multilibs.push_back(Multilib("relative-vtables+hwasan", {}, {}, 10)
242+
.flag("+fexperimental-relative-c++-abi-vtables")
243+
.flag("+fsanitize=hwaddress"));
244+
Multilibs.push_back(Multilib("relative-vtables+hwasan+noexcept", {}, {}, 11)
245+
.flag("+fexperimental-relative-c++-abi-vtables")
246+
.flag("+fsanitize=hwaddress")
247+
.flag("-fexceptions")
248+
.flag("+fno-exceptions"));
249+
230250
Multilibs.FilterOut([&](const Multilib &M) {
231251
std::vector<std::string> RD = FilePaths(M);
232252
return std::all_of(RD.begin(), RD.end(), [&](std::string P) {
@@ -239,6 +259,8 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple,
239259
Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, true),
240260
"fexceptions", Flags);
241261
addMultilibFlag(getSanitizerArgs().needsAsanRt(), "fsanitize=address", Flags);
262+
addMultilibFlag(getSanitizerArgs().needsHwasanRt(), "fsanitize=hwaddress",
263+
Flags);
242264

243265
addMultilibFlag(
244266
Args.hasFlag(options::OPT_fexperimental_relative_cxx_abi_vtables,
@@ -368,6 +390,7 @@ void Fuchsia::AddCXXStdlibLibArgs(const ArgList &Args,
368390
SanitizerMask Fuchsia::getSupportedSanitizers() const {
369391
SanitizerMask Res = ToolChain::getSupportedSanitizers();
370392
Res |= SanitizerKind::Address;
393+
Res |= SanitizerKind::HWAddress;
371394
Res |= SanitizerKind::PointerCompare;
372395
Res |= SanitizerKind::PointerSubtract;
373396
Res |= SanitizerKind::Fuzzer;

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/hwasan+noexcept/libc++.so

Whitespace-only changes.

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/hwasan/libc++.so

Whitespace-only changes.

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables+hwasan+noexcept/libc++.so

Whitespace-only changes.

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables+hwasan/libc++.so

Whitespace-only changes.

clang/test/Driver/fuchsia.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,26 @@
121121
// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
122122
// RUN: -fuse-ld=lld 2>&1\
123123
// RUN: | FileCheck %s -check-prefixes=CHECK-MULTILIB-X86
124+
// RUN: %clangxx %s -### --target=x86_64-fuchsia -fsanitize=hwaddress \
125+
// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
126+
// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
127+
// RUN: -fuse-ld=lld 2>&1\
128+
// RUN: | FileCheck %s -check-prefixes=CHECK-MULTILIB-X86,CHECK-MULTILIB-HWASAN-X86
129+
// RUN: %clangxx %s -### --target=x86_64-fuchsia -fsanitize=hwaddress -fno-exceptions \
130+
// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
131+
// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
132+
// RUN: -fuse-ld=lld 2>&1\
133+
// RUN: | FileCheck %s -check-prefixes=CHECK-MULTILIB-X86,CHECK-MULTILIB-HWASAN-NOEXCEPT-X86
134+
// RUN: %clangxx %s -### --target=x86_64-fuchsia -fexperimental-relative-c++-abi-vtables -fsanitize=hwaddress \
135+
// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
136+
// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
137+
// RUN: -fuse-ld=lld 2>&1\
138+
// RUN: | FileCheck %s -check-prefixes=CHECK-MULTILIB-X86,CHECK-MULTILIB-RELATIVE-VTABLES-HWASAN-X86
139+
// RUN: %clangxx %s -### --target=x86_64-fuchsia -fexperimental-relative-c++-abi-vtables -fno-exceptions -fsanitize=hwaddress \
140+
// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
141+
// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
142+
// RUN: -fuse-ld=lld 2>&1\
143+
// RUN: | FileCheck %s -check-prefixes=CHECK-MULTILIB-X86,CHECK-MULTILIB-RELATIVE-VTABLES-HWASAN-NOEXCEPT-X86
124144
// CHECK-MULTILIB-X86: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
125145
// CHECK-MULTILIB-ASAN-X86: "-L{{.*}}{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}c++{{/|\\\\}}asan"
126146
// CHECK-MULTILIB-NOEXCEPT-X86: "-L{{.*}}{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}c++{{/|\\\\}}noexcept"
@@ -129,4 +149,8 @@
129149
// CHECK-MULTILIB-RELATIVE-VTABLES-NOEXCEPT-X86: "-L{{.*}}{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}c++{{/|\\\\}}relative-vtables+noexcept"
130150
// CHECK-MULTILIB-RELATIVE-VTABLES-ASAN-X86: "-L{{.*}}{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}c++{{/|\\\\}}relative-vtables+asan"
131151
// CHECK-MULTILIB-RELATIVE-VTABLES-ASAN-NOEXCEPT-X86: "-L{{.*}}{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}c++{{/|\\\\}}relative-vtables+asan+noexcept"
152+
// CHECK-MULTILIB-HWASAN-X86: "-L{{.*}}{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}c++{{/|\\\\}}hwasan"
153+
// CHECK-MULTILIB-HWASAN-NOEXCEPT-X86: "-L{{.*}}{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}c++{{/|\\\\}}hwasan+noexcept"
154+
// CHECK-MULTILIB-RELATIVE-VTABLES-HWASAN-X86: "-L{{.*}}{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}c++{{/|\\\\}}relative-vtables+hwasan"
155+
// CHECK-MULTILIB-RELATIVE-VTABLES-HWASAN-NOEXCEPT-X86: "-L{{.*}}{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}c++{{/|\\\\}}relative-vtables+hwasan+noexcept"
132156
// CHECK-MULTILIB-X86: "-L{{.*}}{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}x86_64-fuchsia{{/|\\\\}}c++"

0 commit comments

Comments
 (0)