[llvm] c662795 - [AsmPrinter][ELF] Emit local alias for ExternalLinkage dso_local GlobalAlias

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 12 17:08:40 PST 2020


Author: Fangrui Song
Date: 2020-02-12T17:08:22-08:00
New Revision: c662795b078830aa4af32f031ecb09591eca0f73

URL: https://github.com/llvm/llvm-project/commit/c662795b078830aa4af32f031ecb09591eca0f73
DIFF: https://github.com/llvm/llvm-project/commit/c662795b078830aa4af32f031ecb09591eca0f73.diff

LOG: [AsmPrinter][ELF] Emit local alias for ExternalLinkage dso_local GlobalAlias

Added: 
    

Modified: 
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll
    llvm/test/CodeGen/X86/linux-preemption.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3881270cc5dc..ec0eb497bfa8 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -460,7 +460,7 @@ MCSymbol *AsmPrinter::getSymbolPreferLocal(const GlobalValue &GV) const {
   // assumed it.
   if (TM.getTargetTriple().isOSBinFormatELF() &&
       GlobalObject::isExternalLinkage(GV.getLinkage()) && GV.isDSOLocal() &&
-      !GV.isDeclaration() && isa<GlobalObject>(GV))
+      !GV.isDeclaration() && !isa<GlobalIFunc>(GV))
     return getSymbolWithGlobalValueBase(&GV, "$local");
   return TM.getSymbol(&GV);
 }
@@ -1383,6 +1383,9 @@ void AsmPrinter::emitGlobalIndirectSymbol(Module &M,
 
   // Emit the directives as assignments aka .set:
   OutStreamer->EmitAssignment(Name, Expr);
+  MCSymbol *LocalAlias = getSymbolPreferLocal(GIS);
+  if (LocalAlias != Name)
+    OutStreamer->EmitAssignment(LocalAlias, Expr);
 
   if (auto *GA = dyn_cast<GlobalAlias>(&GIS)) {
     // If the aliasee does not correspond to a symbol in the output, i.e. the

diff  --git a/llvm/test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll b/llvm/test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll
index 2ca003e052aa..89d249c09178 100644
--- a/llvm/test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll
+++ b/llvm/test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll
@@ -12,7 +12,7 @@ target triple = "i386-pc-linux-gnu"
 
 define i32 @foo() {
 ; CHECK-LABEL: foo:
-; CHECK: leal    __libc_resp at TLSLD
+; CHECK: leal    .L__libc_resp$local at TLSLDM
 entry:
 	%retval = alloca i32		; <i32*> [#uses=1]
 	%"alloca point" = bitcast i32 0 to i32		; <i32> [#uses=0]
@@ -27,7 +27,7 @@ return:		; preds = %entry
 
 define i32 @bar() {
 ; CHECK-LABEL: bar:
-; CHECK: leal    __libc_resp at TLSLD
+; CHECK: leal    .L__libc_resp$local at TLSLDM
 entry:
 	%retval = alloca i32		; <i32*> [#uses=1]
 	%"alloca point" = bitcast i32 0 to i32		; <i32> [#uses=0]

diff  --git a/llvm/test/CodeGen/X86/linux-preemption.ll b/llvm/test/CodeGen/X86/linux-preemption.ll
index 3bf97112a840..e876469f8fa6 100644
--- a/llvm/test/CodeGen/X86/linux-preemption.ll
+++ b/llvm/test/CodeGen/X86/linux-preemption.ll
@@ -108,9 +108,9 @@ define i32* @get_weak_default_alias() {
 define i32* @get_strong_local_alias() {
   ret i32* @strong_local_alias
 }
-; CHECK: leaq strong_local_alias(%rip), %rax
-; STATIC: movl $strong_local_alias, %eax
-; CHECK32: leal strong_local_alias at GOTOFF(%eax), %eax
+; CHECK: leaq .Lstrong_local_alias$local(%rip), %rax
+; STATIC: movl $.Lstrong_local_alias$local, %eax
+; CHECK32: leal .Lstrong_local_alias$local at GOTOFF(%eax), %eax
 
 @weak_local_alias = weak dso_local alias i32, i32* @aliasee
 define i32* @get_weak_local_alias() {
@@ -235,6 +235,7 @@ define void()* @get_external_preemptable_function() {
 ; COMMON-NEXT: .set weak_default_alias, aliasee
 ; COMMON-NEXT: .globl strong_local_alias
 ; COMMON-NEXT: .set strong_local_alias, aliasee
+; COMMON-NEXT: .set .Lstrong_local_alias$local, aliasee
 ; COMMON-NEXT: .weak weak_local_alias
 ; COMMON-NEXT: .set weak_local_alias, aliasee
 ; COMMON-NEXT: .globl strong_preemptable_alias


        


More information about the llvm-commits mailing list