Fix fixup evaluation when deciding what to relocate with.
The previous logic was to first try without relocations at all
and failing that stop on the first defined symbol.
That was inefficient and incorrect in the case part of the
expression could be simplified and another part could not
(see included test).
We now stop the evaluation when we get to a variable whose value
can change (i.e. is weak).
llvm-svn: 233187
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 0bc17ef..c99a3ee 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -312,6 +312,8 @@
bool InSet,
bool IsPCRel) const override;
+ bool isWeak(const MCSymbolData &SD) const override;
+
void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
void writeSection(MCAssembler &Asm,
const SectionIndexMapTy &SectionIndexMap,
@@ -847,7 +849,7 @@
Fixup.getLoc(), "Cannot represent a difference across sections");
const MCSymbolData &SymBD = Asm.getSymbolData(SymB);
- if (isWeak(SymBD))
+ if (::isWeak(SymBD))
Asm.getContext().FatalError(
Fixup.getLoc(), "Cannot represent a subtraction with a weak symbol");
@@ -1817,12 +1819,16 @@
const MCFragment &FB,
bool InSet,
bool IsPCRel) const {
- if (isWeak(DataA))
+ if (::isWeak(DataA))
return false;
return MCObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(
Asm, DataA, FB,InSet, IsPCRel);
}
+bool ELFObjectWriter::isWeak(const MCSymbolData &SD) const {
+ return ::isWeak(SD);
+}
+
MCObjectWriter *llvm::createELFObjectWriter(MCELFObjectTargetWriter *MOTW,
raw_ostream &OS,
bool IsLittleEndian) {