[llvm] r286607 - Revert "Use private linkage for MergedGlobals variables" on Darwin.
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 11 09:50:10 PST 2016
Author: adrian
Date: Fri Nov 11 11:50:09 2016
New Revision: 286607
URL: http://llvm.org/viewvc/llvm-project?rev=286607&view=rev
Log:
Revert "Use private linkage for MergedGlobals variables" on Darwin.
This is a partial revert of r244615 (http://reviews.llvm.org/D11942),
which caused a major regression in debug info quality.
Turning the artificial __MergedGlobal symbols into private symbols
(l__MergedGlobal) means that the linker will not include them in the
symbol table of the final executable. Without a symbol table entry
dsymutil is not be able to process the debug info for any of the
merged globals and thus drops the debug info for all of them.
This patch is enabling the old behavior for all MachO targets while
leaving all other targets unaffected.
rdar://problem/29160481
https://reviews.llvm.org/D26531
Modified:
llvm/trunk/lib/CodeGen/GlobalMerge.cpp
llvm/trunk/test/CodeGen/AArch64/global-merge-1.ll
llvm/trunk/test/CodeGen/AArch64/global-merge-2.ll
llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll
llvm/trunk/test/CodeGen/AArch64/global-merge-group-by-use.ll
llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use-minsize.ll
llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use.ll
llvm/trunk/test/CodeGen/ARM/2011-06-29-MergeGlobalsAlign.ll
llvm/trunk/test/CodeGen/ARM/global-merge-1.ll
Modified: llvm/trunk/lib/CodeGen/GlobalMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalMerge.cpp?rev=286607&r1=286606&r2=286607&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalMerge.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalMerge.cpp Fri Nov 11 11:50:09 2016
@@ -432,6 +432,8 @@ bool GlobalMerge::doMerge(const SmallVec
std::vector<Type*> Tys;
std::vector<Constant*> Inits;
+ bool HasExternal = false;
+ GlobalVariable *TheFirstExternal = nullptr;
for (j = i; j != -1; j = GlobalSet.find_next(j)) {
Type *Ty = Globals[j]->getValueType();
MergedSize += DL.getTypeAllocSize(Ty);
@@ -440,14 +442,34 @@ bool GlobalMerge::doMerge(const SmallVec
}
Tys.push_back(Ty);
Inits.push_back(Globals[j]->getInitializer());
+
+ if (Globals[j]->hasExternalLinkage() && !HasExternal) {
+ HasExternal = true;
+ TheFirstExternal = Globals[j];
+ }
}
+ // If merged variables doesn't have external linkage, we needn't to expose
+ // the symbol after merging.
+ GlobalValue::LinkageTypes Linkage = HasExternal
+ ? GlobalValue::ExternalLinkage
+ : GlobalValue::InternalLinkage;
StructType *MergedTy = StructType::get(M.getContext(), Tys);
Constant *MergedInit = ConstantStruct::get(MergedTy, Inits);
- GlobalVariable *MergedGV = new GlobalVariable(
- M, MergedTy, isConst, GlobalValue::PrivateLinkage, MergedInit,
- "_MergedGlobals", nullptr, GlobalVariable::NotThreadLocal, AddrSpace);
+ // On Darwin external linkage needs to be preserved, otherwise dsymutil
+ // cannot preserve the debug info for the merged variables. If they have
+ // external linkage, use the symbol name of the first variable merged as the
+ // suffix of global symbol name. This avoids a link-time naming conflict
+ // for the _MergedGlobals symbols.
+ Twine MergedName =
+ (IsMachO && HasExternal)
+ ? "_MergedGlobals_" + TheFirstExternal->getName()
+ : "_MergedGlobals";
+ auto MergedLinkage = IsMachO ? Linkage : GlobalValue::PrivateLinkage;
+ auto *MergedGV = new GlobalVariable(
+ M, MergedTy, isConst, MergedLinkage, MergedInit, MergedName, nullptr,
+ GlobalVariable::NotThreadLocal, AddrSpace);
const StructLayout *MergedLayout = DL.getStructLayout(MergedTy);
Modified: llvm/trunk/test/CodeGen/AArch64/global-merge-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/global-merge-1.ll?rev=286607&r1=286606&r2=286607&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/global-merge-1.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/global-merge-1.ll Fri Nov 11 11:50:09 2016
@@ -12,9 +12,9 @@
define void @f1(i32 %a1, i32 %a2) {
;CHECK-APPLE-IOS-NOT: adrp
-;CHECK-APPLE-IOS: adrp x8, l__MergedGlobals at PAGE
+;CHECK-APPLE-IOS: adrp x8, __MergedGlobals at PAGE
;CHECK-APPLE-IOS-NOT: adrp
-;CHECK-APPLE-IOS: add x8, x8, l__MergedGlobals at PAGEOFF
+;CHECK-APPLE-IOS: add x8, x8, __MergedGlobals at PAGEOFF
store i32 %a1, i32* @m, align 4
store i32 %a2, i32* @n, align 4
ret void
@@ -26,6 +26,6 @@ define void @f1(i32 %a1, i32 %a2) {
;CHECK: m = .L_MergedGlobals
;CHECK: n = .L_MergedGlobals+4
-;CHECK-APPLE-IOS: .zerofill __DATA,__bss,l__MergedGlobals,8,3 ; @_MergedGlobals
+;CHECK-APPLE-IOS: .zerofill __DATA,__bss,__MergedGlobals,8,3 ; @_MergedGlobals
;CHECK-APPLE-IOS-NOT: _m = l__MergedGlobals
;CHECK-APPLE-IOS-NOT: _n = l__MergedGlobals+4
Modified: llvm/trunk/test/CodeGen/AArch64/global-merge-2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/global-merge-2.ll?rev=286607&r1=286606&r2=286607&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/global-merge-2.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/global-merge-2.ll Fri Nov 11 11:50:09 2016
@@ -9,8 +9,8 @@
define void @f1(i32 %a1, i32 %a2) {
;CHECK-APPLE-IOS-LABEL: _f1:
;CHECK-APPLE-IOS-NOT: adrp
-;CHECK-APPLE-IOS: adrp x8, l__MergedGlobals at PAGE
-;CHECK-APPLE-IOS: add x8, x8, l__MergedGlobals at PAGEOFF
+;CHECK-APPLE-IOS: adrp x8, __MergedGlobals_x at PAGE
+;CHECK-APPLE-IOS: add x8, x8, __MergedGlobals_x at PAGEOFF
;CHECK-APPLE-IOS-NOT: adrp
store i32 %a1, i32* @x, align 4
store i32 %a2, i32* @y, align 4
@@ -19,8 +19,8 @@ define void @f1(i32 %a1, i32 %a2) {
define void @g1(i32 %a1, i32 %a2) {
;CHECK-APPLE-IOS-LABEL: _g1:
-;CHECK-APPLE-IOS: adrp x8, l__MergedGlobals at PAGE
-;CHECK-APPLE-IOS: add x8, x8, l__MergedGlobals at PAGEOFF
+;CHECK-APPLE-IOS: adrp x8, __MergedGlobals_x at PAGE
+;CHECK-APPLE-IOS: add x8, x8, __MergedGlobals_x at PAGEOFF
;CHECK-APPLE-IOS-NOT: adrp
store i32 %a1, i32* @y, align 4
store i32 %a2, i32* @z, align 4
@@ -41,12 +41,12 @@ define void @g1(i32 %a1, i32 %a2) {
;CHECK: z = .L_MergedGlobals+8
;CHECK: .size z, 4
-;CHECK-APPLE-IOS: .zerofill __DATA,__bss,l__MergedGlobals,12,3
+;CHECK-APPLE-IOS: .zerofill __DATA,__common,__MergedGlobals_x,12,3
;CHECK-APPLE-IOS: .globl _x
-;CHECK-APPLE-IOS: = l__MergedGlobals
+;CHECK-APPLE-IOS: = __MergedGlobals_x
;CHECK-APPLE-IOS: .globl _y
-;CHECK-APPLE-IOS: _y = l__MergedGlobals+4
+;CHECK-APPLE-IOS: _y = __MergedGlobals_x+4
;CHECK-APPLE-IOS: .globl _z
-;CHECK-APPLE-IOS: _z = l__MergedGlobals+8
+;CHECK-APPLE-IOS: _z = __MergedGlobals_x+8
;CHECK-APPLE-IOS: .subsections_via_symbols
Modified: llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll?rev=286607&r1=286606&r2=286607&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll Fri Nov 11 11:50:09 2016
@@ -7,11 +7,11 @@
@z = internal global i32 1, align 4
define void @f1(i32 %a1, i32 %a2, i32 %a3) {
-;CHECK-APPLE-IOS: adrp x8, l__MergedGlobals at PAGE
+;CHECK-APPLE-IOS: adrp x8, __MergedGlobals_x at PAGE
;CHECK-APPLE-IOS-NOT: adrp
-;CHECK-APPLE-IOS: add x8, x8, l__MergedGlobals at PAGEOFF
-;CHECK-APPLE-IOS: adrp x9, l__MergedGlobals.1 at PAGE
-;CHECK-APPLE-IOS: add x9, x9, l__MergedGlobals.1 at PAGEOFF
+;CHECK-APPLE-IOS: add x8, x8, __MergedGlobals_x at PAGEOFF
+;CHECK-APPLE-IOS: adrp x9, __MergedGlobals_y at PAGE
+;CHECK-APPLE-IOS: add x9, x9, __MergedGlobals_y at PAGEOFF
%x3 = getelementptr inbounds [1000 x i32], [1000 x i32]* @x, i32 0, i64 3
%y3 = getelementptr inbounds [1000 x i32], [1000 x i32]* @y, i32 0, i64 3
store i32 %a1, i32* %x3, align 4
@@ -30,11 +30,11 @@ define void @f1(i32 %a1, i32 %a2, i32 %a
;CHECK: .comm .L_MergedGlobals.1,4000,16
;CHECK-APPLE-IOS: .p2align 4
-;CHECK-APPLE-IOS: l__MergedGlobals:
+;CHECK-APPLE-IOS: __MergedGlobals_x:
;CHECK-APPLE-IOS: .long 1
;CHECK-APPLE-IOS: .space 4000
-;CHECK-APPLE-IOS: .zerofill __DATA,__bss,l__MergedGlobals.1,4000,4
+;CHECK-APPLE-IOS: .zerofill __DATA,__common,__MergedGlobals_y,4000,4
;CHECK: z = .L_MergedGlobals
;CHECK: .globl x
@@ -44,8 +44,8 @@ define void @f1(i32 %a1, i32 %a2, i32 %a
;CHECK: y = .L_MergedGlobals.1
;CHECK: .size y, 4000
-;CHECK-APPLE-IOS-NOT: _z = l__MergedGlobals
+;CHECK-APPLE-IOS-NOT: _z = __MergedGlobals_x
;CHECK-APPLE-IOS:.globl _x
-;CHECK-APPLE-IOS: _x = l__MergedGlobals+4
+;CHECK-APPLE-IOS: _x = __MergedGlobals_x+4
;CHECK-APPLE-IOS:.globl _y
-;CHECK-APPLE-IOS: _y = l__MergedGlobals.1
+;CHECK-APPLE-IOS: _y = __MergedGlobals_y
Modified: llvm/trunk/test/CodeGen/AArch64/global-merge-group-by-use.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/global-merge-group-by-use.ll?rev=286607&r1=286606&r2=286607&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/global-merge-group-by-use.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/global-merge-group-by-use.ll Fri Nov 11 11:50:09 2016
@@ -13,7 +13,7 @@
; CHECK-LABEL: f1:
define void @f1(i32 %a1, i32 %a2) #0 {
-; CHECK-NEXT: adrp x8, [[SET1:l__MergedGlobals.[0-9]*]]@PAGE
+; CHECK-NEXT: adrp x8, [[SET1:__MergedGlobals.[0-9]*]]@PAGE
; CHECK-NEXT: add x8, x8, [[SET1]]@PAGEOFF
; CHECK-NEXT: stp w0, w1, [x8]
; CHECK-NEXT: ret
@@ -28,7 +28,7 @@ define void @f1(i32 %a1, i32 %a2) #0 {
; CHECK-LABEL: f2:
define void @f2(i32 %a1, i32 %a2, i32 %a3) #0 {
-; CHECK-NEXT: adrp x8, [[SET2:l__MergedGlobals.[0-9]*]]@PAGE
+; CHECK-NEXT: adrp x8, [[SET2:__MergedGlobals.[0-9]*]]@PAGE
; CHECK-NEXT: add x8, x8, [[SET2]]@PAGEOFF
; CHECK-NEXT: stp w0, w1, [x8]
; CHECK-NEXT: str w2, [x8, #8]
@@ -49,7 +49,7 @@ define void @f2(i32 %a1, i32 %a2, i32 %a
; CHECK-LABEL: f3:
define void @f3(i32 %a1, i32 %a2) #0 {
; CHECK-NEXT: adrp x8, _m3 at PAGE
-; CHECK-NEXT: adrp x9, [[SET3:l__MergedGlobals[0-9]*]]@PAGE
+; CHECK-NEXT: adrp x9, [[SET3:__MergedGlobals[0-9]*]]@PAGE
; CHECK-NEXT: str w0, [x8, _m3 at PAGEOFF]
; CHECK-NEXT: str w1, [x9, [[SET3]]@PAGEOFF]
; CHECK-NEXT: ret
Modified: llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use-minsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use-minsize.ll?rev=286607&r1=286606&r2=286607&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use-minsize.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use-minsize.ll Fri Nov 11 11:50:09 2016
@@ -11,7 +11,7 @@
; CHECK-LABEL: f1:
define void @f1(i32 %a1, i32 %a2) minsize nounwind {
-; CHECK-NEXT: adrp x8, [[SET:l__MergedGlobals]]@PAGE
+; CHECK-NEXT: adrp x8, [[SET:__MergedGlobals]]@PAGE
; CHECK-NEXT: add x8, x8, [[SET]]@PAGEOFF
; CHECK-NEXT: stp w0, w1, [x8]
; CHECK-NEXT: ret
Modified: llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use.ll?rev=286607&r1=286606&r2=286607&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/global-merge-ignore-single-use.ll Fri Nov 11 11:50:09 2016
@@ -11,7 +11,7 @@
; CHECK-LABEL: f1:
define void @f1(i32 %a1, i32 %a2) #0 {
-; CHECK-NEXT: adrp x8, [[SET:l__MergedGlobals]]@PAGE
+; CHECK-NEXT: adrp x8, [[SET:__MergedGlobals]]@PAGE
; CHECK-NEXT: add x8, x8, [[SET]]@PAGEOFF
; CHECK-NEXT: stp w0, w1, [x8]
; CHECK-NEXT: ret
Modified: llvm/trunk/test/CodeGen/ARM/2011-06-29-MergeGlobalsAlign.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/2011-06-29-MergeGlobalsAlign.ll?rev=286607&r1=286606&r2=286607&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/2011-06-29-MergeGlobalsAlign.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/2011-06-29-MergeGlobalsAlign.ll Fri Nov 11 11:50:09 2016
@@ -1,5 +1,5 @@
; RUN: llc < %s -mtriple=thumbv7-apple-darwin10 -arm-global-merge -global-merge-group-by-use=false | FileCheck %s
-; CHECK: .zerofill __DATA,__bss,l__MergedGlobals,16,2
+; CHECK: .zerofill __DATA,__bss,__MergedGlobals,16,2
@prev = external global [0 x i16]
@max_lazy_match = internal unnamed_addr global i32 0, align 4
Modified: llvm/trunk/test/CodeGen/ARM/global-merge-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/global-merge-1.ll?rev=286607&r1=286606&r2=286607&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/global-merge-1.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/global-merge-1.ll Fri Nov 11 11:50:09 2016
@@ -11,16 +11,16 @@
; MERGE-NOT: .zerofill __DATA,__bss,_bar,20,2
; MERGE-NOT: .zerofill __DATA,__bss,_baz,20,2
; MERGE-NOT: .zerofill __DATA,__bss,_foo,20,2
-; MERGE: .zerofill __DATA,__bss,l__MergedGlobals,60,4
+; MERGE: .zerofill __DATA,__bss,__MergedGlobals,60,4
; MERGE-NOT: .zerofill __DATA,__bss,_bar,20,2
; MERGE-NOT: .zerofill __DATA,__bss,_baz,20,2
; MERGE-NOT: .zerofill __DATA,__bss,_foo,20,2
-; NO-MERGE-NOT: .zerofill __DATA,__bss,l__MergedGlobals,60,4
+; NO-MERGE-NOT: .zerofill __DATA,__bss,__MergedGlobals,60,4
; NO-MERGE: .zerofill __DATA,__bss,_bar,20,2
; NO-MERGE: .zerofill __DATA,__bss,_baz,20,2
; NO-MERGE: .zerofill __DATA,__bss,_foo,20,2
-; NO-MERGE-NOT: .zerofill __DATA,__bss,l__MergedGlobals,60,4
+; NO-MERGE-NOT: .zerofill __DATA,__bss,__MergedGlobals,60,4
target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32-S32"
target triple = "thumbv7-apple-ios3.0.0"
More information about the llvm-commits
mailing list