-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[LLD][COFF] Add support for ARM64EC import call thunks with extended range #109703
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
REQUIRES: aarch64, x86 | ||
RUN: split-file %s %t.dir && cd %t.dir | ||
|
||
RUN: llvm-mc -filetype=obj -triple=arm64ec-windows test.s -o test.obj | ||
RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o loadconfig-arm64ec.obj | ||
RUN: llvm-lib -machine:arm64ec -def:test.def -out:test.lib | ||
|
||
RUN: lld-link -machine:arm64ec -dll -noentry -out:out.dll loadconfig-arm64ec.obj test.obj test.lib | ||
|
||
RUN: llvm-objdump -d out.dll | FileCheck --check-prefix=DISASM %s | ||
DISASM: 0000000180001000 <.text>: | ||
DISASM-NEXT: 180001000: 52800000 mov w0, #0x0 // =0 | ||
DISASM-NEXT: 180001004: d65f03c0 ret | ||
DISASM-NEXT: ... | ||
DISASM-NEXT: 188001008: b000000b adrp x11, 0x188002000 | ||
DISASM-NEXT: 18800100c: f940016b ldr x11, [x11] | ||
DISASM-NEXT: 188001010: f0fbffea adrp x10, 0x180000000 | ||
DISASM-NEXT: 188001014: 9100014a add x10, x10, #0x0 | ||
DISASM-NEXT: 188001018: 90fc0010 adrp x16, 0x180001000 <.text> | ||
DISASM-NEXT: 18800101c: 91000210 add x16, x16, #0x0 | ||
DISASM-NEXT: 188001020: d61f0200 br x16 | ||
|
||
#--- test.s | ||
.text | ||
.globl __icall_helper_arm64ec | ||
.p2align 2, 0x0 | ||
__icall_helper_arm64ec: | ||
mov w0, #0 | ||
ret | ||
|
||
.space 0x8000000 | ||
|
||
.data | ||
.rva __imp_func | ||
|
||
#--- test.def | ||
NAME test.dll | ||
EXPORTS | ||
func |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this test even require a thunk? We're only referencing
__imp_func
, notfunc
directly, so we should only need the raw IAT entry, no thunks at all? (I guess this is some of the other arm64ec aspects that we've already been through a couple times, that I haven't really internalized yet - sorry about that.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On ARM64EC,
__imp_func
references the auxiliary IAT, not the regular one. The auxiliary IAT is guaranteed to be directly callable by EC code, so the caller doesn’t need to use__icall_helper_arm64ec
, as it would for indirect calls. Initially, the auxiliary IAT is filled with__impchk_*
thunks (#107931), which handle the use of__icall_helper_arm64ec
to call via the regular IAT. The OS may later update the auxiliary IAT entries to allow direct EC calls if the callee is also EC.For ARM64EC, func references the x86 thunk that calls the regular IAT (
__imp_aux_func
), while#func
references the ARM thunk that calls the auxiliary IAT (__imp_func
). At runtime, if the imported function is x86, two thunks are involved:#func
calls__imp_func
, which points to__impchk_func
, and this ultimately invokes the imported function pointer stored in__imp_aux_func
using__icall_helper_arm64ec
.