-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[X86] Handle ifuncs in TargetMachine::isLargeGlobalObject() #74911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isLargeGlobalObject() didn't handle GlobalIFuncs, resulting in crashes. Treat it the same as normal Functions.
@llvm/pr-subscribers-backend-x86 Author: Arthur Eubanks (aeubanks) ChangesisLargeGlobalObject() 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:
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()
+@ifunc_func = ifunc void (), ptr @resolver
+@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@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@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@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@GOTPCREL(%rip), %rax
+; SMALL-STATIC-NEXT: retq
+;
+; MEDIUM-STATIC-LABEL: lea_ifunc:
+; MEDIUM-STATIC: # %bb.0:
+; MEDIUM-STATIC-NEXT: movq ifunc_func@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@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@GOTPCREL(%rip), %rax
+; MEDIUM-SMALL-DATA-PIC-NEXT: retq
+;
+; MEDIUM-PIC-LABEL: lea_ifunc:
+; MEDIUM-PIC: # %bb.0:
+; MEDIUM-PIC-NEXT: movq ifunc_func@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@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@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
|
rnk
approved these changes
Dec 12, 2023
Zentrik
added a commit
to Zentrik/llvm-project
that referenced
this pull request
Jun 30, 2024
…lvm#74911)" This reverts commit 3850131.
Zentrik
added a commit
to Zentrik/llvm-project
that referenced
this pull request
Jul 7, 2024
…lvm#74911)" This reverts commit 3850131.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
isLargeGlobalObject() didn't handle GlobalIFuncs, resulting in crashes.
Treat ifuncs the same as normal Functions.