MaskRay created this revision. MaskRay added reviewers: Sanitizers, aeubanks, rnk, eugenis, phosek, probinson. Herald added a project: All. MaskRay requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
-fsanitize-address-globals-dead-stripping is the default for non-ELF platforms. For ELF, we disabled it to work around an ancient gold 2.26 bug. However, some platforms (Fuchsia and PS) default the option to true. This patch changes -fsanitize-address-globals-dead-stripping to true for all ELF platforms. Without specifying -fdata-sections (non-default for most ELF platforms), `asan_globals` can only be GCed if the monolithic .data/.bss section is GCed, which makes it less effective. However, I think this simplified rule is better than making the -fsanitize-address-globals-dead-stripping default dependent on another option. Close https://github.com/llvm/llvm-project/issues/63127 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D152604 Files: clang/lib/Driver/SanitizerArgs.cpp clang/test/Driver/fsanitize.c Index: clang/test/Driver/fsanitize.c =================================================================== --- clang/test/Driver/fsanitize.c +++ clang/test/Driver/fsanitize.c @@ -240,7 +240,7 @@ // CHECK-ASAN-WITHOUT-POISON-CUSTOM-ARRAY-NEW-COOKIE-NOT: -cc1{{.*}}address-poison-custom-array-cookie // 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 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-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 Index: clang/lib/Driver/SanitizerArgs.cpp =================================================================== --- clang/lib/Driver/SanitizerArgs.cpp +++ clang/lib/Driver/SanitizerArgs.cpp @@ -928,14 +928,9 @@ options::OPT_fno_sanitize_address_outline_instrumentation, AsanOutlineInstrumentation); - // As a workaround for a bug in gold 2.26 and earlier, dead stripping of - // globals in ASan is disabled by default on most ELF targets. - // See https://sourceware.org/bugzilla/show_bug.cgi?id=19002 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().isPS()); + options::OPT_fno_sanitize_address_globals_dead_stripping, true); // Enable ODR indicators which allow better handling of mixed instrumented // and uninstrumented globals. Disable them for Windows where weak odr
Index: clang/test/Driver/fsanitize.c =================================================================== --- clang/test/Driver/fsanitize.c +++ clang/test/Driver/fsanitize.c @@ -240,7 +240,7 @@ // CHECK-ASAN-WITHOUT-POISON-CUSTOM-ARRAY-NEW-COOKIE-NOT: -cc1{{.*}}address-poison-custom-array-cookie // 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 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-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 Index: clang/lib/Driver/SanitizerArgs.cpp =================================================================== --- clang/lib/Driver/SanitizerArgs.cpp +++ clang/lib/Driver/SanitizerArgs.cpp @@ -928,14 +928,9 @@ options::OPT_fno_sanitize_address_outline_instrumentation, AsanOutlineInstrumentation); - // As a workaround for a bug in gold 2.26 and earlier, dead stripping of - // globals in ASan is disabled by default on most ELF targets. - // See https://sourceware.org/bugzilla/show_bug.cgi?id=19002 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().isPS()); + options::OPT_fno_sanitize_address_globals_dead_stripping, true); // Enable ODR indicators which allow better handling of mixed instrumented // and uninstrumented globals. Disable them for Windows where weak odr
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits