[llvm] r244748 - [GlobalMerge] Only emit aliases for internal linkage variables for non-Mach-O

John Brawn via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 06:36:48 PDT 2015


Author: john.brawn
Date: Wed Aug 12 08:36:48 2015
New Revision: 244748

URL: http://llvm.org/viewvc/llvm-project?rev=244748&view=rev
Log:
[GlobalMerge] Only emit aliases for internal linkage variables for non-Mach-O

On Mach-O emitting aliases for the variables that make up a MergedGlobals
variable can cause problems when linking with dead stripping enabled so don't
do that, except for external variables where we must emit an alias.

Modified:
    llvm/trunk/lib/CodeGen/GlobalMerge.cpp
    llvm/trunk/test/CodeGen/AArch64/global-merge-1.ll
    llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll

Modified: llvm/trunk/lib/CodeGen/GlobalMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalMerge.cpp?rev=244748&r1=244747&r2=244748&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalMerge.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalMerge.cpp Wed Aug 12 08:36:48 2015
@@ -459,9 +459,16 @@ bool GlobalMerge::doMerge(SmallVectorImp
       Globals[k]->replaceAllUsesWith(GEP);
       Globals[k]->eraseFromParent();
 
-      // Generate a new alias...
-      auto *PTy = cast<PointerType>(GEP->getType());
-      GlobalAlias::create(PTy, Linkage, Name, GEP, &M);
+      // When the linkage is not internal we must emit an alias for the original
+      // variable name as it may be accessed from another object. On non-Mach-O
+      // we can also emit an alias for internal linkage as it's safe to do so.
+      // It's not safe on Mach-O as the alias (and thus the portion of the
+      // MergedGlobals variable) may be dead stripped at link time.
+      if (Linkage != GlobalValue::InternalLinkage ||
+          !TM->getTargetTriple().isOSBinFormatMachO()) {
+        auto *PTy = cast<PointerType>(GEP->getType());
+        GlobalAlias::create(PTy, Linkage, Name, GEP, &M);
+      }
 
       NumMerged++;
     }

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=244748&r1=244747&r2=244748&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/global-merge-1.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/global-merge-1.ll Wed Aug 12 08:36:48 2015
@@ -23,5 +23,9 @@ define void @f1(i32 %a1, i32 %a2) {
 ;CHECK:	.type	.L_MergedGlobals, at object  // @_MergedGlobals
 ;CHECK:	.local	.L_MergedGlobals
 ;CHECK:	.comm	.L_MergedGlobals,8,8
+;CHECK: m = .L_MergedGlobals
+;CHECK: n = .L_MergedGlobals+4
 
 ;CHECK-APPLE-IOS: .zerofill __DATA,__bss,l__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-3.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll?rev=244748&r1=244747&r2=244748&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/global-merge-3.ll Wed Aug 12 08:36:48 2015
@@ -36,11 +36,13 @@ define void @f1(i32 %a1, i32 %a2, i32 %a
 
 ;CHECK-APPLE-IOS: .zerofill __DATA,__bss,l__MergedGlobals.1,4000,4
 
+;CHECK: z = .L_MergedGlobals
 ;CHECK:	.globl	x
 ;CHECK: x = .L_MergedGlobals+4
 ;CHECK:	.globl	y
 ;CHECK: y = .L_MergedGlobals.1
 
+;CHECK-APPLE-IOS-NOT: _z = l__MergedGlobals
 ;CHECK-APPLE-IOS:.globl	_x
 ;CHECK-APPLE-IOS: _x = l__MergedGlobals+4
 ;CHECK-APPLE-IOS:.globl	_y




More information about the llvm-commits mailing list