mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-12 07:37:34 +00:00
ELF: Simplify the rel/rela implementation.
Now the rela class inherits from rel and just adds the addend. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240790 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
875007d3c4
commit
b65669cdde
@ -305,10 +305,10 @@ struct Elf_Dyn_Impl : Elf_Dyn_Base<ELFT> {
|
||||
};
|
||||
|
||||
// Elf_Rel: Elf Relocation
|
||||
template <class ELFT, bool isRela> struct Elf_Rel_Base;
|
||||
template <class ELFT, bool isRela> struct Elf_Rel_Impl;
|
||||
|
||||
template <endianness TargetEndianness>
|
||||
struct Elf_Rel_Base<ELFType<TargetEndianness, false>, false> {
|
||||
struct Elf_Rel_Impl<ELFType<TargetEndianness, false>, false> {
|
||||
LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
|
||||
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
|
||||
Elf_Word r_info; // Symbol table index and type of relocation to apply
|
||||
@ -321,10 +321,35 @@ struct Elf_Rel_Base<ELFType<TargetEndianness, false>, false> {
|
||||
assert(!IsMips64EL);
|
||||
r_info = R;
|
||||
}
|
||||
|
||||
// These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
|
||||
// and ELF32_R_INFO macros defined in the ELF specification:
|
||||
uint32_t getSymbol(bool isMips64EL) const {
|
||||
return this->getRInfo(isMips64EL) >> 8;
|
||||
}
|
||||
unsigned char getType(bool isMips64EL) const {
|
||||
return (unsigned char)(this->getRInfo(isMips64EL) & 0x0ff);
|
||||
}
|
||||
void setSymbol(uint32_t s, bool IsMips64EL) {
|
||||
setSymbolAndType(s, getType(), IsMips64EL);
|
||||
}
|
||||
void setType(unsigned char t, bool IsMips64EL) {
|
||||
setSymbolAndType(getSymbol(), t, IsMips64EL);
|
||||
}
|
||||
void setSymbolAndType(uint32_t s, unsigned char t, bool IsMips64EL) {
|
||||
this->setRInfo((s << 8) + t, IsMips64EL);
|
||||
}
|
||||
};
|
||||
|
||||
template <endianness TargetEndianness>
|
||||
struct Elf_Rel_Base<ELFType<TargetEndianness, true>, false> {
|
||||
struct Elf_Rel_Impl<ELFType<TargetEndianness, false>, true>
|
||||
: public Elf_Rel_Impl<ELFType<TargetEndianness, false>, false> {
|
||||
LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
|
||||
Elf_Sword r_addend; // Compute value for relocatable field by adding this
|
||||
};
|
||||
|
||||
template <endianness TargetEndianness>
|
||||
struct Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> {
|
||||
LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
|
||||
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
|
||||
Elf_Xword r_info; // Symbol table index and type of relocation to apply
|
||||
@ -346,57 +371,6 @@ struct Elf_Rel_Base<ELFType<TargetEndianness, true>, false> {
|
||||
else
|
||||
r_info = R;
|
||||
}
|
||||
};
|
||||
|
||||
template <endianness TargetEndianness>
|
||||
struct Elf_Rel_Base<ELFType<TargetEndianness, false>, true> {
|
||||
LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
|
||||
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
|
||||
Elf_Word r_info; // Symbol table index and type of relocation to apply
|
||||
Elf_Sword r_addend; // Compute value for relocatable field by adding this
|
||||
|
||||
uint32_t getRInfo(bool isMips64EL) const {
|
||||
assert(!isMips64EL);
|
||||
return r_info;
|
||||
}
|
||||
void setRInfo(uint32_t R, bool IsMips64EL) {
|
||||
assert(!IsMips64EL);
|
||||
r_info = R;
|
||||
}
|
||||
};
|
||||
|
||||
template <endianness TargetEndianness>
|
||||
struct Elf_Rel_Base<ELFType<TargetEndianness, true>, true> {
|
||||
LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
|
||||
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
|
||||
Elf_Xword r_info; // Symbol table index and type of relocation to apply
|
||||
Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
|
||||
|
||||
uint64_t getRInfo(bool isMips64EL) const {
|
||||
// Mips64 little endian has a "special" encoding of r_info. Instead of one
|
||||
// 64 bit little endian number, it is a little endian 32 bit number followed
|
||||
// by a 32 bit big endian number.
|
||||
uint64_t t = r_info;
|
||||
if (!isMips64EL)
|
||||
return t;
|
||||
return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
|
||||
((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
|
||||
}
|
||||
void setRInfo(uint64_t R, bool IsMips64EL) {
|
||||
if (IsMips64EL)
|
||||
r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
|
||||
((R & 0x0000ff00) << 40) | ((R & 0x000000ff) << 56);
|
||||
else
|
||||
r_info = R;
|
||||
}
|
||||
};
|
||||
|
||||
template <class ELFT, bool isRela> struct Elf_Rel_Impl;
|
||||
|
||||
template <endianness TargetEndianness, bool isRela>
|
||||
struct Elf_Rel_Impl<ELFType<TargetEndianness, true>, isRela>
|
||||
: Elf_Rel_Base<ELFType<TargetEndianness, true>, isRela> {
|
||||
LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
|
||||
|
||||
// These accessors and mutators correspond to the ELF64_R_SYM, ELF64_R_TYPE,
|
||||
// and ELF64_R_INFO macros defined in the ELF specification:
|
||||
@ -417,28 +391,11 @@ struct Elf_Rel_Impl<ELFType<TargetEndianness, true>, isRela>
|
||||
}
|
||||
};
|
||||
|
||||
template <endianness TargetEndianness, bool isRela>
|
||||
struct Elf_Rel_Impl<ELFType<TargetEndianness, false>, isRela>
|
||||
: Elf_Rel_Base<ELFType<TargetEndianness, false>, isRela> {
|
||||
LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
|
||||
|
||||
// These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
|
||||
// and ELF32_R_INFO macros defined in the ELF specification:
|
||||
uint32_t getSymbol(bool isMips64EL) const {
|
||||
return this->getRInfo(isMips64EL) >> 8;
|
||||
}
|
||||
unsigned char getType(bool isMips64EL) const {
|
||||
return (unsigned char)(this->getRInfo(isMips64EL) & 0x0ff);
|
||||
}
|
||||
void setSymbol(uint32_t s, bool IsMips64EL) {
|
||||
setSymbolAndType(s, getType(), IsMips64EL);
|
||||
}
|
||||
void setType(unsigned char t, bool IsMips64EL) {
|
||||
setSymbolAndType(getSymbol(), t, IsMips64EL);
|
||||
}
|
||||
void setSymbolAndType(uint32_t s, unsigned char t, bool IsMips64EL) {
|
||||
this->setRInfo((s << 8) + t, IsMips64EL);
|
||||
}
|
||||
template <endianness TargetEndianness>
|
||||
struct Elf_Rel_Impl<ELFType<TargetEndianness, true>, true>
|
||||
: public Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> {
|
||||
LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
|
||||
Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
|
||||
};
|
||||
|
||||
template <class ELFT>
|
||||
|
Loading…
x
Reference in New Issue
Block a user