[llvm] [X86] Treat __ehdr_start as large (PR #79884)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 29 11:19:39 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: Arthur Eubanks (aeubanks)
<details>
<summary>Changes</summary>
The __ehdr_start symbol is added by the linker and points to the ELF file headers, which can be very far away from text. Treat it as a large symbol under the medium/large code models. Performance to access __ehdr_start is almost certainly not important.
There are a couple of other symbols that the linker adds [1], but this is the most relevant one that may be far away from text.
[1] https://github.com/llvm/llvm-project/blob/547c395b279a93357082ac06cf3e8fe37ebfc3fe/lld/ELF/Writer.cpp#L226
---
Full diff: https://github.com/llvm/llvm-project/pull/79884.diff
2 Files Affected:
- (modified) llvm/lib/Target/TargetMachine.cpp (+2)
- (modified) llvm/test/CodeGen/X86/code-model-elf.ll (+94-36)
``````````diff
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index 0839fb22d35a8fe..178d199836abe09 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -85,6 +85,8 @@ bool TargetMachine::isLargeGlobalValue(const GlobalValue *GVal) const {
getCodeModel() == CodeModel::Large) {
if (!GV->getValueType()->isSized())
return true;
+ if (GV->isDeclaration() && GV->getName() == "__ehdr_start")
+ return true;
const DataLayout &DL = GV->getParent()->getDataLayout();
uint64_t Size = DL.getTypeSizeInBits(GV->getValueType()) / 8;
return Size == 0 || Size > LargeDataThreshold;
diff --git a/llvm/test/CodeGen/X86/code-model-elf.ll b/llvm/test/CodeGen/X86/code-model-elf.ll
index afcffb3a7adeda4..4bc917a3b3aa6a0 100644
--- a/llvm/test/CodeGen/X86/code-model-elf.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf.ll
@@ -57,6 +57,7 @@ target triple = "x86_64--linux"
@opaque = external dso_local global %t
@forced_small_data = dso_local global [10 x i32] zeroinitializer, code_model "small", align 16
@forced_large_data = dso_local global [10 x i32] zeroinitializer, code_model "large", align 16
+ at __ehdr_start = external dso_local global i8
define dso_local ptr @lea_static_data() #0 {
; SMALL-STATIC-LABEL: lea_static_data:
@@ -800,6 +801,63 @@ define dso_local ptr @lea_opaque() #0 {
ret ptr @opaque
}
+define dso_local ptr @lea_ehdr_start() #0 {
+; SMALL-STATIC-LABEL: lea_ehdr_start:
+; SMALL-STATIC: # %bb.0:
+; SMALL-STATIC-NEXT: movl $__ehdr_start, %eax
+; SMALL-STATIC-NEXT: retq
+;
+; MEDIUM-STATIC-LABEL: lea_ehdr_start:
+; MEDIUM-STATIC: # %bb.0:
+; MEDIUM-STATIC-NEXT: movabsq $__ehdr_start, %rax
+; MEDIUM-STATIC-NEXT: retq
+;
+; LARGE-STATIC-LABEL: lea_ehdr_start:
+; LARGE-STATIC: # %bb.0:
+; LARGE-STATIC-NEXT: movabsq $__ehdr_start, %rax
+; LARGE-STATIC-NEXT: retq
+;
+; SMALL-PIC-LABEL: lea_ehdr_start:
+; SMALL-PIC: # %bb.0:
+; SMALL-PIC-NEXT: leaq __ehdr_start(%rip), %rax
+; SMALL-PIC-NEXT: retq
+;
+; MEDIUM-SMALL-DATA-PIC-LABEL: lea_ehdr_start:
+; MEDIUM-SMALL-DATA-PIC: # %bb.0:
+; MEDIUM-SMALL-DATA-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx
+; MEDIUM-SMALL-DATA-PIC-NEXT: movabsq $__ehdr_start at GOTOFF, %rax
+; MEDIUM-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
+; MEDIUM-SMALL-DATA-PIC-NEXT: retq
+;
+; MEDIUM-PIC-LABEL: lea_ehdr_start:
+; MEDIUM-PIC: # %bb.0:
+; MEDIUM-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx
+; MEDIUM-PIC-NEXT: movabsq $__ehdr_start at GOTOFF, %rax
+; MEDIUM-PIC-NEXT: addq %rcx, %rax
+; MEDIUM-PIC-NEXT: retq
+;
+; LARGE-PIC-LABEL: lea_ehdr_start:
+; LARGE-PIC: # %bb.0:
+; LARGE-PIC-NEXT: .L13$pb:
+; LARGE-PIC-NEXT: leaq .L13$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L13$pb, %rcx
+; LARGE-PIC-NEXT: addq %rax, %rcx
+; LARGE-PIC-NEXT: movabsq $__ehdr_start at GOTOFF, %rax
+; LARGE-PIC-NEXT: addq %rcx, %rax
+; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: lea_ehdr_start:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L13$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L13$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L13$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $__ehdr_start at GOTOFF, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
+ ret ptr @__ehdr_start
+}
+
define dso_local void @global_fn() #0 {
; CHECK-LABEL: global_fn:
; CHECK: # %bb.0:
@@ -861,9 +919,9 @@ define dso_local ptr @lea_static_fn() #0 {
;
; LARGE-PIC-LABEL: lea_static_fn:
; LARGE-PIC: # %bb.0:
-; LARGE-PIC-NEXT: .L16$pb:
-; LARGE-PIC-NEXT: leaq .L16$pb(%rip), %rax
-; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L16$pb, %rcx
+; LARGE-PIC-NEXT: .L17$pb:
+; LARGE-PIC-NEXT: leaq .L17$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L17$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq $static_fn at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
@@ -871,9 +929,9 @@ define dso_local ptr @lea_static_fn() #0 {
;
; LARGE-SMALL-DATA-PIC-LABEL: lea_static_fn:
; LARGE-SMALL-DATA-PIC: # %bb.0:
-; LARGE-SMALL-DATA-PIC-NEXT: .L16$pb:
-; LARGE-SMALL-DATA-PIC-NEXT: leaq .L16$pb(%rip), %rax
-; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L16$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: .L17$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L17$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L17$pb, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: movabsq $static_fn at GOTOFF, %rax
; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
@@ -914,9 +972,9 @@ define dso_local ptr @lea_global_fn() #0 {
;
; LARGE-PIC-LABEL: lea_global_fn:
; LARGE-PIC: # %bb.0:
-; LARGE-PIC-NEXT: .L17$pb:
-; LARGE-PIC-NEXT: leaq .L17$pb(%rip), %rax
-; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L17$pb, %rcx
+; LARGE-PIC-NEXT: .L18$pb:
+; LARGE-PIC-NEXT: leaq .L18$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L18$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq $global_fn at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
@@ -924,9 +982,9 @@ define dso_local ptr @lea_global_fn() #0 {
;
; LARGE-SMALL-DATA-PIC-LABEL: lea_global_fn:
; LARGE-SMALL-DATA-PIC: # %bb.0:
-; LARGE-SMALL-DATA-PIC-NEXT: .L17$pb:
-; LARGE-SMALL-DATA-PIC-NEXT: leaq .L17$pb(%rip), %rax
-; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L17$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: .L18$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L18$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L18$pb, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: movabsq $global_fn at GOTOFF, %rax
; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
@@ -967,9 +1025,9 @@ define dso_local ptr @lea_extern_fn() #0 {
;
; LARGE-PIC-LABEL: lea_extern_fn:
; LARGE-PIC: # %bb.0:
-; LARGE-PIC-NEXT: .L18$pb:
-; LARGE-PIC-NEXT: leaq .L18$pb(%rip), %rax
-; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L18$pb, %rcx
+; LARGE-PIC-NEXT: .L19$pb:
+; LARGE-PIC-NEXT: leaq .L19$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L19$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq $extern_fn at GOT, %rax
; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
@@ -977,9 +1035,9 @@ define dso_local ptr @lea_extern_fn() #0 {
;
; LARGE-SMALL-DATA-PIC-LABEL: lea_extern_fn:
; LARGE-SMALL-DATA-PIC: # %bb.0:
-; LARGE-SMALL-DATA-PIC-NEXT: .L18$pb:
-; LARGE-SMALL-DATA-PIC-NEXT: leaq .L18$pb(%rip), %rax
-; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L18$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: .L19$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L19$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L19$pb, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: movabsq $extern_fn at GOT, %rax
; LARGE-SMALL-DATA-PIC-NEXT: movq (%rcx,%rax), %rax
@@ -1020,9 +1078,9 @@ define dso_local ptr @lea_ifunc() #0 {
;
; LARGE-PIC-LABEL: lea_ifunc:
; LARGE-PIC: # %bb.0:
-; LARGE-PIC-NEXT: .L19$pb:
-; LARGE-PIC-NEXT: leaq .L19$pb(%rip), %rax
-; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L19$pb, %rcx
+; LARGE-PIC-NEXT: .L20$pb:
+; LARGE-PIC-NEXT: leaq .L20$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L20$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq $ifunc_func at GOT, %rax
; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
@@ -1030,9 +1088,9 @@ define dso_local ptr @lea_ifunc() #0 {
;
; LARGE-SMALL-DATA-PIC-LABEL: lea_ifunc:
; LARGE-SMALL-DATA-PIC: # %bb.0:
-; LARGE-SMALL-DATA-PIC-NEXT: .L19$pb:
-; LARGE-SMALL-DATA-PIC-NEXT: leaq .L19$pb(%rip), %rax
-; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L19$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: .L20$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L20$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L20$pb, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: movabsq $ifunc_func at GOT, %rax
; LARGE-SMALL-DATA-PIC-NEXT: movq (%rcx,%rax), %rax
@@ -1073,9 +1131,9 @@ define dso_local ptr @lea_dso_local_ifunc() #0 {
;
; LARGE-PIC-LABEL: lea_dso_local_ifunc:
; LARGE-PIC: # %bb.0:
-; LARGE-PIC-NEXT: .L20$pb:
-; LARGE-PIC-NEXT: leaq .L20$pb(%rip), %rax
-; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L20$pb, %rcx
+; LARGE-PIC-NEXT: .L21$pb:
+; LARGE-PIC-NEXT: leaq .L21$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L21$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq $dso_local_ifunc_func at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
@@ -1083,9 +1141,9 @@ define dso_local ptr @lea_dso_local_ifunc() #0 {
;
; LARGE-SMALL-DATA-PIC-LABEL: lea_dso_local_ifunc:
; LARGE-SMALL-DATA-PIC: # %bb.0:
-; LARGE-SMALL-DATA-PIC-NEXT: .L20$pb:
-; LARGE-SMALL-DATA-PIC-NEXT: leaq .L20$pb(%rip), %rax
-; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L20$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: .L21$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L21$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L21$pb, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: movabsq $dso_local_ifunc_func at GOTOFF, %rax
; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
@@ -1160,9 +1218,9 @@ define dso_local float @load_constant_pool(float %x) #0 {
;
; LARGE-PIC-LABEL: load_constant_pool:
; LARGE-PIC: # %bb.0:
-; LARGE-PIC-NEXT: .L22$pb:
-; LARGE-PIC-NEXT: leaq .L22$pb(%rip), %rax
-; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L22$pb, %rcx
+; LARGE-PIC-NEXT: .L23$pb:
+; LARGE-PIC-NEXT: leaq .L23$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L23$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq ${{\.?LCPI[0-9]+_[0-9]+}}@GOTOFF, %rax
; LARGE-PIC-NEXT: addss (%rcx,%rax), %xmm0
@@ -1170,9 +1228,9 @@ define dso_local float @load_constant_pool(float %x) #0 {
;
; LARGE-SMALL-DATA-PIC-LABEL: load_constant_pool:
; LARGE-SMALL-DATA-PIC: # %bb.0:
-; LARGE-SMALL-DATA-PIC-NEXT: .L22$pb:
-; LARGE-SMALL-DATA-PIC-NEXT: leaq .L22$pb(%rip), %rax
-; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L22$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: .L23$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L23$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L23$pb, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: movabsq ${{\.?LCPI[0-9]+_[0-9]+}}@GOTOFF, %rax
; LARGE-SMALL-DATA-PIC-NEXT: addss (%rcx,%rax), %xmm0
``````````
</details>
https://github.com/llvm/llvm-project/pull/79884
More information about the llvm-commits
mailing list