forked from OSchip/llvm-project
ARM: Share applyFixup between ELF and Darwin.
The implementations already diverged a bit, merge them back together. llvm-svn: 168542
This commit is contained in:
parent
dd76a93af5
commit
07ea85a5e6
|
@ -114,6 +114,10 @@ public:
|
|||
MCValue &Target, uint64_t &Value,
|
||||
bool &IsResolved);
|
||||
|
||||
|
||||
void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
|
||||
uint64_t Value) const;
|
||||
|
||||
bool mayNeedRelaxation(const MCInst &Inst) const;
|
||||
|
||||
bool fixupNeedsRelaxation(const MCFixup &Fixup,
|
||||
|
@ -552,65 +556,6 @@ void ARMAsmBackend::processFixupValue(const MCAssembler &Asm,
|
|||
(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.
|
||||
static unsigned getFixupKindNumBytes(unsigned 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 NumBytes = getFixupKindNumBytes(Fixup.getKind());
|
||||
Value = adjustFixupValue(Fixup, Value);
|
||||
|
@ -668,12 +613,50 @@ void DarwinARMAsmBackend::applyFixup(const MCFixup &Fixup, char *Data,
|
|||
unsigned Offset = Fixup.getOffset();
|
||||
assert(Offset + NumBytes <= DataSize && "Invalid fixup offset!");
|
||||
|
||||
// For each byte of the fragment that the fixup touches, mask in the
|
||||
// bits from the fixup value.
|
||||
// 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);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
MCAsmBackend *llvm::createARMAsmBackend(const Target &T, StringRef TT, StringRef CPU) {
|
||||
|
|
Loading…
Reference in New Issue