mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-26 23:29:22 +00:00
add support for PIC on linux x86-64
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52139 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
313f0e63f7
commit
d674b4e87d
@ -197,11 +197,16 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool printGOT(TargetMachine &TM, const X86Subtarget* ST) {
|
static inline bool shouldPrintGOT(TargetMachine &TM, const X86Subtarget* ST) {
|
||||||
return ST->isPICStyleGOT() && TM.getRelocationModel() == Reloc::PIC_;
|
return ST->isPICStyleGOT() && TM.getRelocationModel() == Reloc::PIC_;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool printStub(TargetMachine &TM, const X86Subtarget* ST) {
|
static inline bool shouldPrintPLT(TargetMachine &TM, const X86Subtarget* ST) {
|
||||||
|
return ST->isTargetELF() && TM.getRelocationModel() == Reloc::PIC_ &&
|
||||||
|
(ST->isPICStyleRIPRel() || ST->isPICStyleGOT());
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool shouldPrintStub(TargetMachine &TM, const X86Subtarget* ST) {
|
||||||
return ST->isPICStyleStub() && TM.getRelocationModel() != Reloc::Static;
|
return ST->isPICStyleStub() && TM.getRelocationModel() != Reloc::Static;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +309,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
|
|||||||
needCloseParen = true;
|
needCloseParen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (printStub(TM, Subtarget)) {
|
if (shouldPrintStub(TM, Subtarget)) {
|
||||||
// Link-once, declaration, or Weakly-linked global variables need
|
// Link-once, declaration, or Weakly-linked global variables need
|
||||||
// non-lazily-resolved stubs
|
// non-lazily-resolved stubs
|
||||||
if (GV->isDeclaration() ||
|
if (GV->isDeclaration() ||
|
||||||
@ -333,11 +338,11 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
|
|||||||
}
|
}
|
||||||
O << Name;
|
O << Name;
|
||||||
|
|
||||||
if (isCallOp && isa<Function>(GV)) {
|
if (isCallOp) {
|
||||||
if (printGOT(TM, Subtarget)) {
|
if (shouldPrintPLT(TM, Subtarget)) {
|
||||||
// Assemble call via PLT for non-local symbols
|
// Assemble call via PLT for externally visible symbols
|
||||||
if (!(GV->hasHiddenVisibility() || GV->hasProtectedVisibility()) ||
|
if (!GV->hasHiddenVisibility() && !GV->hasProtectedVisibility() &&
|
||||||
GV->isDeclaration())
|
!GV->hasInternalLinkage())
|
||||||
O << "@PLT";
|
O << "@PLT";
|
||||||
}
|
}
|
||||||
if (Subtarget->isTargetCygMing() && GV->isDeclaration())
|
if (Subtarget->isTargetCygMing() && GV->isDeclaration())
|
||||||
@ -364,7 +369,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
|
|||||||
else
|
else
|
||||||
O << "@NTPOFF"; // local exec TLS model
|
O << "@NTPOFF"; // local exec TLS model
|
||||||
} else if (isMemOp) {
|
} else if (isMemOp) {
|
||||||
if (printGOT(TM, Subtarget)) {
|
if (shouldPrintGOT(TM, Subtarget)) {
|
||||||
if (Subtarget->GVRequiresExtraLoad(GV, TM, false))
|
if (Subtarget->GVRequiresExtraLoad(GV, TM, false))
|
||||||
O << "@GOT";
|
O << "@GOT";
|
||||||
else
|
else
|
||||||
@ -396,7 +401,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
|
|||||||
bool needCloseParen = false;
|
bool needCloseParen = false;
|
||||||
std::string Name(TAI->getGlobalPrefix());
|
std::string Name(TAI->getGlobalPrefix());
|
||||||
Name += MO.getSymbolName();
|
Name += MO.getSymbolName();
|
||||||
if (isCallOp && printStub(TM, Subtarget)) {
|
if (isCallOp && shouldPrintStub(TM, Subtarget)) {
|
||||||
FnStubs.insert(Name);
|
FnStubs.insert(Name);
|
||||||
printSuffixedName(Name, "$stub");
|
printSuffixedName(Name, "$stub");
|
||||||
return;
|
return;
|
||||||
@ -412,7 +417,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
|
|||||||
|
|
||||||
O << Name;
|
O << Name;
|
||||||
|
|
||||||
if (printGOT(TM, Subtarget)) {
|
if (shouldPrintPLT(TM, Subtarget)) {
|
||||||
std::string GOTName(TAI->getGlobalPrefix());
|
std::string GOTName(TAI->getGlobalPrefix());
|
||||||
GOTName+="_GLOBAL_OFFSET_TABLE_";
|
GOTName+="_GLOBAL_OFFSET_TABLE_";
|
||||||
if (Name == GOTName)
|
if (Name == GOTName)
|
||||||
@ -646,4 +651,3 @@ void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
|
|||||||
|
|
||||||
// Include the auto-generated portion of the assembly writer.
|
// Include the auto-generated portion of the assembly writer.
|
||||||
#include "X86GenAsmWriter.inc"
|
#include "X86GenAsmWriter.inc"
|
||||||
|
|
||||||
|
11
test/CodeGen/X86/x86-64-pic-1.ll
Normal file
11
test/CodeGen/X86/x86-64-pic-1.ll
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
; RUN: llvm-as < %s | \
|
||||||
|
; RUN: llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
|
||||||
|
; RUN: grep {call f@PLT} %t1
|
||||||
|
|
||||||
|
define void @g() {
|
||||||
|
entry:
|
||||||
|
call void @f( )
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare void @f()
|
13
test/CodeGen/X86/x86-64-pic-10.ll
Normal file
13
test/CodeGen/X86/x86-64-pic-10.ll
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
; RUN: llvm-as < %s | \
|
||||||
|
; RUN: llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
|
||||||
|
; RUN: grep {call g@PLT} %t1
|
||||||
|
|
||||||
|
@g = alias weak i32 ()* @f
|
||||||
|
|
||||||
|
define void @g() {
|
||||||
|
entry:
|
||||||
|
%tmp31 = call i32 @g()
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare extern_weak i32 @f()
|
9
test/CodeGen/X86/x86-64-pic-11.ll
Normal file
9
test/CodeGen/X86/x86-64-pic-11.ll
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
; RUN: llvm-as < %s | \
|
||||||
|
; RUN: llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
|
||||||
|
; RUN: grep {call __fixunsxfti@PLT} %t1
|
||||||
|
|
||||||
|
define i128 @f(x86_fp80 %a) {
|
||||||
|
entry:
|
||||||
|
%tmp78 = fptoui x86_fp80 %a to i128
|
||||||
|
ret i128 %tmp78
|
||||||
|
}
|
12
test/CodeGen/X86/x86-64-pic-2.ll
Normal file
12
test/CodeGen/X86/x86-64-pic-2.ll
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
; RUN: llvm-as < %s | \
|
||||||
|
; RUN: llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
|
||||||
|
; RUN: grep {call f} %t1
|
||||||
|
; RUN: not grep {call f@PLT} %t1
|
||||||
|
|
||||||
|
define void @g() {
|
||||||
|
entry:
|
||||||
|
call void @f( )
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare hidden void @f()
|
15
test/CodeGen/X86/x86-64-pic-3.ll
Normal file
15
test/CodeGen/X86/x86-64-pic-3.ll
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
; RUN: llvm-as < %s | \
|
||||||
|
; RUN: llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
|
||||||
|
; RUN: grep {call f} %t1
|
||||||
|
; RUN: not grep {call f@PLT} %t1
|
||||||
|
|
||||||
|
define void @g() {
|
||||||
|
entry:
|
||||||
|
call void @f( )
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
define internal void @f() {
|
||||||
|
entry:
|
||||||
|
ret void
|
||||||
|
}
|
11
test/CodeGen/X86/x86-64-pic-4.ll
Normal file
11
test/CodeGen/X86/x86-64-pic-4.ll
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
; RUN: llvm-as < %s | \
|
||||||
|
; RUN: llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
|
||||||
|
; RUN: grep {movq a@GOTPCREL(%rip),} %t1
|
||||||
|
|
||||||
|
@a = global i32 0
|
||||||
|
|
||||||
|
define i32 @get_a() {
|
||||||
|
entry:
|
||||||
|
%tmp1 = load i32* @a, align 4
|
||||||
|
ret i32 %tmp1
|
||||||
|
}
|
12
test/CodeGen/X86/x86-64-pic-5.ll
Normal file
12
test/CodeGen/X86/x86-64-pic-5.ll
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
; RUN: llvm-as < %s | \
|
||||||
|
; RUN: llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
|
||||||
|
; RUN: grep {movl a(%rip),} %t1
|
||||||
|
; RUN: not grep GOTPCREL %t1
|
||||||
|
|
||||||
|
@a = hidden global i32 0
|
||||||
|
|
||||||
|
define i32 @get_a() {
|
||||||
|
entry:
|
||||||
|
%tmp1 = load i32* @a, align 4
|
||||||
|
ret i32 %tmp1
|
||||||
|
}
|
12
test/CodeGen/X86/x86-64-pic-6.ll
Normal file
12
test/CodeGen/X86/x86-64-pic-6.ll
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
; RUN: llvm-as < %s | \
|
||||||
|
; RUN: llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
|
||||||
|
; RUN: grep {movl a(%rip),} %t1
|
||||||
|
; RUN: not grep GOTPCREL %t1
|
||||||
|
|
||||||
|
@a = internal global i32 0
|
||||||
|
|
||||||
|
define i32 @get_a() {
|
||||||
|
entry:
|
||||||
|
%tmp1 = load i32* @a, align 4
|
||||||
|
ret i32 %tmp1
|
||||||
|
}
|
10
test/CodeGen/X86/x86-64-pic-7.ll
Normal file
10
test/CodeGen/X86/x86-64-pic-7.ll
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
; RUN: llvm-as < %s | \
|
||||||
|
; RUN: llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
|
||||||
|
; RUN: grep {movq f@GOTPCREL(%rip),} %t1
|
||||||
|
|
||||||
|
define void ()* @g() {
|
||||||
|
entry:
|
||||||
|
ret void ()* @f
|
||||||
|
}
|
||||||
|
|
||||||
|
declare void @f()
|
11
test/CodeGen/X86/x86-64-pic-8.ll
Normal file
11
test/CodeGen/X86/x86-64-pic-8.ll
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
; RUN: llvm-as < %s | \
|
||||||
|
; RUN: llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
|
||||||
|
; RUN: grep {leaq f(%rip),} %t1
|
||||||
|
; RUN: not grep GOTPCREL %t1
|
||||||
|
|
||||||
|
define void ()* @g() {
|
||||||
|
entry:
|
||||||
|
ret void ()* @f
|
||||||
|
}
|
||||||
|
|
||||||
|
declare hidden void @f()
|
14
test/CodeGen/X86/x86-64-pic-9.ll
Normal file
14
test/CodeGen/X86/x86-64-pic-9.ll
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
; RUN: llvm-as < %s | \
|
||||||
|
; RUN: llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
|
||||||
|
; RUN: grep {leaq f(%rip),} %t1
|
||||||
|
; RUN: not grep GOTPCREL %t1
|
||||||
|
|
||||||
|
define void ()* @g() {
|
||||||
|
entry:
|
||||||
|
ret void ()* @f
|
||||||
|
}
|
||||||
|
|
||||||
|
define internal void @f() {
|
||||||
|
entry:
|
||||||
|
ret void
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user