Expand Up
@@ -47,8 +47,11 @@ namespace {
class X86TargetInfo final : public TargetInfo {
public:
X86TargetInfo ();
void writeGotPltEntry (uint8_t *Buf, uint64_t Plt) const override ;
void writePltZeroEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const override ;
void writePltEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const override ;
uint64_t PltEntryAddr, int32_t Index ) const override ;
bool relocNeedsGot (uint32_t Type, const SymbolBody &S) const override ;
bool relocPointsToGot (uint32_t Type) const override ;
bool relocNeedsPlt (uint32_t Type, const SymbolBody &S) const override ;
Expand All
@@ -61,8 +64,11 @@ class X86_64TargetInfo final : public TargetInfo {
public:
X86_64TargetInfo ();
unsigned getPLTRefReloc (unsigned Type) const override ;
void writeGotPltEntry (uint8_t *Buf, uint64_t Plt) const override ;
void writePltZeroEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const override ;
void writePltEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const override ;
uint64_t PltEntryAddr, int32_t Index ) const override ;
bool relocNeedsGot (uint32_t Type, const SymbolBody &S) const override ;
bool relocNeedsPlt (uint32_t Type, const SymbolBody &S) const override ;
void relocateOne (uint8_t *Buf, uint8_t *BufEnd, const void *RelP,
Expand All
@@ -74,8 +80,11 @@ class X86_64TargetInfo final : public TargetInfo {
class PPC64TargetInfo final : public TargetInfo {
public:
PPC64TargetInfo ();
void writeGotPltEntry (uint8_t *Buf, uint64_t Plt) const override ;
void writePltZeroEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const override ;
void writePltEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const override ;
uint64_t PltEntryAddr, int32_t Index ) const override ;
bool relocNeedsGot (uint32_t Type, const SymbolBody &S) const override ;
bool relocNeedsPlt (uint32_t Type, const SymbolBody &S) const override ;
void relocateOne (uint8_t *Buf, uint8_t *BufEnd, const void *RelP,
Expand All
@@ -87,8 +96,11 @@ class PPC64TargetInfo final : public TargetInfo {
class AArch64TargetInfo final : public TargetInfo {
public:
AArch64TargetInfo ();
void writeGotPltEntry (uint8_t *Buf, uint64_t Plt) const override ;
void writePltZeroEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const override ;
void writePltEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const override ;
uint64_t PltEntryAddr, int32_t Index ) const override ;
bool relocNeedsGot (uint32_t Type, const SymbolBody &S) const override ;
bool relocNeedsPlt (uint32_t Type, const SymbolBody &S) const override ;
void relocateOne (uint8_t *Buf, uint8_t *BufEnd, const void *RelP,
Expand All
@@ -99,8 +111,11 @@ class AArch64TargetInfo final : public TargetInfo {
template <class ELFT > class MipsTargetInfo final : public TargetInfo {
public:
MipsTargetInfo ();
void writeGotPltEntry (uint8_t *Buf, uint64_t Plt) const override ;
void writePltZeroEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const override ;
void writePltEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const override ;
uint64_t PltEntryAddr, int32_t Index ) const override ;
bool relocNeedsGot (uint32_t Type, const SymbolBody &S) const override ;
bool relocNeedsPlt (uint32_t Type, const SymbolBody &S) const override ;
void relocateOne (uint8_t *Buf, uint8_t *BufEnd, const void *RelP,
Expand Down
Expand Up
@@ -144,10 +159,15 @@ X86TargetInfo::X86TargetInfo() {
PCRelReloc = R_386_PC32;
GotReloc = R_386_GLOB_DAT;
GotRefReloc = R_386_GOT32;
PltReloc = R_386_JUMP_SLOT;
}
void X86TargetInfo::writeGotPltEntry (uint8_t *Buf, uint64_t Plt) const {}
void X86TargetInfo::writePltZeroEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const {}
void X86TargetInfo::writePltEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const {
uint64_t PltEntryAddr, int32_t Index ) const {
// jmpl *val; nop; nop
const uint8_t Inst[] = {0xff , 0x25 , 0 , 0 , 0 , 0 , 0x90 , 0x90 };
memcpy (Buf, Inst, sizeof (Inst));
Expand Down
Expand Up
@@ -194,19 +214,43 @@ X86_64TargetInfo::X86_64TargetInfo() {
PCRelReloc = R_X86_64_PC32;
GotReloc = R_X86_64_GLOB_DAT;
GotRefReloc = R_X86_64_PC32;
PltReloc = R_X86_64_JUMP_SLOT;
RelativeReloc = R_X86_64_RELATIVE;
LazyRelocations = true ;
PltEntrySize = 16 ;
PltZeroEntrySize = 16 ;
}
void X86_64TargetInfo::writeGotPltEntry (uint8_t *Buf, uint64_t Plt) const {
// Skip 6 bytes of "jmpq *got(%rip)"
write32le (Buf, Plt + 6 );
}
void X86_64TargetInfo::writePltZeroEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const {
const uint8_t PltData[] = {
0xff , 0x35 , 0x00 , 0x00 , 0x00 , 0x00 , // pushq GOT+8(%rip)
0xff , 0x25 , 0x00 , 0x00 , 0x00 , 0x00 , // jmp *GOT+16(%rip)
0x0f , 0x1f , 0x40 , 0x00 // nopl 0x0(rax)
};
memcpy (Buf, PltData, sizeof (PltData));
write32le (Buf + 2 , GotEntryAddr - PltEntryAddr + 2 ); // GOT+8
write32le (Buf + 8 , GotEntryAddr - PltEntryAddr + 4 ); // GOT+16
}
void X86_64TargetInfo::writePltEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const {
// jmpq *val(%rip); nop; nop
const uint8_t Inst[] = {0xff , 0x25 , 0 , 0 , 0 , 0 , 0x90 , 0x90 };
uint64_t PltEntryAddr,
int32_t Index) const {
const uint8_t Inst[] = {
0xff , 0x25 , 0x00 , 0x00 , 0x00 , 0x00 , // jmpq *got(%rip)
0x68 , 0x00 , 0x00 , 0x00 , 0x00 , // pushq <relocation index>
0xe9 , 0x00 , 0x00 , 0x00 , 0x00 // jmpq plt[0]
};
memcpy (Buf, Inst, sizeof (Inst));
uint64_t NextPC = PltEntryAddr + 6 ;
int64_t Delta = GotEntryAddr - NextPC;
assert (isInt<32 >(Delta));
write32le (Buf + 2 , Delta);
write32le (Buf + 2 , GotEntryAddr - PltEntryAddr - 6 );
write32le (Buf + 7 , Index);
write32le (Buf + 12 , -Index * PltEntrySize - PltZeroEntrySize - 16 );
}
bool X86_64TargetInfo::relocNeedsGot (uint32_t Type, const SymbolBody &S) const {
Expand Down
Expand Up
@@ -364,8 +408,11 @@ uint64_t getPPC64TocBase() {
return TocVA + 0x8000 ;
}
void PPC64TargetInfo::writeGotPltEntry (uint8_t *Buf, uint64_t Plt) const {}
void PPC64TargetInfo::writePltZeroEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const {}
void PPC64TargetInfo::writePltEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const {
uint64_t PltEntryAddr, int32_t Index ) const {
uint64_t Off = GotEntryAddr - getPPC64TocBase ();
// FIXME: What we should do, in theory, is get the offset of the function
Expand Down
Expand Up
@@ -548,8 +595,12 @@ AArch64TargetInfo::AArch64TargetInfo() {
// PCRelReloc = FIXME
// GotReloc = FIXME
}
void AArch64TargetInfo::writeGotPltEntry (uint8_t *Buf, uint64_t Plt) const {}
void AArch64TargetInfo::writePltZeroEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const {}
void AArch64TargetInfo::writePltEntry (uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const {}
uint64_t PltEntryAddr, int32_t Index ) const {}
bool AArch64TargetInfo::relocNeedsGot (uint32_t Type,
const SymbolBody &S) const {
return false ;
Expand Down
Expand Up
@@ -629,9 +680,14 @@ template <class ELFT> MipsTargetInfo<ELFT>::MipsTargetInfo() {
PageSize = 65536 ;
}
template <class ELFT >
void MipsTargetInfo<ELFT>::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const {}
template <class ELFT >
void MipsTargetInfo<ELFT>::writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const {}
template <class ELFT >
void MipsTargetInfo<ELFT>::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
uint64_t PltEntryAddr) const {}
uint64_t PltEntryAddr, int32_t Index ) const {}
template <class ELFT >
bool MipsTargetInfo<ELFT>::relocNeedsGot(uint32_t Type,
Expand Down