1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

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

This commit is contained in:
Fangrui Song 2020-02-11 16:07:06 -08:00
parent 3f8a544115
commit a9c1f8f10e
3 changed files with 10 additions and 6 deletions

View File

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

View File

@ -12,7 +12,7 @@ target triple = "i386-pc-linux-gnu"
define i32 @foo() { define i32 @foo() {
; CHECK-LABEL: foo: ; CHECK-LABEL: foo:
; CHECK: leal __libc_resp@TLSLD ; CHECK: leal .L__libc_resp$local@TLSLDM
entry: entry:
%retval = alloca i32 ; <i32*> [#uses=1] %retval = alloca i32 ; <i32*> [#uses=1]
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0] %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
@ -27,7 +27,7 @@ return: ; preds = %entry
define i32 @bar() { define i32 @bar() {
; CHECK-LABEL: bar: ; CHECK-LABEL: bar:
; CHECK: leal __libc_resp@TLSLD ; CHECK: leal .L__libc_resp$local@TLSLDM
entry: entry:
%retval = alloca i32 ; <i32*> [#uses=1] %retval = alloca i32 ; <i32*> [#uses=1]
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0] %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]

View File

@ -108,9 +108,9 @@ define i32* @get_weak_default_alias() {
define i32* @get_strong_local_alias() { define i32* @get_strong_local_alias() {
ret i32* @strong_local_alias ret i32* @strong_local_alias
} }
; CHECK: leaq strong_local_alias(%rip), %rax ; CHECK: leaq .Lstrong_local_alias$local(%rip), %rax
; STATIC: movl $strong_local_alias, %eax ; STATIC: movl $.Lstrong_local_alias$local, %eax
; CHECK32: leal strong_local_alias@GOTOFF(%eax), %eax ; CHECK32: leal .Lstrong_local_alias$local@GOTOFF(%eax), %eax
@weak_local_alias = weak dso_local alias i32, i32* @aliasee @weak_local_alias = weak dso_local alias i32, i32* @aliasee
define i32* @get_weak_local_alias() { 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: .set weak_default_alias, aliasee
; COMMON-NEXT: .globl strong_local_alias ; COMMON-NEXT: .globl strong_local_alias
; COMMON-NEXT: .set strong_local_alias, aliasee ; COMMON-NEXT: .set strong_local_alias, aliasee
; COMMON-NEXT: .set .Lstrong_local_alias$local, aliasee
; COMMON-NEXT: .weak weak_local_alias ; COMMON-NEXT: .weak weak_local_alias
; COMMON-NEXT: .set weak_local_alias, aliasee ; COMMON-NEXT: .set weak_local_alias, aliasee
; COMMON-NEXT: .globl strong_preemptable_alias ; COMMON-NEXT: .globl strong_preemptable_alias