mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-28 21:34:23 +00:00
Add a hook in MCELFObjectTargetWriter to allow targets to sort relocation
entries in the relocation table before they are written out to the file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153345 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6fedb3c401
commit
00ca888ccc
@ -13,8 +13,35 @@
|
|||||||
#include "llvm/MC/MCObjectWriter.h"
|
#include "llvm/MC/MCObjectWriter.h"
|
||||||
#include "llvm/Support/DataTypes.h"
|
#include "llvm/Support/DataTypes.h"
|
||||||
#include "llvm/Support/ELF.h"
|
#include "llvm/Support/ELF.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
/// @name Relocation Data
|
||||||
|
/// @{
|
||||||
|
|
||||||
|
struct ELFRelocationEntry {
|
||||||
|
// Make these big enough for both 32-bit and 64-bit
|
||||||
|
uint64_t r_offset;
|
||||||
|
int Index;
|
||||||
|
unsigned Type;
|
||||||
|
const MCSymbol *Symbol;
|
||||||
|
uint64_t r_addend;
|
||||||
|
const MCFixup *Fixup;
|
||||||
|
|
||||||
|
ELFRelocationEntry()
|
||||||
|
: r_offset(0), Index(0), Type(0), Symbol(0), r_addend(0), Fixup(0) {}
|
||||||
|
|
||||||
|
ELFRelocationEntry(uint64_t RelocOffset, int Idx, unsigned RelType,
|
||||||
|
const MCSymbol *Sym, uint64_t Addend, const MCFixup &Fixup)
|
||||||
|
: r_offset(RelocOffset), Index(Idx), Type(RelType), Symbol(Sym),
|
||||||
|
r_addend(Addend), Fixup(&Fixup) {}
|
||||||
|
|
||||||
|
// Support lexicographic sorting.
|
||||||
|
bool operator<(const ELFRelocationEntry &RE) const {
|
||||||
|
return RE.r_offset < r_offset;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class MCELFObjectTargetWriter {
|
class MCELFObjectTargetWriter {
|
||||||
const uint8_t OSABI;
|
const uint8_t OSABI;
|
||||||
const uint16_t EMachine;
|
const uint16_t EMachine;
|
||||||
@ -52,6 +79,8 @@ public:
|
|||||||
virtual void adjustFixupOffset(const MCFixup &Fixup,
|
virtual void adjustFixupOffset(const MCFixup &Fixup,
|
||||||
uint64_t &RelocOffset);
|
uint64_t &RelocOffset);
|
||||||
|
|
||||||
|
virtual void sortRelocs(const MCAssembler &Asm,
|
||||||
|
std::vector<ELFRelocationEntry> &Relocs);
|
||||||
|
|
||||||
/// @name Accessors
|
/// @name Accessors
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -84,32 +84,6 @@ class ELFObjectWriter : public MCObjectWriter {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @name Relocation Data
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
struct ELFRelocationEntry {
|
|
||||||
// Make these big enough for both 32-bit and 64-bit
|
|
||||||
uint64_t r_offset;
|
|
||||||
int Index;
|
|
||||||
unsigned Type;
|
|
||||||
const MCSymbol *Symbol;
|
|
||||||
uint64_t r_addend;
|
|
||||||
|
|
||||||
ELFRelocationEntry()
|
|
||||||
: r_offset(0), Index(0), Type(0), Symbol(0), r_addend(0) {}
|
|
||||||
|
|
||||||
ELFRelocationEntry(uint64_t RelocOffset, int Idx,
|
|
||||||
unsigned RelType, const MCSymbol *Sym,
|
|
||||||
uint64_t Addend)
|
|
||||||
: r_offset(RelocOffset), Index(Idx), Type(RelType),
|
|
||||||
Symbol(Sym), r_addend(Addend) {}
|
|
||||||
|
|
||||||
// Support lexicographic sorting.
|
|
||||||
bool operator<(const ELFRelocationEntry &RE) const {
|
|
||||||
return RE.r_offset < r_offset;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The target specific ELF writer instance.
|
/// The target specific ELF writer instance.
|
||||||
llvm::OwningPtr<MCELFObjectTargetWriter> TargetObjectWriter;
|
llvm::OwningPtr<MCELFObjectTargetWriter> TargetObjectWriter;
|
||||||
|
|
||||||
@ -786,7 +760,7 @@ void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
|||||||
else
|
else
|
||||||
assert(isInt<32>(Addend));
|
assert(isInt<32>(Addend));
|
||||||
|
|
||||||
ELFRelocationEntry ERE(RelocOffset, Index, Type, RelocSymbol, Addend);
|
ELFRelocationEntry ERE(RelocOffset, Index, Type, RelocSymbol, Addend, Fixup);
|
||||||
Relocations[Fragment->getParent()].push_back(ERE);
|
Relocations[Fragment->getParent()].push_back(ERE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1072,8 +1046,10 @@ void ELFObjectWriter::WriteRelocationsFragment(const MCAssembler &Asm,
|
|||||||
MCDataFragment *F,
|
MCDataFragment *F,
|
||||||
const MCSectionData *SD) {
|
const MCSectionData *SD) {
|
||||||
std::vector<ELFRelocationEntry> &Relocs = Relocations[SD];
|
std::vector<ELFRelocationEntry> &Relocs = Relocations[SD];
|
||||||
// sort by the r_offset just like gnu as does
|
|
||||||
array_pod_sort(Relocs.begin(), Relocs.end());
|
// Sort the relocation entries. Most targets just sort by r_offset, but some
|
||||||
|
// (e.g., MIPS) have additional constraints.
|
||||||
|
TargetObjectWriter->sortRelocs(Asm, Relocs);
|
||||||
|
|
||||||
for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
|
||||||
ELFRelocationEntry entry = Relocs[e - i - 1];
|
ELFRelocationEntry entry = Relocs[e - i - 1];
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/MC/MCELFObjectWriter.h"
|
#include "llvm/MC/MCELFObjectWriter.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -36,3 +37,10 @@ const MCSymbol *MCELFObjectTargetWriter::ExplicitRelSym(const MCAssembler &Asm,
|
|||||||
void MCELFObjectTargetWriter::adjustFixupOffset(const MCFixup &Fixup,
|
void MCELFObjectTargetWriter::adjustFixupOffset(const MCFixup &Fixup,
|
||||||
uint64_t &RelocOffset) {
|
uint64_t &RelocOffset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MCELFObjectTargetWriter::sortRelocs(const MCAssembler &Asm,
|
||||||
|
std::vector<ELFRelocationEntry> &Relocs) {
|
||||||
|
// Sort by the r_offset, just like gnu as does.
|
||||||
|
array_pod_sort(Relocs.begin(), Relocs.end());
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user