Skip to content

Commit 4cb016c

Browse files
committed
[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
1 parent 41f4973 commit 4cb016c

9 files changed

+37
-11
lines changed

llvm/lib/IR/Globals.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ bool GlobalValue::isInterposable() const {
104104

105105
bool GlobalValue::canBenefitFromLocalAlias() const {
106106
// See AsmPrinter::getSymbolPreferLocal().
107-
return GlobalObject::isExternalLinkage(getLinkage()) && !isDeclaration() &&
107+
return hasDefaultVisibility() &&
108+
GlobalObject::isExternalLinkage(getLinkage()) && !isDeclaration() &&
108109
!isa<GlobalIFunc>(this) && !hasComdat();
109110
}
110111

llvm/test/CodeGen/AArch64/emutls.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,13 @@ entry:
155155
; ARM64: .data{{$}}
156156
; ARM64: .globl __emutls_v.i4
157157
; ARM64-LABEL: __emutls_v.i4:
158-
; ARM64-NEXT: .L__emutls_v.i4$local:
159158
; ARM64-NEXT: .xword 4
160159
; ARM64-NEXT: .xword 4
161160
; ARM64-NEXT: .xword 0
162161
; ARM64-NEXT: .xword __emutls_t.i4
163162

164163
; ARM64: .section .rodata,
165164
; ARM64-LABEL: __emutls_t.i4:
166-
; ARM64-NEXT: .L__emutls_t.i4$local:
167165
; ARM64-NEXT: .word 15
168166

169167
; ARM64-NOT: __emutls_v.i5:

llvm/test/CodeGen/ARM/emutls.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,13 @@ entry:
238238
; ARM32: .data{{$}}
239239
; ARM32: .globl __emutls_v.i4
240240
; ARM32-LABEL: __emutls_v.i4:
241-
; ARM32-NEXT: .L__emutls_v.i4$local:
242241
; ARM32-NEXT: .long 4
243242
; ARM32-NEXT: .long 4
244243
; ARM32-NEXT: .long 0
245244
; ARM32-NEXT: .long __emutls_t.i4
246245

247246
; ARM32: .section .rodata,
248247
; ARM32-LABEL: __emutls_t.i4:
249-
; ARM32-NEXT: .L__emutls_t.i4$local:
250248
; ARM32-NEXT: .long 15
251249

252250
; ARM32-NOT: __emutls_v.i5:

llvm/test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ target triple = "i386-pc-linux-gnu"
1212

1313
define i32 @foo() {
1414
; CHECK-LABEL: foo:
15-
; CHECK: leal .L__libc_resp$local@TLSLDM
15+
; CHECK: leal __libc_resp@TLSLD
1616
entry:
1717
%retval = alloca i32 ; <i32*> [#uses=1]
1818
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
@@ -27,7 +27,7 @@ return: ; preds = %entry
2727

2828
define i32 @bar() {
2929
; CHECK-LABEL: bar:
30-
; CHECK: leal .L__libc_resp$local@TLSLDM
30+
; CHECK: leal __libc_resp@TLSLD
3131
entry:
3232
%retval = alloca i32 ; <i32*> [#uses=1]
3333
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]

llvm/test/CodeGen/X86/linux-preemption.ll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ define i32* @get_strong_default_global() {
2020
; STATIC: movl $strong_default_global, %eax
2121
; CHECK32: movl strong_default_global@GOT(%eax), %eax
2222

23+
@strong_hidden_global = hidden global i32 42
24+
define i32* @get_hidden_default_global() {
25+
ret i32* @strong_hidden_global
26+
}
27+
; CHECK: leaq strong_hidden_global(%rip), %rax
28+
; STATIC: movl $strong_hidden_global, %eax
29+
; CHECK32: leal strong_hidden_global@GOTOFF(%eax), %eax
30+
2331
@weak_default_global = weak global i32 42
2432
define i32* @get_weak_default_global() {
2533
ret i32* @weak_default_global
@@ -96,6 +104,14 @@ define i32* @get_strong_default_alias() {
96104
; STATIC: movl $strong_default_alias, %eax
97105
; CHECK32: movl strong_default_alias@GOT(%eax), %eax
98106

107+
@strong_hidden_alias = hidden alias i32, i32* @aliasee
108+
define i32* @get_strong_hidden_alias() {
109+
ret i32* @strong_hidden_alias
110+
}
111+
; CHECK: leaq strong_hidden_alias(%rip), %rax
112+
; STATIC: movl $strong_hidden_alias, %eax
113+
; CHECK32: leal strong_hidden_alias@GOTOFF(%eax), %eax
114+
99115
@weak_default_alias = weak alias i32, i32* @aliasee
100116
define i32* @get_weak_default_alias() {
101117
ret i32* @weak_default_alias
@@ -149,6 +165,16 @@ define void()* @get_strong_default_function() {
149165
; STATIC: movl $strong_default_function, %eax
150166
; CHECK32: movl strong_default_function@GOT(%eax), %eax
151167

168+
define hidden void @strong_hidden_function() {
169+
ret void
170+
}
171+
define void()* @get_strong_hidden_function() {
172+
ret void()* @strong_hidden_function
173+
}
174+
; CHECK: leaq strong_hidden_function(%rip), %rax
175+
; STATIC: movl $strong_hidden_function, %eax
176+
; CHECK32: leal strong_hidden_function@GOTOFF(%eax), %eax
177+
152178
define weak void @weak_default_function() {
153179
ret void
154180
}
@@ -234,6 +260,9 @@ define void()* @get_external_preemptable_function() {
234260

235261
; COMMON: .globl strong_default_alias
236262
; COMMON-NEXT: .set strong_default_alias, aliasee
263+
; COMMON-NEXT: .globl strong_hidden_alias
264+
; COMMON-NEXT: .hidden strong_hidden_alias
265+
; COMMON-NEXT: .set strong_hidden_alias, aliasee
237266
; COMMON-NEXT: .weak weak_default_alias
238267
; COMMON-NEXT: .set weak_default_alias, aliasee
239268
; COMMON-NEXT: .globl strong_local_alias

llvm/test/CodeGen/X86/semantic-interposition-comdat.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$comdat_func = comdat any
44

55
; CHECK-LABEL: func2:
6-
; CHECK-NEXT: .Lfunc2$local
6+
; CHECK-NOT: .Lfunc2$local
77

88
declare void @func()
99

llvm/test/CodeGen/X86/tailcallpic1.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ define fastcc i32 @tailcaller(i32 %in1, i32 %in2) {
1212
entry:
1313
%tmp11 = tail call fastcc i32 @tailcallee( i32 %in1, i32 %in2, i32 %in1, i32 %in2 ) ; <i32> [#uses=1]
1414
ret i32 %tmp11
15-
; CHECK: jmp .Ltailcallee$local
15+
; CHECK: jmp tailcallee
1616
}

llvm/test/CodeGen/X86/tailcallpic3.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ entry:
1616
ret void
1717
}
1818
; CHECK: tailcall_hidden:
19-
; CHECK: jmp .Ltailcallee_hidden$local
19+
; CHECK: jmp tailcallee_hidden
2020

2121
define internal void @tailcallee_internal() {
2222
entry:

llvm/test/CodeGen/X86/tailccpic1.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ define tailcc i32 @tailcaller(i32 %in1, i32 %in2) {
1212
entry:
1313
%tmp11 = tail call tailcc i32 @tailcallee( i32 %in1, i32 %in2, i32 %in1, i32 %in2 ) ; <i32> [#uses=1]
1414
ret i32 %tmp11
15-
; CHECK: jmp .Ltailcallee$local
15+
; CHECK: jmp tailcallee
1616
}

0 commit comments

Comments
 (0)