[PATCH] D143530: [SanitizerBinaryMetadata] Make module_[cd]tor external
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 7 15:37:58 PST 2023
MaskRay created this revision.
MaskRay added reviewers: dvyukov, melver.
Herald added subscribers: Enna1, hiraditya.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
If a COMDAT key has a local linkage, it behaves as `comdat nodeduplicate` and
llvm/lib/Linker/LinkModules.cpp does not deduplicate its members.
This is not intended. Switch to an external linkage to allow deduplication.
See also https://groups.google.com/g/generic-abi/c/2X6mR-s2zoc
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D143530
Files:
llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
llvm/test/Instrumentation/SanitizerBinaryMetadata/ctor.ll
Index: llvm/test/Instrumentation/SanitizerBinaryMetadata/ctor.ll
===================================================================
--- /dev/null
+++ llvm/test/Instrumentation/SanitizerBinaryMetadata/ctor.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -passes='module(sanmd-module)' -sanitizer-metadata-atomics -S | FileCheck %s
+
+; CHECK: $__sanitizer_metadata_atomics.module_ctor = comdat any
+; CHECK: $__sanitizer_metadata_atomics.module_dtor = comdat any
+; CHECK: $__sanitizer_metadata_covered.module_ctor = comdat any
+; CHECK: $__sanitizer_metadata_covered.module_dtor = comdat any
+
+; CHECK: @llvm.used = appending global [4 x ptr] [ptr @__sanitizer_metadata_atomics.module_ctor, ptr @__sanitizer_metadata_atomics.module_dtor, ptr @__sanitizer_metadata_covered.module_ctor, ptr @__sanitizer_metadata_covered.module_dtor], section "llvm.metadata"
+; 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 {
+
+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"
+
+define i8 @foo(ptr %a) nounwind uwtable {
+entry:
+ %0 = load atomic i8, ptr %a unordered, align 1
+ ret i8 %0
+}
Index: llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
+++ llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
@@ -218,6 +218,8 @@
// Use COMDAT to deduplicate constructor/destructor function.
Ctor->setComdat(Mod.getOrInsertComdat(Ctor->getName()));
Dtor->setComdat(Mod.getOrInsertComdat(Dtor->getName()));
+ Ctor->setLinkage(GlobalValue::ExternalLinkage);
+ Dtor->setLinkage(GlobalValue::ExternalLinkage);
CtorData = Ctor;
DtorData = Dtor;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143530.495659.patch
Type: text/x-patch
Size: 2580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230207/dd50d007/attachment.bin>
More information about the llvm-commits
mailing list