[llvm] [X86] Handle ifuncs in TargetMachine::isLargeGlobalObject() (PR #74911)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 8 19:16:16 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: Arthur Eubanks (aeubanks)
<details>
<summary>Changes</summary>
isLargeGlobalObject() didn't handle GlobalIFuncs, resulting in crashes.
Treat ifuncs the same as normal Functions.
---
Full diff: https://github.com/llvm/llvm-project/pull/74911.diff
2 Files Affected:
- (modified) llvm/lib/Target/TargetMachine.cpp (+4-3)
- (modified) llvm/test/CodeGen/X86/code-model-elf.ll (+110-12)
``````````diff
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index ff496d29b39121..86c819a8281031 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -43,10 +43,11 @@ bool TargetMachine::isLargeGlobalObject(const GlobalObject *GO) const {
if (getTargetTriple().getArch() != Triple::x86_64)
return false;
- if (isa<Function>(GO))
- return getCodeModel() == CodeModel::Large;
+ auto *GV = dyn_cast<GlobalVariable>(GO);
- auto *GV = cast<GlobalVariable>(GO);
+ // Functions/GlobalIFuncs are only large under the large code model.
+ if (!GV)
+ return getCodeModel() == CodeModel::Large;
if (GV->isThreadLocal())
return false;
diff --git a/llvm/test/CodeGen/X86/code-model-elf.ll b/llvm/test/CodeGen/X86/code-model-elf.ll
index 457c6bde354f2e..3154a3d9baaa3f 100644
--- a/llvm/test/CodeGen/X86/code-model-elf.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf.ll
@@ -583,6 +583,18 @@ define internal void @static_fn() #0 {
declare void @extern_fn()
+ at ifunc_func = ifunc void (), ptr @resolver
+ at dso_local_ifunc_func = dso_local ifunc void (), ptr @resolver
+
+define internal ptr @resolver() {
+; CHECK-LABEL: resolver:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: xorl %eax, %eax
+; CHECK-NEXT: retq
+entry:
+ ret ptr null
+}
+
define dso_local ptr @lea_static_fn() #0 {
; SMALL-STATIC-LABEL: lea_static_fn:
; SMALL-STATIC: # %bb.0:
@@ -616,9 +628,9 @@ define dso_local ptr @lea_static_fn() #0 {
;
; LARGE-PIC-LABEL: lea_static_fn:
; 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: .L14$pb:
+; LARGE-PIC-NEXT: leaq .L14$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L14$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq $static_fn at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
@@ -659,9 +671,9 @@ define dso_local ptr @lea_global_fn() #0 {
;
; LARGE-PIC-LABEL: lea_global_fn:
; LARGE-PIC: # %bb.0:
-; LARGE-PIC-NEXT: .L14$pb:
-; LARGE-PIC-NEXT: leaq .L14$pb(%rip), %rax
-; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L14$pb, %rcx
+; LARGE-PIC-NEXT: .L15$pb:
+; LARGE-PIC-NEXT: leaq .L15$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L15$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq $global_fn at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
@@ -702,9 +714,9 @@ define dso_local ptr @lea_extern_fn() #0 {
;
; LARGE-PIC-LABEL: lea_extern_fn:
; LARGE-PIC: # %bb.0:
-; LARGE-PIC-NEXT: .L15$pb:
-; LARGE-PIC-NEXT: leaq .L15$pb(%rip), %rax
-; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L15$pb, %rcx
+; 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: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq $extern_fn at GOT, %rax
; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
@@ -712,6 +724,92 @@ define dso_local ptr @lea_extern_fn() #0 {
ret ptr @extern_fn
}
+define dso_local ptr @lea_ifunc() #0 {
+; SMALL-STATIC-LABEL: lea_ifunc:
+; SMALL-STATIC: # %bb.0:
+; SMALL-STATIC-NEXT: movq ifunc_func at GOTPCREL(%rip), %rax
+; SMALL-STATIC-NEXT: retq
+;
+; MEDIUM-STATIC-LABEL: lea_ifunc:
+; MEDIUM-STATIC: # %bb.0:
+; MEDIUM-STATIC-NEXT: movq ifunc_func at GOTPCREL(%rip), %rax
+; MEDIUM-STATIC-NEXT: retq
+;
+; LARGE-STATIC-LABEL: lea_ifunc:
+; LARGE-STATIC: # %bb.0:
+; LARGE-STATIC-NEXT: movabsq $ifunc_func, %rax
+; LARGE-STATIC-NEXT: retq
+;
+; SMALL-PIC-LABEL: lea_ifunc:
+; SMALL-PIC: # %bb.0:
+; SMALL-PIC-NEXT: movq ifunc_func at GOTPCREL(%rip), %rax
+; SMALL-PIC-NEXT: retq
+;
+; MEDIUM-SMALL-DATA-PIC-LABEL: lea_ifunc:
+; MEDIUM-SMALL-DATA-PIC: # %bb.0:
+; MEDIUM-SMALL-DATA-PIC-NEXT: movq ifunc_func at GOTPCREL(%rip), %rax
+; MEDIUM-SMALL-DATA-PIC-NEXT: retq
+;
+; MEDIUM-PIC-LABEL: lea_ifunc:
+; MEDIUM-PIC: # %bb.0:
+; MEDIUM-PIC-NEXT: movq ifunc_func at GOTPCREL(%rip), %rax
+; MEDIUM-PIC-NEXT: retq
+;
+; LARGE-PIC-LABEL: lea_ifunc:
+; 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: addq %rax, %rcx
+; LARGE-PIC-NEXT: movabsq $ifunc_func at GOT, %rax
+; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
+; LARGE-PIC-NEXT: retq
+ ret ptr @ifunc_func
+}
+
+define dso_local ptr @lea_dso_local_ifunc() #0 {
+; SMALL-STATIC-LABEL: lea_dso_local_ifunc:
+; SMALL-STATIC: # %bb.0:
+; SMALL-STATIC-NEXT: movl $dso_local_ifunc_func, %eax
+; SMALL-STATIC-NEXT: retq
+;
+; MEDIUM-STATIC-LABEL: lea_dso_local_ifunc:
+; MEDIUM-STATIC: # %bb.0:
+; MEDIUM-STATIC-NEXT: movabsq $dso_local_ifunc_func, %rax
+; MEDIUM-STATIC-NEXT: retq
+;
+; LARGE-STATIC-LABEL: lea_dso_local_ifunc:
+; LARGE-STATIC: # %bb.0:
+; LARGE-STATIC-NEXT: movabsq $dso_local_ifunc_func, %rax
+; LARGE-STATIC-NEXT: retq
+;
+; SMALL-PIC-LABEL: lea_dso_local_ifunc:
+; SMALL-PIC: # %bb.0:
+; SMALL-PIC-NEXT: leaq dso_local_ifunc_func(%rip), %rax
+; SMALL-PIC-NEXT: retq
+;
+; MEDIUM-SMALL-DATA-PIC-LABEL: lea_dso_local_ifunc:
+; MEDIUM-SMALL-DATA-PIC: # %bb.0:
+; MEDIUM-SMALL-DATA-PIC-NEXT: leaq dso_local_ifunc_func(%rip), %rax
+; MEDIUM-SMALL-DATA-PIC-NEXT: retq
+;
+; MEDIUM-PIC-LABEL: lea_dso_local_ifunc:
+; MEDIUM-PIC: # %bb.0:
+; MEDIUM-PIC-NEXT: leaq dso_local_ifunc_func(%rip), %rax
+; MEDIUM-PIC-NEXT: retq
+;
+; LARGE-PIC-LABEL: lea_dso_local_ifunc:
+; 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: addq %rax, %rcx
+; LARGE-PIC-NEXT: movabsq $dso_local_ifunc_func at GOTOFF, %rax
+; LARGE-PIC-NEXT: addq %rcx, %rax
+; LARGE-PIC-NEXT: retq
+ ret ptr @dso_local_ifunc_func
+}
+
; FIXME: The result is same for small, medium and large model, because we
; specify pie option in the test case. And the type of tls is initial exec tls.
; For pic code. The large model code for pic tls should be emitted as below.
@@ -780,9 +878,9 @@ define dso_local float @load_constant_pool(float %x) #0 {
;
; LARGE-PIC-LABEL: load_constant_pool:
; 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: .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 ${{\.?LCPI[0-9]+_[0-9]+}}@GOTOFF, %rax
; LARGE-PIC-NEXT: addss (%rcx,%rax), %xmm0
``````````
</details>
https://github.com/llvm/llvm-project/pull/74911
More information about the llvm-commits
mailing list