mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-30 19:35:54 +00:00
Avoid runtime type checks.
In most cases the relocation type implies the object word size and endianness. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181515 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6ce62dc1d0
commit
4fcf82f316
@ -124,12 +124,37 @@ private:
|
|||||||
StringRef FileFormat;
|
StringRef FileFormat;
|
||||||
bool HasError;
|
bool HasError;
|
||||||
|
|
||||||
int64_t getAddend(RelocationRef R) {
|
int64_t getAddend32LE(RelocationRef R) {
|
||||||
|
const ELF32LEObjectFile *Obj = cast<ELF32LEObjectFile>(R.getObjectFile());
|
||||||
|
DataRefImpl DRI = R.getRawDataRefImpl();
|
||||||
int64_t Addend;
|
int64_t Addend;
|
||||||
getELFRelocationAddend(R, Addend);
|
Obj->getRelocationAddend(DRI, Addend);
|
||||||
return Addend;
|
return Addend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t getAddend64LE(RelocationRef R) {
|
||||||
|
const ELF64LEObjectFile *Obj = cast<ELF64LEObjectFile>(R.getObjectFile());
|
||||||
|
DataRefImpl DRI = R.getRawDataRefImpl();
|
||||||
|
int64_t Addend;
|
||||||
|
Obj->getRelocationAddend(DRI, Addend);
|
||||||
|
return Addend;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t getAddend32BE(RelocationRef R) {
|
||||||
|
const ELF32BEObjectFile *Obj = cast<ELF32BEObjectFile>(R.getObjectFile());
|
||||||
|
DataRefImpl DRI = R.getRawDataRefImpl();
|
||||||
|
int64_t Addend;
|
||||||
|
Obj->getRelocationAddend(DRI, Addend);
|
||||||
|
return Addend;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t getAddend64BE(RelocationRef R) {
|
||||||
|
const ELF64BEObjectFile *Obj = cast<ELF64BEObjectFile>(R.getObjectFile());
|
||||||
|
DataRefImpl DRI = R.getRawDataRefImpl();
|
||||||
|
int64_t Addend;
|
||||||
|
Obj->getRelocationAddend(DRI, Addend);
|
||||||
|
return Addend;
|
||||||
|
}
|
||||||
/// Operations
|
/// Operations
|
||||||
|
|
||||||
/// 386-ELF
|
/// 386-ELF
|
||||||
@ -140,13 +165,13 @@ private:
|
|||||||
// Ideally the Addend here will be the addend in the data for
|
// Ideally the Addend here will be the addend in the data for
|
||||||
// the relocation. It's not actually the case for Rel relocations.
|
// the relocation. It's not actually the case for Rel relocations.
|
||||||
RelocToApply visitELF_386_32(RelocationRef R, uint64_t Value) {
|
RelocToApply visitELF_386_32(RelocationRef R, uint64_t Value) {
|
||||||
int64_t Addend = getAddend(R);
|
int64_t Addend = getAddend32LE(R);
|
||||||
return RelocToApply(Value + Addend, 4);
|
return RelocToApply(Value + Addend, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
RelocToApply visitELF_386_PC32(RelocationRef R, uint64_t Value,
|
RelocToApply visitELF_386_PC32(RelocationRef R, uint64_t Value,
|
||||||
uint64_t SecAddr) {
|
uint64_t SecAddr) {
|
||||||
int64_t Addend = getAddend(R);
|
int64_t Addend = getAddend32LE(R);
|
||||||
uint64_t Address;
|
uint64_t Address;
|
||||||
R.getOffset(Address);
|
R.getOffset(Address);
|
||||||
return RelocToApply(Value + Addend - Address, 4);
|
return RelocToApply(Value + Addend - Address, 4);
|
||||||
@ -157,44 +182,45 @@ private:
|
|||||||
return RelocToApply(0, 0);
|
return RelocToApply(0, 0);
|
||||||
}
|
}
|
||||||
RelocToApply visitELF_X86_64_64(RelocationRef R, uint64_t Value) {
|
RelocToApply visitELF_X86_64_64(RelocationRef R, uint64_t Value) {
|
||||||
int64_t Addend = getAddend(R);
|
int64_t Addend = getAddend64LE(R);
|
||||||
return RelocToApply(Value + Addend, 8);
|
return RelocToApply(Value + Addend, 8);
|
||||||
}
|
}
|
||||||
RelocToApply visitELF_X86_64_PC32(RelocationRef R, uint64_t Value,
|
RelocToApply visitELF_X86_64_PC32(RelocationRef R, uint64_t Value,
|
||||||
uint64_t SecAddr) {
|
uint64_t SecAddr) {
|
||||||
int64_t Addend = getAddend(R);
|
int64_t Addend = getAddend64LE(R);
|
||||||
uint64_t Address;
|
uint64_t Address;
|
||||||
R.getOffset(Address);
|
R.getOffset(Address);
|
||||||
return RelocToApply(Value + Addend - Address, 4);
|
return RelocToApply(Value + Addend - Address, 4);
|
||||||
}
|
}
|
||||||
RelocToApply visitELF_X86_64_32(RelocationRef R, uint64_t Value) {
|
RelocToApply visitELF_X86_64_32(RelocationRef R, uint64_t Value) {
|
||||||
int64_t Addend = getAddend(R);
|
int64_t Addend = getAddend64LE(R);
|
||||||
uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
|
uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
|
||||||
return RelocToApply(Res, 4);
|
return RelocToApply(Res, 4);
|
||||||
}
|
}
|
||||||
RelocToApply visitELF_X86_64_32S(RelocationRef R, uint64_t Value) {
|
RelocToApply visitELF_X86_64_32S(RelocationRef R, uint64_t Value) {
|
||||||
int64_t Addend = getAddend(R);
|
int64_t Addend = getAddend64LE(R);
|
||||||
int32_t Res = (Value + Addend) & 0xFFFFFFFF;
|
int32_t Res = (Value + Addend) & 0xFFFFFFFF;
|
||||||
return RelocToApply(Res, 4);
|
return RelocToApply(Res, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// PPC64 ELF
|
/// PPC64 ELF
|
||||||
RelocToApply visitELF_PPC64_ADDR32(RelocationRef R, uint64_t Value) {
|
RelocToApply visitELF_PPC64_ADDR32(RelocationRef R, uint64_t Value) {
|
||||||
int64_t Addend = getAddend(R);
|
int64_t Addend = getAddend64BE(R);
|
||||||
uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
|
uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
|
||||||
return RelocToApply(Res, 4);
|
return RelocToApply(Res, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// MIPS ELF
|
/// MIPS ELF
|
||||||
RelocToApply visitELF_MIPS_32(RelocationRef R, uint64_t Value) {
|
RelocToApply visitELF_MIPS_32(RelocationRef R, uint64_t Value) {
|
||||||
int64_t Addend = getAddend(R);
|
int64_t Addend;
|
||||||
|
getELFRelocationAddend(R, Addend);
|
||||||
uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
|
uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
|
||||||
return RelocToApply(Res, 4);
|
return RelocToApply(Res, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AArch64 ELF
|
// AArch64 ELF
|
||||||
RelocToApply visitELF_AARCH64_ABS32(RelocationRef R, uint64_t Value) {
|
RelocToApply visitELF_AARCH64_ABS32(RelocationRef R, uint64_t Value) {
|
||||||
int64_t Addend = getAddend(R);
|
int64_t Addend = getAddend64LE(R);
|
||||||
int64_t Res = Value + Addend;
|
int64_t Res = Value + Addend;
|
||||||
|
|
||||||
// Overflow check allows for both signed and unsigned interpretation.
|
// Overflow check allows for both signed and unsigned interpretation.
|
||||||
@ -205,13 +231,13 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
RelocToApply visitELF_AARCH64_ABS64(RelocationRef R, uint64_t Value) {
|
RelocToApply visitELF_AARCH64_ABS64(RelocationRef R, uint64_t Value) {
|
||||||
int64_t Addend = getAddend(R);
|
int64_t Addend = getAddend64LE(R);
|
||||||
return RelocToApply(Value + Addend, 8);
|
return RelocToApply(Value + Addend, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SystemZ ELF
|
// SystemZ ELF
|
||||||
RelocToApply visitELF_390_32(RelocationRef R, uint64_t Value) {
|
RelocToApply visitELF_390_32(RelocationRef R, uint64_t Value) {
|
||||||
int64_t Addend = getAddend(R);
|
int64_t Addend = getAddend64BE(R);
|
||||||
int64_t Res = Value + Addend;
|
int64_t Res = Value + Addend;
|
||||||
|
|
||||||
// Overflow check allows for both signed and unsigned interpretation.
|
// Overflow check allows for both signed and unsigned interpretation.
|
||||||
@ -222,7 +248,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
RelocToApply visitELF_390_64(RelocationRef R, uint64_t Value) {
|
RelocToApply visitELF_390_64(RelocationRef R, uint64_t Value) {
|
||||||
int64_t Addend = getAddend(R);
|
int64_t Addend = getAddend64BE(R);
|
||||||
return RelocToApply(Value + Addend, 8);
|
return RelocToApply(Value + Addend, 8);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user