[llvm] r317009 - [asan] Upgrade private linkage globals to internal linkage on COFF
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 31 09:16:08 PDT 2017
Author: rnk
Date: Tue Oct 31 09:16:08 2017
New Revision: 317009
URL: http://llvm.org/viewvc/llvm-project?rev=317009&view=rev
Log:
[asan] Upgrade private linkage globals to internal linkage on COFF
COFF comdats require symbol table entries, which means the comdat leader
cannot have private linkage.
Modified:
llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
llvm/trunk/test/Instrumentation/AddressSanitizer/global_metadata_windows.ll
Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=317009&r1=317008&r2=317009&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Tue Oct 31 09:16:08 2017
@@ -1764,9 +1764,14 @@ void AddressSanitizerModule::SetComdatFo
C = M.getOrInsertComdat(G->getName());
}
- // Make this IMAGE_COMDAT_SELECT_NODUPLICATES on COFF.
- if (TargetTriple.isOSBinFormatCOFF())
+ // Make this IMAGE_COMDAT_SELECT_NODUPLICATES on COFF. Also upgrade private
+ // linkage to internal linkage so that a symbol table entry is emitted. This
+ // is necessary in order to create the comdat group.
+ if (TargetTriple.isOSBinFormatCOFF()) {
C->setSelectionKind(Comdat::NoDuplicates);
+ if (G->hasPrivateLinkage())
+ G->setLinkage(GlobalValue::InternalLinkage);
+ }
G->setComdat(C);
}
Modified: llvm/trunk/test/Instrumentation/AddressSanitizer/global_metadata_windows.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/global_metadata_windows.ll?rev=317009&r1=317008&r2=317009&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/AddressSanitizer/global_metadata_windows.ll (original)
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/global_metadata_windows.ll Tue Oct 31 09:16:08 2017
@@ -12,16 +12,25 @@ target triple = "x86_64-pc-windows-msvc1
$mystr = comdat any
; CHECK: $dead_global = comdat noduplicates
+; CHECK: $private_str = comdat noduplicates
+
; CHECK: @dead_global = local_unnamed_addr global { i32, [60 x i8] } { i32 42, [60 x i8] zeroinitializer }, comdat, align 32
+; CHECK: @private_str = internal unnamed_addr constant { [8 x i8], [56 x i8] } { [8 x i8] c"private\00", [56 x i8] zeroinitializer }, comdat, align 32
+
; CHECK: @__asan_global_dead_global = private global { {{.*}} }, section ".ASAN$GL", comdat($dead_global), align 64
+; CHECK: @__asan_global_private_str = private global { {{.*}} }, section ".ASAN$GL", comdat($private_str), align 64
@dead_global = local_unnamed_addr global i32 42, align 4
@mystr = linkonce_odr unnamed_addr constant [5 x i8] c"main\00", comdat, align 1
+; Private globals will get upgraded to internal linkage.
+ at private_str = private unnamed_addr constant [8 x i8] c"private\00", align 1
+
; Function Attrs: nounwind uwtable
define i32 @main() local_unnamed_addr #0 {
entry:
%call = tail call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @mystr, i64 0, i64 0))
+ %call2 = tail call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @private_str, i64 0, i64 0))
ret i32 0
}
More information about the llvm-commits
mailing list