#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCValue.h"
-#include "llvm/Object/StringTableBuilder.h"
+#include "llvm/MC/StringTableBuilder.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
/// \param NumRegularSections - Number of non-relocation sections.
void computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
const SectionIndexMapTy &SectionIndexMap,
- RevGroupMapTy RevGroupMap,
+ const RevGroupMapTy &RevGroupMap,
unsigned NumRegularSections);
void ComputeIndexMap(MCAssembler &Asm,
return Type;
}
-static const MCSymbol *getBaseSymbol(const MCAsmLayout &Layout,
- const MCSymbol &Symbol) {
- if (!Symbol.isVariable())
- return &Symbol;
-
- const MCExpr *Expr = Symbol.getVariableValue();
- MCValue Value;
- if (!Expr->EvaluateAsValue(Value, &Layout))
- llvm_unreachable("Invalid Expression");
-
- const MCSymbolRefExpr *RefB = Value.getSymB();
- if (RefB)
- Layout.getAssembler().getContext().FatalError(
- SMLoc(), Twine("symbol '") + RefB->getSymbol().getName() +
- "' could not be evaluated in a subtraction expression");
-
- const MCSymbolRefExpr *A = Value.getSymA();
- if (!A)
- return nullptr;
-
- return &A->getSymbol();
-}
-
void ELFObjectWriter::WriteSymbol(SymbolTableWriter &Writer, ELFSymbolData &MSD,
const MCAsmLayout &Layout) {
MCSymbolData &OrigData = *MSD.SymbolData;
(&OrigData.getFragment()->getParent()->getSection() ==
&OrigData.getSymbol().getSection())) &&
"The symbol's section doesn't match the fragment's symbol");
- const MCSymbol *Base = getBaseSymbol(Layout, OrigData.getSymbol());
+ const MCSymbol *Base = Layout.getBaseSymbol(OrigData.getSymbol());
// This has to be in sync with when computeSymbolTable uses SHN_ABS or
// SHN_COMMON.
}
// Most TLS relocations use a got, so they need the symbol. Even those that
- // are just an offset (@tpoff), require a symbol in some linkers (gold,
- // but not bfd ld).
+ // are just an offset (@tpoff), require a symbol in gold versions before
+ // 5efeedf61e4fe720fd3e9a08e6c91c10abb66d42 (2014-09-26) which fixed
+ // http://sourceware.org/PR16773.
if (Flags & ELF::SHF_TLS)
return true;
if (Asm.isThumbFunc(&Sym))
return true;
- if (TargetObjectWriter->needsRelocateWithSymbol(Type))
+ if (TargetObjectWriter->needsRelocateWithSymbol(*SD, Type))
return true;
return false;
}
+static const MCSymbol *getWeakRef(const MCSymbolRefExpr &Ref) {
+ const MCSymbol &Sym = Ref.getSymbol();
+
+ if (Ref.getKind() == MCSymbolRefExpr::VK_WEAKREF)
+ return &Sym;
+
+ if (!Sym.isVariable())
+ return nullptr;
+
+ const MCExpr *Expr = Sym.getVariableValue();
+ const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr);
+ if (!Inner)
+ return nullptr;
+
+ if (Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF)
+ return &Inner->getSymbol();
+ return nullptr;
+}
+
void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
const MCAsmLayout &Layout,
const MCFragment *Fragment,
if (const MCSymbol *R = Renames.lookup(SymA))
SymA = R;
- if (RefA->getKind() == MCSymbolRefExpr::VK_WEAKREF)
- WeakrefUsedInReloc.insert(SymA);
+ if (const MCSymbol *WeakRef = getWeakRef(*RefA))
+ WeakrefUsedInReloc.insert(WeakRef);
else
UsedInReloc.insert(SymA);
}
return true;
if (Symbol.isVariable()) {
- const MCSymbol *Base = getBaseSymbol(Layout, Symbol);
+ const MCSymbol *Base = Layout.getBaseSymbol(Symbol);
if (Base && Base->isUndefined())
return false;
}
void
ELFObjectWriter::computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
const SectionIndexMapTy &SectionIndexMap,
- RevGroupMapTy RevGroupMap,
+ const RevGroupMapTy &RevGroupMap,
unsigned NumRegularSections) {
// FIXME: Is this the correct place to do this?
// FIXME: Why is an undefined reference to _GLOBAL_OFFSET_TABLE_ needed?
ELFSymbolData MSD;
MSD.SymbolData = &SD;
- const MCSymbol *BaseSymbol = getBaseSymbol(Layout, Symbol);
+ const MCSymbol *BaseSymbol = Layout.getBaseSymbol(Symbol);
// Undefined symbols are global, but this is the first place we
// are able to set it.
MSD.SectionIndex = ELF::SHN_COMMON;
} else if (BaseSymbol->isUndefined()) {
if (isSignature && !Used)
- MSD.SectionIndex = SectionIndexMap.lookup(RevGroupMap[&Symbol]);
+ MSD.SectionIndex = SectionIndexMap.lookup(RevGroupMap.lookup(&Symbol));
else
MSD.SectionIndex = ELF::SHN_UNDEF;
if (!Used && WeakrefUsed)
for (auto i = Asm.file_names_begin(), e = Asm.file_names_end(); i != e; ++i)
StrTabBuilder.add(*i);
- StrTabBuilder.finalize();
+ StrTabBuilder.finalize(StringTableBuilder::ELF);
for (auto i = Asm.file_names_begin(), e = Asm.file_names_end(); i != e; ++i)
FileSymbolData.push_back(StrTabBuilder.getOffset(*i));
if (Size <= Magic.size() + sizeof(Size) + CompressedContents.size())
return false;
if (sys::IsLittleEndianHost)
- Size = sys::SwapByteOrder(Size);
+ sys::swapByteOrder(Size);
CompressedContents.insert(CompressedContents.begin(),
Magic.size() + sizeof(Size), 0);
std::copy(Magic.begin(), Magic.end(), CompressedContents.begin());
static_cast<const MCSectionELF&>(it->getSection());
ShStrTabBuilder.add(Section.getSectionName());
}
- ShStrTabBuilder.finalize();
+ ShStrTabBuilder.finalize(StringTableBuilder::ELF);
F->getContents().append(ShStrTabBuilder.data().begin(),
ShStrTabBuilder.data().end());
}
case ELF::SHT_X86_64_UNWIND:
case ELF::SHT_MIPS_REGINFO:
case ELF::SHT_MIPS_OPTIONS:
+ case ELF::SHT_MIPS_ABIFLAGS:
// Nothing to do.
break;
break;
default:
- assert(0 && "FIXME: sh_type value not supported!");
- break;
+ llvm_unreachable("FIXME: sh_type value not supported!");
}
if (TargetObjectWriter->getEMachine() == ELF::EM_ARM &&