diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-10-17 01:06:02 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-10-17 01:06:02 +0000 |
commit | 4544a4062c5cac54d61b4d13319b6dfc1004a65a (patch) | |
tree | 68b1144e3e40c9980099d91bd265d99916efe05e /llvm/lib/MC | |
parent | 0680d8aa6887e8567825b270fe700da61f58259b (diff) | |
download | bcm5719-llvm-4544a4062c5cac54d61b4d13319b6dfc1004a65a.tar.gz bcm5719-llvm-4544a4062c5cac54d61b4d13319b6dfc1004a65a.zip |
Revert commit r219835 and r219829.
Revert "Correctly handle references to section symbols."
Revert "Allow forward references to section symbols."
Rui found a regression I am debugging.
llvm-svn: 220010
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r-- | llvm/lib/MC/ELFObjectWriter.cpp | 74 | ||||
-rw-r--r-- | llvm/lib/MC/MCContext.cpp | 24 | ||||
-rw-r--r-- | llvm/lib/MC/MCELFStreamer.cpp | 13 |
3 files changed, 50 insertions, 61 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index d77f03f5281..4577f0130ed 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -81,13 +81,23 @@ public: struct ELFRelocationEntry { uint64_t Offset; // Where is the relocation. - const MCSymbol *Symbol; // The symbol to relocate with. + bool UseSymbol; // Relocate with a symbol, not the section. + union { + const MCSymbol *Symbol; // The symbol to relocate with. + const MCSectionData *Section; // The section to relocate with. + }; unsigned Type; // The type of the relocation. uint64_t Addend; // The addend to use. ELFRelocationEntry(uint64_t Offset, const MCSymbol *Symbol, unsigned Type, uint64_t Addend) - : Offset(Offset), Symbol(Symbol), Type(Type), Addend(Addend) {} + : Offset(Offset), UseSymbol(true), Symbol(Symbol), Type(Type), + Addend(Addend) {} + + ELFRelocationEntry(uint64_t Offset, const MCSectionData *Section, + unsigned Type, uint64_t Addend) + : Offset(Offset), UseSymbol(false), Section(Section), Type(Type), + Addend(Addend) {} }; class ELFObjectWriter : public MCObjectWriter { @@ -127,14 +137,6 @@ class ELFObjectWriter : public MCObjectWriter { // Support lexicographic sorting. bool operator<(const ELFSymbolData &RHS) const { - unsigned LHSType = MCELF::GetType(*SymbolData); - unsigned RHSType = MCELF::GetType(*RHS.SymbolData); - if (LHSType == ELF::STT_SECTION && RHSType != ELF::STT_SECTION) - return false; - if (LHSType != ELF::STT_SECTION && RHSType == ELF::STT_SECTION) - return true; - if (LHSType == ELF::STT_SECTION && RHSType == ELF::STT_SECTION) - return SectionIndex < RHS.SectionIndex; return Name < RHS.Name; } }; @@ -649,6 +651,22 @@ void ELFObjectWriter::WriteSymbolTable(MCDataFragment *SymtabF, WriteSymbol(Writer, MSD, Layout); } + // Write out a symbol table entry for each regular section. + for (MCAssembler::const_iterator i = Asm.begin(), e = Asm.end(); i != e; + ++i) { + const MCSectionELF &Section = + static_cast<const MCSectionELF&>(i->getSection()); + if (Section.getType() == ELF::SHT_RELA || + Section.getType() == ELF::SHT_REL || + Section.getType() == ELF::SHT_STRTAB || + Section.getType() == ELF::SHT_SYMTAB || + Section.getType() == ELF::SHT_SYMTAB_SHNDX) + continue; + Writer.writeSymbol(0, ELF::STT_SECTION, 0, 0, ELF::STV_DEFAULT, + SectionIndexMap.lookup(&Section), false); + LastLocalSymbolIndex++; + } + for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i) { ELFSymbolData &MSD = ExternalSymbolData[i]; MCSymbolData &Data = *MSD.SymbolData; @@ -864,11 +882,8 @@ void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm, if (!RelocateWithSymbol) { const MCSection *SecA = (SymA && !SymA->isUndefined()) ? &SymA->getSection() : nullptr; - auto *ELFSec = cast_or_null<MCSectionELF>(SecA); - MCSymbol *SectionSymbol = - ELFSec ? Asm.getContext().GetOrCreateSymbol(ELFSec->getSectionName()) - : nullptr; - ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend); + const MCSectionData *SecAD = SecA ? &Asm.getSectionData(*SecA) : nullptr; + ELFRelocationEntry Rec(FixupOffset, SecAD, Type, Addend); Relocations[FixupSection].push_back(Rec); return; } @@ -1046,10 +1061,7 @@ ELFObjectWriter::computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout, Buf += Name.substr(Pos + Skip); Name = Buf; } - - // Sections have their own string table - if (MCELF::GetType(SD) != ELF::STT_SECTION) - MSD.Name = StrTabBuilder.add(Name); + MSD.Name = StrTabBuilder.add(Name); if (MSD.SectionIndex == ELF::SHN_UNDEF) UndefinedSymbolData.push_back(MSD); @@ -1067,11 +1079,9 @@ ELFObjectWriter::computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout, for (auto i = Asm.file_names_begin(), e = Asm.file_names_end(); i != e; ++i) FileSymbolData.push_back(StrTabBuilder.getOffset(*i)); - for (ELFSymbolData &MSD : LocalSymbolData) - MSD.StringIndex = MCELF::GetType(*MSD.SymbolData) == ELF::STT_SECTION - ? 0 - : StrTabBuilder.getOffset(MSD.Name); - for (ELFSymbolData &MSD : ExternalSymbolData) + for (ELFSymbolData& MSD : LocalSymbolData) + MSD.StringIndex = StrTabBuilder.getOffset(MSD.Name); + for (ELFSymbolData& MSD : ExternalSymbolData) MSD.StringIndex = StrTabBuilder.getOffset(MSD.Name); for (ELFSymbolData& MSD : UndefinedSymbolData) MSD.StringIndex = StrTabBuilder.getOffset(MSD.Name); @@ -1087,6 +1097,8 @@ ELFObjectWriter::computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout, for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i) LocalSymbolData[i].SymbolData->setIndex(Index++); + Index += NumRegularSections; + for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i) ExternalSymbolData[i].SymbolData->setIndex(Index++); for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i) @@ -1342,8 +1354,18 @@ void ELFObjectWriter::WriteRelocationsFragment(const MCAssembler &Asm, for (unsigned i = 0, e = Relocs.size(); i != e; ++i) { const ELFRelocationEntry &Entry = Relocs[e - i - 1]; - unsigned Index = - Entry.Symbol ? getSymbolIndexInSymbolTable(Asm, Entry.Symbol) : 0; + + unsigned Index; + if (Entry.UseSymbol) { + Index = getSymbolIndexInSymbolTable(Asm, Entry.Symbol); + } else { + const MCSectionData *Sec = Entry.Section; + if (Sec) + Index = Sec->getOrdinal() + FileSymbolData.size() + + LocalSymbolData.size() + 1; + else + Index = 0; + } if (is64Bit()) { write(*F, Entry.Offset); diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index ea6db142fd7..9d8a57e55f6 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -113,30 +113,6 @@ MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) { return Sym; } -MCSymbol *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) { - MCSymbol *&Sym = SectionSymbols[&Section]; - if (Sym) - return Sym; - - StringRef Name = Section.getSectionName(); - - StringMapEntry<MCSymbol*> &Entry = Symbols.GetOrCreateValue(Name); - MCSymbol *OldSym = Entry.getValue(); - if (OldSym && OldSym->isUndefined()) { - Sym = OldSym; - return OldSym; - } - - StringMapEntry<bool> *NameEntry = &UsedNames.GetOrCreateValue(Name); - NameEntry->setValue(true); - Sym = new (*this) MCSymbol(NameEntry->getKey(), /*isTemporary*/ false); - - if (!Entry.getValue()) - Entry.setValue(Sym); - - return Sym; -} - MCSymbol *MCContext::CreateSymbol(StringRef Name) { // Determine whether this is an assembler temporary or normal label, if used. bool isTemporary = false; diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index bdc4a8410fb..4ef22d00224 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -92,19 +92,10 @@ void MCELFStreamer::ChangeSection(const MCSection *Section, MCSectionData *CurSection = getCurrentSectionData(); if (CurSection && CurSection->isBundleLocked()) report_fatal_error("Unterminated .bundle_lock when changing a section"); - - MCAssembler &Asm = getAssembler(); - auto *SectionELF = static_cast<const MCSectionELF *>(Section); - const MCSymbol *Grp = SectionELF->getGroup(); + const MCSymbol *Grp = static_cast<const MCSectionELF *>(Section)->getGroup(); if (Grp) - Asm.getOrCreateSymbolData(*Grp); - + getAssembler().getOrCreateSymbolData(*Grp); this->MCObjectStreamer::ChangeSection(Section, Subsection); - MCSymbol *SectionSymbol = getContext().getOrCreateSectionSymbol(*SectionELF); - if (SectionSymbol->isUndefined()) { - EmitLabel(SectionSymbol); - MCELF::SetType(Asm.getSymbolData(*SectionSymbol), ELF::STT_SECTION); - } } void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) { |