mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 16:17:17 +00:00
ARM: Share applyFixup between ELF and Darwin.
The implementations already diverged a bit, merge them back together. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168542 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -114,6 +114,10 @@ public:
|
|||||||
MCValue &Target, uint64_t &Value,
|
MCValue &Target, uint64_t &Value,
|
||||||
bool &IsResolved);
|
bool &IsResolved);
|
||||||
|
|
||||||
|
|
||||||
|
void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
|
||||||
|
uint64_t Value) const;
|
||||||
|
|
||||||
bool mayNeedRelaxation(const MCInst &Inst) const;
|
bool mayNeedRelaxation(const MCInst &Inst) const;
|
||||||
|
|
||||||
bool fixupNeedsRelaxation(const MCFixup &Fixup,
|
bool fixupNeedsRelaxation(const MCFixup &Fixup,
|
||||||
@@ -552,65 +556,6 @@ void ARMAsmBackend::processFixupValue(const MCAssembler &Asm,
|
|||||||
(void)adjustFixupValue(Fixup, Value, &Asm.getContext());
|
(void)adjustFixupValue(Fixup, Value, &Asm.getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// FIXME: This should be in a separate file.
|
|
||||||
// ELF is an ELF of course...
|
|
||||||
class ELFARMAsmBackend : public ARMAsmBackend {
|
|
||||||
public:
|
|
||||||
uint8_t OSABI;
|
|
||||||
ELFARMAsmBackend(const Target &T, const StringRef TT,
|
|
||||||
uint8_t _OSABI)
|
|
||||||
: ARMAsmBackend(T, TT), OSABI(_OSABI) { }
|
|
||||||
|
|
||||||
void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
|
|
||||||
uint64_t Value) const;
|
|
||||||
|
|
||||||
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
|
|
||||||
return createARMELFObjectWriter(OS, OSABI);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// FIXME: Raise this to share code between Darwin and ELF.
|
|
||||||
void ELFARMAsmBackend::applyFixup(const MCFixup &Fixup, char *Data,
|
|
||||||
unsigned DataSize, uint64_t Value) const {
|
|
||||||
unsigned NumBytes = 4; // FIXME: 2 for Thumb
|
|
||||||
Value = adjustFixupValue(Fixup, Value);
|
|
||||||
if (!Value) return; // Doesn't change encoding.
|
|
||||||
|
|
||||||
unsigned Offset = Fixup.getOffset();
|
|
||||||
|
|
||||||
// For each byte of the fragment that the fixup touches, mask in the bits from
|
|
||||||
// the fixup value. The Value has been "split up" into the appropriate
|
|
||||||
// bitfields above.
|
|
||||||
for (unsigned i = 0; i != NumBytes; ++i)
|
|
||||||
Data[Offset + i] |= uint8_t((Value >> (i * 8)) & 0xff);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: This should be in a separate file.
|
|
||||||
class DarwinARMAsmBackend : public ARMAsmBackend {
|
|
||||||
public:
|
|
||||||
const object::mach::CPUSubtypeARM Subtype;
|
|
||||||
DarwinARMAsmBackend(const Target &T, const StringRef TT,
|
|
||||||
object::mach::CPUSubtypeARM st)
|
|
||||||
: ARMAsmBackend(T, TT), Subtype(st) {
|
|
||||||
HasDataInCodeSupport = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
|
|
||||||
return createARMMachObjectWriter(OS, /*Is64Bit=*/false,
|
|
||||||
object::mach::CTM_ARM,
|
|
||||||
Subtype);
|
|
||||||
}
|
|
||||||
|
|
||||||
void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
|
|
||||||
uint64_t Value) const;
|
|
||||||
|
|
||||||
virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// getFixupKindNumBytes - The number of bytes the fixup may change.
|
/// getFixupKindNumBytes - The number of bytes the fixup may change.
|
||||||
static unsigned getFixupKindNumBytes(unsigned Kind) {
|
static unsigned getFixupKindNumBytes(unsigned Kind) {
|
||||||
switch (Kind) {
|
switch (Kind) {
|
||||||
@@ -659,7 +604,7 @@ static unsigned getFixupKindNumBytes(unsigned Kind) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DarwinARMAsmBackend::applyFixup(const MCFixup &Fixup, char *Data,
|
void ARMAsmBackend::applyFixup(const MCFixup &Fixup, char *Data,
|
||||||
unsigned DataSize, uint64_t Value) const {
|
unsigned DataSize, uint64_t Value) const {
|
||||||
unsigned NumBytes = getFixupKindNumBytes(Fixup.getKind());
|
unsigned NumBytes = getFixupKindNumBytes(Fixup.getKind());
|
||||||
Value = adjustFixupValue(Fixup, Value);
|
Value = adjustFixupValue(Fixup, Value);
|
||||||
@@ -668,12 +613,50 @@ void DarwinARMAsmBackend::applyFixup(const MCFixup &Fixup, char *Data,
|
|||||||
unsigned Offset = Fixup.getOffset();
|
unsigned Offset = Fixup.getOffset();
|
||||||
assert(Offset + NumBytes <= DataSize && "Invalid fixup offset!");
|
assert(Offset + NumBytes <= DataSize && "Invalid fixup offset!");
|
||||||
|
|
||||||
// For each byte of the fragment that the fixup touches, mask in the
|
// For each byte of the fragment that the fixup touches, mask in the bits from
|
||||||
// bits from the fixup value.
|
// the fixup value. The Value has been "split up" into the appropriate
|
||||||
|
// bitfields above.
|
||||||
for (unsigned i = 0; i != NumBytes; ++i)
|
for (unsigned i = 0; i != NumBytes; ++i)
|
||||||
Data[Offset + i] |= uint8_t((Value >> (i * 8)) & 0xff);
|
Data[Offset + i] |= uint8_t((Value >> (i * 8)) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// FIXME: This should be in a separate file.
|
||||||
|
// ELF is an ELF of course...
|
||||||
|
class ELFARMAsmBackend : public ARMAsmBackend {
|
||||||
|
public:
|
||||||
|
uint8_t OSABI;
|
||||||
|
ELFARMAsmBackend(const Target &T, const StringRef TT,
|
||||||
|
uint8_t _OSABI)
|
||||||
|
: ARMAsmBackend(T, TT), OSABI(_OSABI) { }
|
||||||
|
|
||||||
|
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
|
||||||
|
return createARMELFObjectWriter(OS, OSABI);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// FIXME: This should be in a separate file.
|
||||||
|
class DarwinARMAsmBackend : public ARMAsmBackend {
|
||||||
|
public:
|
||||||
|
const object::mach::CPUSubtypeARM Subtype;
|
||||||
|
DarwinARMAsmBackend(const Target &T, const StringRef TT,
|
||||||
|
object::mach::CPUSubtypeARM st)
|
||||||
|
: ARMAsmBackend(T, TT), Subtype(st) {
|
||||||
|
HasDataInCodeSupport = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
|
||||||
|
return createARMMachObjectWriter(OS, /*Is64Bit=*/false,
|
||||||
|
object::mach::CTM_ARM,
|
||||||
|
Subtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
MCAsmBackend *llvm::createARMAsmBackend(const Target &T, StringRef TT, StringRef CPU) {
|
MCAsmBackend *llvm::createARMAsmBackend(const Target &T, StringRef TT, StringRef CPU) {
|
||||||
|
Reference in New Issue
Block a user