Arm64EC has two different ways to refer to dllimport'ed functions in an object file. One is using the usual __imp_ prefix, the other is using an Arm64EC-specific prefix __imp_aux_. As far as I can tell, if a function is in an x64 DLL, __imp_aux_ refers to the actual x64 address, while __imp_ points to some linker-generated code that calls the exit thunk. So __imp_aux_ is used to refer to the address in non-call contexts, while __imp_ is used for calls to avoid the indirect call checker. There's one twist to this, though: if an object refers to a symbol using the __imp_aux_ prefix, the object file's symbol table must also contain the symbol with the usual __imp_ prefix. The symbol doesn't actually have to be used anywhere, it just has to exist; otherwise, the linker's symbol lookup in x64 import libraries doesn't work correctly. Currently, this is handled by emitting a .globl __imp_foo directive; we could try to design some better way to handle this. One minor quirk I haven't figured out: apparently, in Arm64EC mode, MSVC prefers to use a linker-synthesized stub to call dllimport'ed functions, instead of branching directly. The linker stub appears to do the same thing that inline code would do, so not sure if it's just a code-size optimization, or if the synthesized stub can actually do something other than just load from the import table in some circumstances. Differential Revision: https://reviews.llvm.org/D136202
39 lines
1.0 KiB
LLVM
39 lines
1.0 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
|
; RUN: llc -mtriple=arm64ec-pc-windows-msvc < %s | FileCheck %s
|
|
|
|
@a = external dllimport global i32
|
|
declare dllimport void @b()
|
|
|
|
define ptr @dllimport_var() nounwind {
|
|
; CHECK-LABEL: dllimport_var:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: adrp x0, __imp_a
|
|
; CHECK-NEXT: ldr x0, [x0, :lo12:__imp_a]
|
|
; CHECK-NEXT: ret
|
|
ret ptr @a
|
|
}
|
|
|
|
define ptr @dllimport_fn() nounwind {
|
|
; CHECK-LABEL: dllimport_fn:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: .globl __imp_b
|
|
; CHECK-NEXT: adrp x0, __imp_aux_b
|
|
; CHECK-NEXT: .globl __imp_b
|
|
; CHECK-NEXT: ldr x0, [x0, :lo12:__imp_aux_b]
|
|
; CHECK-NEXT: ret
|
|
ret ptr @b
|
|
}
|
|
|
|
define void @dllimport_fn_call() nounwind {
|
|
; CHECK-LABEL: dllimport_fn_call:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
|
|
; CHECK-NEXT: adrp x8, __imp_b
|
|
; CHECK-NEXT: ldr x8, [x8, :lo12:__imp_b]
|
|
; CHECK-NEXT: blr x8
|
|
; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
|
|
; CHECK-NEXT: ret
|
|
call void @b()
|
|
ret void
|
|
}
|