[clang] 0477cac - [asan] Allow -fsanitize-address-globals-dead-stripping with -fno-data-sections for ELF
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 23 16:08:29 PST 2022
Author: Fangrui Song
Date: 2022-02-23T16:08:25-08:00
New Revision: 0477cac332d5abf7b2b51b470370afcbb1e8d513
URL: https://github.com/llvm/llvm-project/commit/0477cac332d5abf7b2b51b470370afcbb1e8d513
DIFF: https://github.com/llvm/llvm-project/commit/0477cac332d5abf7b2b51b470370afcbb1e8d513.diff
LOG: [asan] Allow -fsanitize-address-globals-dead-stripping with -fno-data-sections for ELF
-fdata-sections decides whether global variables go into different sections.
This is orthogonal to whether we place their metadata (`.data` or `asan_globals`) into different sections.
With -fno-data-sections, `-fsanitize-address-globals-dead-stripping` can still:
* deduplicate COMDAT `asan.module_ctor` and `asan.module_dtor`
* (with ld --gc-sections): for a data section (e.g. `.data`), if all global variables defined relative to it are unreferenced, discard them and associated `asan_globals` sections (rare but no need to exclude this case)
Similar to c7b90947bd0179d914fea56b52be545c8f60f20a for PE/COFF.
Reviewed By: #sanitizers, kstoimenov, vitalybuka
Differential Revision: https://reviews.llvm.org/D120394
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/asan-globals-gc.cpp
clang/test/CodeGen/asan-no-globals-no-comdat.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index f3026040ad216..ebfbe991881c6 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -281,7 +281,7 @@ static bool asanUseGlobalsGC(const Triple &T, const CodeGenOptions &CGOpts) {
case Triple::COFF:
return true;
case Triple::ELF:
- return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
+ return !CGOpts.DisableIntegratedAS;
case Triple::GOFF:
llvm::report_fatal_error("ASan not implemented for GOFF");
case Triple::XCOFF:
diff --git a/clang/test/CodeGen/asan-globals-gc.cpp b/clang/test/CodeGen/asan-globals-gc.cpp
index 95702516d8a16..f2adbfb6eb36f 100644
--- a/clang/test/CodeGen/asan-globals-gc.cpp
+++ b/clang/test/CodeGen/asan-globals-gc.cpp
@@ -1,6 +1,5 @@
-// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITH-GC
// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fdata-sections -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITH-GC
-// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fno-integrated-as -fdata-sections -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fno-integrated-as -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
// RUN: %clang_cc1 -fsanitize=address -fdata-sections -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
diff --git a/clang/test/CodeGen/asan-no-globals-no-comdat.cpp b/clang/test/CodeGen/asan-no-globals-no-comdat.cpp
index b7a6b16159a5f..9c7a0d2ff53da 100644
--- a/clang/test/CodeGen/asan-no-globals-no-comdat.cpp
+++ b/clang/test/CodeGen/asan-no-globals-no-comdat.cpp
@@ -1,9 +1,7 @@
// Test that on Linux asan constructor is placed in a comdat iff globals-gc is on.
// Even if there are no globals in the module.
-// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
-// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fdata-sections -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITH-GC
-// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fno-integrated-as -fdata-sections -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITH-GC
// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fno-integrated-as -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
// RUN: %clang_cc1 -fsanitize=address -fdata-sections -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
More information about the cfe-commits
mailing list