aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/MC/MCAssembler.h2
-rw-r--r--llvm/include/llvm/MC/MCFixup.h4
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp4
-rw-r--r--llvm/lib/MC/MCAssembler.cpp8
-rw-r--r--llvm/lib/MC/XCOFFObjectWriter.cpp9
5 files changed, 13 insertions, 14 deletions
diff --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h
index 0374412..bfd6375 100644
--- a/llvm/include/llvm/MC/MCAssembler.h
+++ b/llvm/include/llvm/MC/MCAssembler.h
@@ -101,7 +101,7 @@ private:
/// out.
/// \param RecordReloc Record relocation if needed.
/// relocation.
- bool evaluateFixup(const MCFragment &F, const MCFixup &Fixup, MCValue &Target,
+ bool evaluateFixup(const MCFragment &F, MCFixup &Fixup, MCValue &Target,
uint64_t &Value, bool RecordReloc,
MutableArrayRef<char> Contents) const;
diff --git a/llvm/include/llvm/MC/MCFixup.h b/llvm/include/llvm/MC/MCFixup.h
index 7575202..ab2e4718 100644
--- a/llvm/include/llvm/MC/MCFixup.h
+++ b/llvm/include/llvm/MC/MCFixup.h
@@ -73,6 +73,8 @@ class MCFixup {
/// determine how the operand value should be encoded into the instruction.
MCFixupKind Kind = FK_NONE;
+ bool PCRel = false;
+
/// Used by RISC-V style linker relaxation. Whether the fixup is
/// linker-relaxable.
bool LinkerRelaxable = false;
@@ -105,6 +107,8 @@ public:
const MCExpr *getValue() const { return Value; }
+ bool isPCRel() const { return PCRel; }
+ void setPCRel() { PCRel = true; }
bool isLinkerRelaxable() const { return LinkerRelaxable; }
void setLinkerRelaxable() { LinkerRelaxable = true; }
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 3fed77f..0d427b5 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1326,7 +1326,6 @@ bool ELFObjectWriter::checkRelocation(SMLoc Loc, const MCSectionELF *From,
void ELFObjectWriter::recordRelocation(const MCFragment &F,
const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue) {
- MCAsmBackend &Backend = Asm->getBackend();
const MCSectionELF &Section = cast<MCSectionELF>(*F.getParent());
MCContext &Ctx = getContext();
@@ -1337,8 +1336,7 @@ void ELFObjectWriter::recordRelocation(const MCFragment &F,
if (DwoOS && !checkRelocation(Fixup.getLoc(), &Section, SecA))
return;
- bool IsPCRel = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
- MCFixupKindInfo::FKF_IsPCRel;
+ bool IsPCRel = Fixup.isPCRel();
uint64_t FixupOffset = Asm->getFragmentOffset(F) + Fixup.getOffset();
uint64_t Addend = Target.getConstant();
if (auto *RefB = Target.getSubSym()) {
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 98225c0..cc21cf4 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -142,7 +142,7 @@ bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
return true;
}
-bool MCAssembler::evaluateFixup(const MCFragment &F, const MCFixup &Fixup,
+bool MCAssembler::evaluateFixup(const MCFragment &F, MCFixup &Fixup,
MCValue &Target, uint64_t &Value,
bool RecordReloc,
MutableArrayRef<char> Contents) const {
@@ -163,6 +163,7 @@ bool MCAssembler::evaluateFixup(const MCFragment &F, const MCFixup &Fixup,
bool IsResolved = false;
unsigned FixupFlags = getBackend().getFixupKindInfo(Fixup.getKind()).Flags;
+ bool IsPCRel = FixupFlags & MCFixupKindInfo::FKF_IsPCRel;
if (FixupFlags & MCFixupKindInfo::FKF_IsTarget) {
IsResolved = getBackend().evaluateTargetFixup(Fixup, Target, Value);
} else {
@@ -174,7 +175,6 @@ bool MCAssembler::evaluateFixup(const MCFragment &F, const MCFixup &Fixup,
if (Sub && Sub->isDefined())
Value -= getSymbolOffset(*Sub);
- bool IsPCRel = FixupFlags & MCFixupKindInfo::FKF_IsPCRel;
bool ShouldAlignPC =
FixupFlags & MCFixupKindInfo::FKF_IsAlignedDownTo32Bits;
if (IsPCRel) {
@@ -202,6 +202,8 @@ bool MCAssembler::evaluateFixup(const MCFragment &F, const MCFixup &Fixup,
if (IsResolved && mc::isRelocRelocation(Fixup.getKind()))
IsResolved = false;
+ if (IsPCRel)
+ Fixup.setPCRel();
getBackend().applyFixup(F, Fixup, Target, Contents, Value, IsResolved);
return true;
}
@@ -875,7 +877,7 @@ void MCAssembler::layout() {
// Process fragments with fixups here.
if (auto *F = dyn_cast<MCEncodedFragment>(&Frag)) {
auto Contents = F->getContents();
- for (const MCFixup &Fixup : F->getFixups()) {
+ for (MCFixup &Fixup : F->getFixups()) {
uint64_t FixedValue;
MCValue Target;
evaluateFixup(Frag, Fixup, Target, FixedValue,
diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index ddb2ca8..bfc8c50 100644
--- a/llvm/lib/MC/XCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -686,15 +686,10 @@ void XCOFFWriter::recordRelocation(const MCFragment &F, const MCFixup &Fixup,
};
const MCSymbol *const SymA = Target.getAddSym();
-
- MCAsmBackend &Backend = Asm->getBackend();
- bool IsPCRel = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
- MCFixupKindInfo::FKF_IsPCRel;
-
uint8_t Type;
uint8_t SignAndSize;
- std::tie(Type, SignAndSize) =
- TargetObjectWriter->getRelocTypeAndSignSize(Target, Fixup, IsPCRel);
+ std::tie(Type, SignAndSize) = TargetObjectWriter->getRelocTypeAndSignSize(
+ Target, Fixup, Fixup.isPCRel());
const MCSectionXCOFF *SymASec = getContainingCsect(cast<MCSymbolXCOFF>(SymA));
assert(SectionMap.contains(SymASec) &&