mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-21 00:32:23 +00:00
edfd4f18bc
This patch builds upon the two preceding MC changes to implement the basic ELFv2 function call convention. In the ELFv1 ABI, a "function descriptor" was associated with every function, pointing to both the entry address and the related TOC base (and a static chain pointer for nested functions). Function pointers would actually refer to that descriptor, and the indirect call sequence needed to load up both entry address and TOC base. In the ELFv2 ABI, there are no more function descriptors, and function pointers simply refer to the (global) entry point of the function code. Indirect function calls simply branch to that address, after loading it up into r12 (as required by the ABI rules for a global entry point). Direct function calls continue to just do a "bl" to the target symbol; this will be resolved by the linker to the local entry point of the target function if it is local, and to a PLT stub if it is global. That PLT stub would then load the (global) entry point address of the final target into r12 and branch to it. Note that when performing a local function call, r2 must be set up to point to the current TOC base: if the target ends up local, the ABI requires that its local entry point is called with r2 set up; if the target ends up global, the PLT stub requires that r2 is set up. This patch implements all LLVM changes to implement that scheme: - No longer create a function descriptor when emitting a function definition (in EmitFunctionEntryLabel) - Emit two entry points *if* the function needs the TOC base (r2) anywhere (this is done EmitFunctionBodyStart; note that this cannot be done in EmitFunctionBodyStart because the global entry point prologue code must be *part* of the function as covered by debug info). - In order to make use tracking of r2 (as needed above) work correctly, mark direct function calls as implicitly using r2. - Implement the ELFv2 indirect function call sequence (no function descriptors; load target address into r12). - When creating an ELFv2 object file, emit the .abiversion 2 directive to tell the linker to create the appropriate version of PLT stubs. Reviewed by Hal Finkel. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213489 91177308-0d34-0410-b5e6-96231b3b80d8
47 lines
1.2 KiB
LLVM
47 lines
1.2 KiB
LLVM
; RUN: llc -march=ppc64le -mcpu=pwr8 < %s | FileCheck %s
|
|
; RUN: llc -march=ppc64le -mcpu=pwr8 -O0 < %s | FileCheck %s
|
|
|
|
target datalayout = "e-m:e-i64:64-n32:64"
|
|
target triple = "powerpc64le-unknown-linux-gnu"
|
|
|
|
@number64 = global i64 10, align 8
|
|
|
|
; CHECK: .abiversion 2
|
|
|
|
define i64 @use_toc(i64 %a) nounwind {
|
|
entry:
|
|
; CHECK-LABEL: @use_toc
|
|
; CHECK-NEXT: .Ltmp[[TMP1:[0-9]+]]:
|
|
; CHECK-NEXT: addis 2, 12, .TOC.-.Ltmp[[TMP1]]@ha
|
|
; CHECK-NEXT: addi 2, 2, .TOC.-.Ltmp[[TMP1]]@l
|
|
; CHECK-NEXT: .Ltmp[[TMP2:[0-9]+]]:
|
|
; CHECK-NEXT: .localentry use_toc, .Ltmp[[TMP2]]-.Ltmp[[TMP1]]
|
|
; CHECK-NEXT: %entry
|
|
%0 = load i64* @number64, align 8
|
|
%cmp = icmp eq i64 %0, %a
|
|
%conv1 = zext i1 %cmp to i64
|
|
ret i64 %conv1
|
|
}
|
|
|
|
declare void @callee()
|
|
define void @use_toc_implicit() nounwind {
|
|
entry:
|
|
; CHECK-LABEL: @use_toc_implicit
|
|
; CHECK-NEXT: .Ltmp[[TMP1:[0-9]+]]:
|
|
; CHECK-NEXT: addis 2, 12, .TOC.-.Ltmp[[TMP1]]@ha
|
|
; CHECK-NEXT: addi 2, 2, .TOC.-.Ltmp[[TMP1]]@l
|
|
; CHECK-NEXT: .Ltmp[[TMP2:[0-9]+]]:
|
|
; CHECK-NEXT: .localentry use_toc_implicit, .Ltmp[[TMP2]]-.Ltmp[[TMP1]]
|
|
; CHECK-NEXT: %entry
|
|
call void @callee()
|
|
ret void
|
|
}
|
|
|
|
define i64 @no_toc(i64 %a) nounwind {
|
|
entry:
|
|
; CHECK-LABEL: @no_toc
|
|
; CHECK-NEXT: %entry
|
|
ret i64 %a
|
|
}
|
|
|