Skip to content

Commit e87c32e

Browse files
committed
[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
1 parent a3e9b32 commit e87c32e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,9 +1662,11 @@ defm sanitize_address_poison_custom_array_cookie : BoolOption<"f", "sanitize-add
16621662
PosFlag<SetTrue, [], "Enable">, NegFlag<SetFalse, [], "Disable">,
16631663
BothFlags<[], " poisoning array cookies when using custom operator new[] in AddressSanitizer">>,
16641664
Group<f_clang_Group>;
1665-
def fsanitize_address_globals_dead_stripping : Flag<["-"], "fsanitize-address-globals-dead-stripping">,
1666-
Group<f_clang_Group>, HelpText<"Enable linker dead stripping of globals in AddressSanitizer">,
1667-
MarshallingInfoFlag<CodeGenOpts<"SanitizeAddressGlobalsDeadStripping">, "false">;
1665+
defm sanitize_address_globals_dead_stripping : BoolOption<"f", "sanitize-address-globals-dead-stripping",
1666+
CodeGenOpts<"SanitizeAddressGlobalsDeadStripping">, DefaultFalse,
1667+
PosFlag<SetTrue, [], "Enable linker dead stripping of globals in AddressSanitizer">,
1668+
NegFlag<SetFalse, [], "Disable linker dead stripping of globals in AddressSanitizer">>,
1669+
Group<f_clang_Group>;
16681670
defm sanitize_address_use_odr_indicator : BoolOption<"f", "sanitize-address-use-odr-indicator",
16691671
CodeGenOpts<"SanitizeAddressUseOdrIndicator">, DefaultFalse,
16701672
PosFlag<SetTrue, [], "Enable ODR indicator globals to avoid false ODR violation"

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,10 +848,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
848848
// As a workaround for a bug in gold 2.26 and earlier, dead stripping of
849849
// globals in ASan is disabled by default on ELF targets.
850850
// See https://sourceware.org/bugzilla/show_bug.cgi?id=19002
851-
AsanGlobalsDeadStripping =
851+
AsanGlobalsDeadStripping = Args.hasFlag(
852+
options::OPT_fsanitize_address_globals_dead_stripping,
853+
options::OPT_fno_sanitize_address_globals_dead_stripping,
852854
!TC.getTriple().isOSBinFormatELF() || TC.getTriple().isOSFuchsia() ||
853-
TC.getTriple().isPS4() ||
854-
Args.hasArg(options::OPT_fsanitize_address_globals_dead_stripping);
855+
TC.getTriple().isPS4());
855856

856857
AsanUseOdrIndicator =
857858
Args.hasFlag(options::OPT_fsanitize_address_use_odr_indicator,

clang/test/Driver/fsanitize.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242

243243
// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-globals-dead-stripping %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
244244
// RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ASAN-GLOBALS
245+
// 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
245246
// 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
246247
// RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
247248
// RUN: %clang -target x86_64-scei-ps4 -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS

0 commit comments

Comments
 (0)