[llvm] 8c469d1 - [SanitizerBinaryMetadata] Make constructors/destructors hidden
Marco Elver via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 8 15:47:06 PST 2023
Author: Marco Elver
Date: 2023-02-09T00:46:28+01:00
New Revision: 8c469d1693895e2cf7bf8b65b31184e9e4716c8f
URL: https://github.com/llvm/llvm-project/commit/8c469d1693895e2cf7bf8b65b31184e9e4716c8f
DIFF: https://github.com/llvm/llvm-project/commit/8c469d1693895e2cf7bf8b65b31184e9e4716c8f.diff
LOG: [SanitizerBinaryMetadata] Make constructors/destructors hidden
By switching them to external with default visibility, DSOs may not call
their own constructor/destructor. This is incorrect, because they pass
different parameters.
Fix it by marking the ctors/dtors as external linkage but with hidden
visibility.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D143611
Added:
Modified:
llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
llvm/test/Instrumentation/SanitizerBinaryMetadata/ctor.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
index 64ae7272cc2d8..876d7340f1f3c 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
@@ -216,8 +216,8 @@ bool SanitizerBinaryMetadata::run() {
(MI->FunctionPrefix + "_del").str(), InitTypes, InitArgs,
/*VersionCheckName=*/StringRef(), /*Weak=*/ClWeakCallbacks)
.first;
- Constant *CtorData = nullptr;
- Constant *DtorData = nullptr;
+ Constant *CtorComdatKey = nullptr;
+ Constant *DtorComdatKey = nullptr;
if (TargetTriple.supportsCOMDAT()) {
// Use COMDAT to deduplicate constructor/destructor function. The COMDAT
// key needs to be a non-local linkage.
@@ -225,11 +225,14 @@ bool SanitizerBinaryMetadata::run() {
Dtor->setComdat(Mod.getOrInsertComdat(Dtor->getName()));
Ctor->setLinkage(GlobalValue::ExternalLinkage);
Dtor->setLinkage(GlobalValue::ExternalLinkage);
- CtorData = Ctor;
- DtorData = Dtor;
+ // DSOs should _not_ call another constructor/destructor!
+ Ctor->setVisibility(GlobalValue::HiddenVisibility);
+ Dtor->setVisibility(GlobalValue::HiddenVisibility);
+ CtorComdatKey = Ctor;
+ DtorComdatKey = Dtor;
}
- appendToGlobalCtors(Mod, Ctor, kCtorDtorPriority, CtorData);
- appendToGlobalDtors(Mod, Dtor, kCtorDtorPriority, DtorData);
+ appendToGlobalCtors(Mod, Ctor, kCtorDtorPriority, CtorComdatKey);
+ appendToGlobalDtors(Mod, Dtor, kCtorDtorPriority, DtorComdatKey);
}
return true;
diff --git a/llvm/test/Instrumentation/SanitizerBinaryMetadata/ctor.ll b/llvm/test/Instrumentation/SanitizerBinaryMetadata/ctor.ll
index 9e26c7525c5a6..55f92ea3026ec 100644
--- a/llvm/test/Instrumentation/SanitizerBinaryMetadata/ctor.ll
+++ b/llvm/test/Instrumentation/SanitizerBinaryMetadata/ctor.ll
@@ -9,8 +9,8 @@
; CHECK: @llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_atomics.module_ctor, ptr @__sanitizer_metadata_atomics.module_ctor }, { i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_covered.module_ctor, ptr @__sanitizer_metadata_covered.module_ctor }]
; CHECK: @llvm.global_dtors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_atomics.module_dtor, ptr @__sanitizer_metadata_atomics.module_dtor }, { i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_covered.module_dtor, ptr @__sanitizer_metadata_covered.module_dtor }]
-; CHECK: define dso_local void @__sanitizer_metadata_covered.module_ctor() #1 comdat {
-; CHECK: define dso_local void @__sanitizer_metadata_covered.module_dtor() #1 comdat {
+; CHECK: define hidden void @__sanitizer_metadata_covered.module_ctor() #1 comdat {
+; CHECK: define hidden void @__sanitizer_metadata_covered.module_dtor() #1 comdat {
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
More information about the llvm-commits
mailing list