-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ASan] Introduce a way set different ways of emitting module destruct…
…ors. Previously there was no way to control how module destructors were emitted by `ModuleAddressSanitizerPass`. However, we want language frontends (e.g. Clang) to be able to decide how to emit these destructors (if at all). This patch introduces the `AsanDtorKind` enum that represents the different ways destructors can be emitted. There are currently only two valid ways to emit destructors. * `Global` - Use `llvm.global_dtors`. This was the previous behavior and is the default. * `None` - Do not emit module destructors. The `ModuleAddressSanitizerPass` and the various wrappers around it have been updated to take the `AsanDtorKind` as an argument. The `-asan-destructor-kind=` command line argument has been introduced to make this easy to test from `opt`. If this argument is specified it overrides the value passed to the `ModuleAddressSanitizerPass` constructor. Note that `AsanDtorKind` is not `bool` because we will introduce a new way to emit destructors in a subsequent patch. Note that `AsanDtorKind` is given its own header file because if it is declared in `Transforms/Instrumentation/AddressSanitizer.h` it leads to compile error (Module is ambiguous) when trying to use it in `clang/Basic/CodeGenOptions.def`. rdar://71609176 Differential Revision: https://reviews.llvm.org/D96571
- Loading branch information
1 parent
a3ce7f5
commit 7d3ef10
Showing
4 changed files
with
109 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===--------- Definition of the AddressSanitizer options -------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// This file defines data types used to set Address Sanitizer options. | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZEROPTIONS_H | ||
#define LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZEROPTIONS_H | ||
|
||
namespace llvm { | ||
|
||
/// Types of ASan module destructors supported | ||
enum class AsanDtorKind { | ||
None, ///< Do not emit any destructors for ASan | ||
Global, ///< Append to llvm.global_dtors | ||
Invalid, ///< Not a valid destructor Kind. | ||
// TODO(dliew): Add more more kinds. | ||
}; | ||
} // namespace llvm | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
llvm/test/Instrumentation/AddressSanitizer/no_global_dtors.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
; Check Default behaviour still emits dtors | ||
; RUN: opt < %s -asan -asan-module -enable-new-pm=0 -S | \ | ||
; RUN: FileCheck -check-prefix=CHECK-DEFAULT %s | ||
; RUN: opt < %s -passes='asan-pipeline' -S | \ | ||
; RUN: FileCheck -check-prefix=CHECK-DEFAULT %s | ||
; CHECK-DEFAULT: llvm.global_dtor{{.+}}asan.module_dtor | ||
; CHECK-DEFAULT: define internal void @asan.module_dtor | ||
|
||
; Check with dtor emission disabled | ||
; RUN: opt < %s -asan -asan-module -enable-new-pm=0 \ | ||
; RUN: -asan-destructor-kind=none -S | \ | ||
; RUN: FileCheck %s | ||
; RUN: opt < %s -passes='asan-pipeline' \ | ||
; RUN: -asan-destructor-kind=none -S | \ | ||
; RUN: FileCheck %s | ||
; CHECK-NOT: llvm.global_dtor{{.+}}asan.module_dtor | ||
; CHECK-NOT: define internal void @asan.module_dtor | ||
|
||
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-apple-macosx11.0.0" | ||
|
||
@foo = dso_local global i32 0, align 4 |