[clang] e87c32e - [Driver] Add -fno-sanitize-address-globals-dead-stripping
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 23 11:51:40 PST 2022
Author: Fangrui Song
Date: 2022-02-23T11:51:30-08:00
New Revision: e87c32e390bb812d9390d3df39357409d073ac3f
URL: https://github.com/llvm/llvm-project/commit/e87c32e390bb812d9390d3df39357409d073ac3f
DIFF: https://github.com/llvm/llvm-project/commit/e87c32e390bb812d9390d3df39357409d073ac3f.diff
LOG: [Driver] Add -fno-sanitize-address-globals-dead-stripping
It's customary for these options to have the -fno- form which is sometimes
handy to work around issues. Using the supported driver option is preferred over
the internal cl::opt option `-mllvm -asan-globals-live-support=0`
Reviewed By: kstoimenov, vitalybuka
Differential Revision: https://reviews.llvm.org/D120391
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Driver/SanitizerArgs.cpp
clang/test/Driver/fsanitize.c
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index c377329e8f6f4..fcee066905703 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1662,9 +1662,11 @@ defm sanitize_address_poison_custom_array_cookie : BoolOption<"f", "sanitize-add
PosFlag<SetTrue, [], "Enable">, NegFlag<SetFalse, [], "Disable">,
BothFlags<[], " poisoning array cookies when using custom operator new[] in AddressSanitizer">>,
Group<f_clang_Group>;
-def fsanitize_address_globals_dead_stripping : Flag<["-"], "fsanitize-address-globals-dead-stripping">,
- Group<f_clang_Group>, HelpText<"Enable linker dead stripping of globals in AddressSanitizer">,
- MarshallingInfoFlag<CodeGenOpts<"SanitizeAddressGlobalsDeadStripping">, "false">;
+defm sanitize_address_globals_dead_stripping : BoolOption<"f", "sanitize-address-globals-dead-stripping",
+ CodeGenOpts<"SanitizeAddressGlobalsDeadStripping">, DefaultFalse,
+ PosFlag<SetTrue, [], "Enable linker dead stripping of globals in AddressSanitizer">,
+ NegFlag<SetFalse, [], "Disable linker dead stripping of globals in AddressSanitizer">>,
+ Group<f_clang_Group>;
defm sanitize_address_use_odr_indicator : BoolOption<"f", "sanitize-address-use-odr-indicator",
CodeGenOpts<"SanitizeAddressUseOdrIndicator">, DefaultFalse,
PosFlag<SetTrue, [], "Enable ODR indicator globals to avoid false ODR violation"
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index 403fac76f0602..440f29142ab29 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -848,10 +848,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
// As a workaround for a bug in gold 2.26 and earlier, dead stripping of
// globals in ASan is disabled by default on ELF targets.
// See https://sourceware.org/bugzilla/show_bug.cgi?id=19002
- AsanGlobalsDeadStripping =
+ AsanGlobalsDeadStripping = Args.hasFlag(
+ options::OPT_fsanitize_address_globals_dead_stripping,
+ options::OPT_fno_sanitize_address_globals_dead_stripping,
!TC.getTriple().isOSBinFormatELF() || TC.getTriple().isOSFuchsia() ||
- TC.getTriple().isPS4() ||
- Args.hasArg(options::OPT_fsanitize_address_globals_dead_stripping);
+ TC.getTriple().isPS4());
AsanUseOdrIndicator =
Args.hasFlag(options::OPT_fsanitize_address_use_odr_indicator,
diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 7bcda5c33dc9e..c61726aaa3115 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -242,6 +242,7 @@
// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-globals-dead-stripping %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
// RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ASAN-GLOBALS
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-globals-dead-stripping -fno-sanitize-address-globals-dead-stripping %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ASAN-GLOBALS
// RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -fsanitize-address-globals-dead-stripping -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
// RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
// RUN: %clang -target x86_64-scei-ps4 -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
More information about the cfe-commits
mailing list