aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MC/ELFObjectWriter.cpp')
-rw-r--r--lib/MC/ELFObjectWriter.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp
index 4819905..c99a3ee 100644
--- a/lib/MC/ELFObjectWriter.cpp
+++ b/lib/MC/ELFObjectWriter.cpp
@@ -185,11 +185,25 @@ class ELFObjectWriter : public MCObjectWriter {
}
public:
- ELFObjectWriter(MCELFObjectTargetWriter *MOTW, raw_ostream &_OS,
+ ELFObjectWriter(MCELFObjectTargetWriter *MOTW, raw_ostream &OS,
bool IsLittleEndian)
- : MCObjectWriter(_OS, IsLittleEndian), FWriter(IsLittleEndian),
+ : MCObjectWriter(OS, IsLittleEndian), FWriter(IsLittleEndian),
TargetObjectWriter(MOTW), NeedsGOT(false) {}
+ void reset() override {
+ UsedInReloc.clear();
+ WeakrefUsedInReloc.clear();
+ Renames.clear();
+ Relocations.clear();
+ ShStrTabBuilder.clear();
+ StrTabBuilder.clear();
+ FileSymbolData.clear();
+ LocalSymbolData.clear();
+ ExternalSymbolData.clear();
+ UndefinedSymbolData.clear();
+ MCObjectWriter::reset();
+ }
+
virtual ~ELFObjectWriter();
void WriteWord(uint64_t W) {
@@ -298,6 +312,8 @@ class ELFObjectWriter : public MCObjectWriter {
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,
@@ -789,6 +805,10 @@ static const MCSymbol *getWeakRef(const MCSymbolRefExpr &Ref) {
return nullptr;
}
+static bool isWeak(const MCSymbolData &D) {
+ return D.getFlags() & ELF_STB_Weak || MCELF::GetType(D) == ELF::STT_GNU_IFUNC;
+}
+
void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
const MCAsmLayout &Layout,
const MCFragment *Fragment,
@@ -829,6 +849,10 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
Fixup.getLoc(), "Cannot represent a difference across sections");
const MCSymbolData &SymBD = Asm.getSymbolData(SymB);
+ if (::isWeak(SymBD))
+ Asm.getContext().FatalError(
+ Fixup.getLoc(), "Cannot represent a subtraction with a weak symbol");
+
uint64_t SymBOffset = Layout.getSymbolOffset(&SymBD);
uint64_t K = SymBOffset - FixupOffset;
IsPCRel = true;
@@ -1186,7 +1210,7 @@ getUncompressedData(MCAsmLayout &Layout,
static bool
prependCompressionHeader(uint64_t Size,
SmallVectorImpl<char> &CompressedContents) {
- static const StringRef Magic = "ZLIB";
+ const StringRef Magic = "ZLIB";
if (Size <= Magic.size() + sizeof(Size) + CompressedContents.size())
return false;
if (sys::IsLittleEndianHost)
@@ -1348,7 +1372,8 @@ static int cmpRel(const ELFRelocationEntry *AP, const ELFRelocationEntry *BP) {
return B.Offset - A.Offset;
if (B.Type != A.Type)
return A.Type - B.Type;
- llvm_unreachable("ELFRelocs might be unstable!");
+ //llvm_unreachable("ELFRelocs might be unstable!");
+ return 0;
}
static void sortRelocs(const MCAssembler &Asm,
@@ -1794,12 +1819,16 @@ ELFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
const MCFragment &FB,
bool InSet,
bool IsPCRel) const {
- if (DataA.getFlags() & ELF_STB_Weak || MCELF::GetType(DataA) == ELF::STT_GNU_IFUNC)
+ 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) {