mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
[X86][ELF] Prefer lowering MC_GlobalAddress operands to .Lfoo$local for STV_DEFAULT only
This patch restricts the behaviour of referencing via .Lfoo$local local aliases, introduced in https://reviews.llvm.org/D73230, to STV_DEFAULT globals only. Hidden symbols via --fvisiblity=hidden (https://gcc.gnu.org/wiki/Visibility) is an important scenario. Benefits: - Improves the size of object files by using fewer STT_SECTION symbols. - The code reads a bit better (it was not obvious to me without going back to the code reviews why the canBenefitFromLocalAlias function currently doesn't consider visibility). - There is also a side benefit in restoring the effectiveness of the --wrap linker option and making the behavior of --wrap consistent between LTO and normal builds for references within a translation-unit. Note: this --wrap behavior (which is specific to LLD) should not be considered reliable. See comments on https://reviews.llvm.org/D73230 for more. Differential Revision: https://reviews.llvm.org/D85782 (cherry picked from commit 4cb016cd2d8467c572b2e5c5d34f376ee79e4ac1)
This commit is contained in:
parent
e9634e03cf
commit
d8484b56e4
@ -104,7 +104,8 @@ bool GlobalValue::isInterposable() const {
|
|||||||
|
|
||||||
bool GlobalValue::canBenefitFromLocalAlias() const {
|
bool GlobalValue::canBenefitFromLocalAlias() const {
|
||||||
// See AsmPrinter::getSymbolPreferLocal().
|
// See AsmPrinter::getSymbolPreferLocal().
|
||||||
return GlobalObject::isExternalLinkage(getLinkage()) && !isDeclaration() &&
|
return hasDefaultVisibility() &&
|
||||||
|
GlobalObject::isExternalLinkage(getLinkage()) && !isDeclaration() &&
|
||||||
!isa<GlobalIFunc>(this) && !hasComdat();
|
!isa<GlobalIFunc>(this) && !hasComdat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,6 @@ entry:
|
|||||||
; ARM64: .data{{$}}
|
; ARM64: .data{{$}}
|
||||||
; ARM64: .globl __emutls_v.i4
|
; ARM64: .globl __emutls_v.i4
|
||||||
; ARM64-LABEL: __emutls_v.i4:
|
; ARM64-LABEL: __emutls_v.i4:
|
||||||
; ARM64-NEXT: .L__emutls_v.i4$local:
|
|
||||||
; ARM64-NEXT: .xword 4
|
; ARM64-NEXT: .xword 4
|
||||||
; ARM64-NEXT: .xword 4
|
; ARM64-NEXT: .xword 4
|
||||||
; ARM64-NEXT: .xword 0
|
; ARM64-NEXT: .xword 0
|
||||||
@ -163,7 +162,6 @@ entry:
|
|||||||
|
|
||||||
; ARM64: .section .rodata,
|
; ARM64: .section .rodata,
|
||||||
; ARM64-LABEL: __emutls_t.i4:
|
; ARM64-LABEL: __emutls_t.i4:
|
||||||
; ARM64-NEXT: .L__emutls_t.i4$local:
|
|
||||||
; ARM64-NEXT: .word 15
|
; ARM64-NEXT: .word 15
|
||||||
|
|
||||||
; ARM64-NOT: __emutls_v.i5:
|
; ARM64-NOT: __emutls_v.i5:
|
||||||
|
@ -238,7 +238,6 @@ entry:
|
|||||||
; ARM32: .data{{$}}
|
; ARM32: .data{{$}}
|
||||||
; ARM32: .globl __emutls_v.i4
|
; ARM32: .globl __emutls_v.i4
|
||||||
; ARM32-LABEL: __emutls_v.i4:
|
; ARM32-LABEL: __emutls_v.i4:
|
||||||
; ARM32-NEXT: .L__emutls_v.i4$local:
|
|
||||||
; ARM32-NEXT: .long 4
|
; ARM32-NEXT: .long 4
|
||||||
; ARM32-NEXT: .long 4
|
; ARM32-NEXT: .long 4
|
||||||
; ARM32-NEXT: .long 0
|
; ARM32-NEXT: .long 0
|
||||||
@ -246,7 +245,6 @@ entry:
|
|||||||
|
|
||||||
; ARM32: .section .rodata,
|
; ARM32: .section .rodata,
|
||||||
; ARM32-LABEL: __emutls_t.i4:
|
; ARM32-LABEL: __emutls_t.i4:
|
||||||
; ARM32-NEXT: .L__emutls_t.i4$local:
|
|
||||||
; ARM32-NEXT: .long 15
|
; ARM32-NEXT: .long 15
|
||||||
|
|
||||||
; ARM32-NOT: __emutls_v.i5:
|
; ARM32-NOT: __emutls_v.i5:
|
||||||
|
@ -12,7 +12,7 @@ target triple = "i386-pc-linux-gnu"
|
|||||||
|
|
||||||
define i32 @foo() {
|
define i32 @foo() {
|
||||||
; CHECK-LABEL: foo:
|
; CHECK-LABEL: foo:
|
||||||
; CHECK: leal .L__libc_resp$local@TLSLDM
|
; CHECK: leal __libc_resp@TLSLD
|
||||||
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 .L__libc_resp$local@TLSLDM
|
; CHECK: leal __libc_resp@TLSLD
|
||||||
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]
|
||||||
|
@ -20,6 +20,14 @@ define i32* @get_strong_default_global() {
|
|||||||
; STATIC: movl $strong_default_global, %eax
|
; STATIC: movl $strong_default_global, %eax
|
||||||
; CHECK32: movl strong_default_global@GOT(%eax), %eax
|
; CHECK32: movl strong_default_global@GOT(%eax), %eax
|
||||||
|
|
||||||
|
@strong_hidden_global = hidden global i32 42
|
||||||
|
define i32* @get_hidden_default_global() {
|
||||||
|
ret i32* @strong_hidden_global
|
||||||
|
}
|
||||||
|
; CHECK: leaq strong_hidden_global(%rip), %rax
|
||||||
|
; STATIC: movl $strong_hidden_global, %eax
|
||||||
|
; CHECK32: leal strong_hidden_global@GOTOFF(%eax), %eax
|
||||||
|
|
||||||
@weak_default_global = weak global i32 42
|
@weak_default_global = weak global i32 42
|
||||||
define i32* @get_weak_default_global() {
|
define i32* @get_weak_default_global() {
|
||||||
ret i32* @weak_default_global
|
ret i32* @weak_default_global
|
||||||
@ -96,6 +104,14 @@ define i32* @get_strong_default_alias() {
|
|||||||
; STATIC: movl $strong_default_alias, %eax
|
; STATIC: movl $strong_default_alias, %eax
|
||||||
; CHECK32: movl strong_default_alias@GOT(%eax), %eax
|
; CHECK32: movl strong_default_alias@GOT(%eax), %eax
|
||||||
|
|
||||||
|
@strong_hidden_alias = hidden alias i32, i32* @aliasee
|
||||||
|
define i32* @get_strong_hidden_alias() {
|
||||||
|
ret i32* @strong_hidden_alias
|
||||||
|
}
|
||||||
|
; CHECK: leaq strong_hidden_alias(%rip), %rax
|
||||||
|
; STATIC: movl $strong_hidden_alias, %eax
|
||||||
|
; CHECK32: leal strong_hidden_alias@GOTOFF(%eax), %eax
|
||||||
|
|
||||||
@weak_default_alias = weak alias i32, i32* @aliasee
|
@weak_default_alias = weak alias i32, i32* @aliasee
|
||||||
define i32* @get_weak_default_alias() {
|
define i32* @get_weak_default_alias() {
|
||||||
ret i32* @weak_default_alias
|
ret i32* @weak_default_alias
|
||||||
@ -149,6 +165,16 @@ define void()* @get_strong_default_function() {
|
|||||||
; STATIC: movl $strong_default_function, %eax
|
; STATIC: movl $strong_default_function, %eax
|
||||||
; CHECK32: movl strong_default_function@GOT(%eax), %eax
|
; CHECK32: movl strong_default_function@GOT(%eax), %eax
|
||||||
|
|
||||||
|
define hidden void @strong_hidden_function() {
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
define void()* @get_strong_hidden_function() {
|
||||||
|
ret void()* @strong_hidden_function
|
||||||
|
}
|
||||||
|
; CHECK: leaq strong_hidden_function(%rip), %rax
|
||||||
|
; STATIC: movl $strong_hidden_function, %eax
|
||||||
|
; CHECK32: leal strong_hidden_function@GOTOFF(%eax), %eax
|
||||||
|
|
||||||
define weak void @weak_default_function() {
|
define weak void @weak_default_function() {
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
@ -234,6 +260,9 @@ define void()* @get_external_preemptable_function() {
|
|||||||
|
|
||||||
; COMMON: .globl strong_default_alias
|
; COMMON: .globl strong_default_alias
|
||||||
; COMMON-NEXT: .set strong_default_alias, aliasee
|
; COMMON-NEXT: .set strong_default_alias, aliasee
|
||||||
|
; COMMON-NEXT: .globl strong_hidden_alias
|
||||||
|
; COMMON-NEXT: .hidden strong_hidden_alias
|
||||||
|
; COMMON-NEXT: .set strong_hidden_alias, aliasee
|
||||||
; COMMON-NEXT: .weak weak_default_alias
|
; COMMON-NEXT: .weak weak_default_alias
|
||||||
; 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
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
$comdat_func = comdat any
|
$comdat_func = comdat any
|
||||||
|
|
||||||
; CHECK-LABEL: func2:
|
; CHECK-LABEL: func2:
|
||||||
; CHECK-NEXT: .Lfunc2$local
|
; CHECK-NOT: .Lfunc2$local
|
||||||
|
|
||||||
declare void @func()
|
declare void @func()
|
||||||
|
|
||||||
|
@ -12,5 +12,5 @@ define fastcc i32 @tailcaller(i32 %in1, i32 %in2) {
|
|||||||
entry:
|
entry:
|
||||||
%tmp11 = tail call fastcc i32 @tailcallee( i32 %in1, i32 %in2, i32 %in1, i32 %in2 ) ; <i32> [#uses=1]
|
%tmp11 = tail call fastcc i32 @tailcallee( i32 %in1, i32 %in2, i32 %in1, i32 %in2 ) ; <i32> [#uses=1]
|
||||||
ret i32 %tmp11
|
ret i32 %tmp11
|
||||||
; CHECK: jmp .Ltailcallee$local
|
; CHECK: jmp tailcallee
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ entry:
|
|||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
; CHECK: tailcall_hidden:
|
; CHECK: tailcall_hidden:
|
||||||
; CHECK: jmp .Ltailcallee_hidden$local
|
; CHECK: jmp tailcallee_hidden
|
||||||
|
|
||||||
define internal void @tailcallee_internal() {
|
define internal void @tailcallee_internal() {
|
||||||
entry:
|
entry:
|
||||||
|
@ -12,5 +12,5 @@ define tailcc i32 @tailcaller(i32 %in1, i32 %in2) {
|
|||||||
entry:
|
entry:
|
||||||
%tmp11 = tail call tailcc i32 @tailcallee( i32 %in1, i32 %in2, i32 %in1, i32 %in2 ) ; <i32> [#uses=1]
|
%tmp11 = tail call tailcc i32 @tailcallee( i32 %in1, i32 %in2, i32 %in1, i32 %in2 ) ; <i32> [#uses=1]
|
||||||
ret i32 %tmp11
|
ret i32 %tmp11
|
||||||
; CHECK: jmp .Ltailcallee$local
|
; CHECK: jmp tailcallee
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user