From 43e76cd489250329cddb1fd575cf9fc9c17ea334 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 26 May 2017 17:48:27 +0000 Subject: [PATCH] Avoid a couple uses of OutputSections. After fabricateDefaultCommands we can look at the script commands. llvm-svn: 304014 --- lld/ELF/Writer.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 7e0b0f1..e539d8f 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -81,7 +81,8 @@ private: void addStartStopSymbols(OutputSection *Sec); uint64_t getEntryAddr(); OutputSection *findSection(StringRef Name); - OutputSectionCommand *findSectionInScript(StringRef Name); + OutputSection *findSectionInScript(StringRef Name); + OutputSectionCommand *findSectionCommand(StringRef Name); std::vector Phdrs; @@ -1313,7 +1314,7 @@ void Writer::addStartStopSymbols(OutputSection *Sec) { } template -OutputSectionCommand *Writer::findSectionInScript(StringRef Name) { +OutputSectionCommand *Writer::findSectionCommand(StringRef Name) { for (BaseCommand *Base : Script->Opt.Commands) if (auto *Cmd = dyn_cast(Base)) if (Cmd->Name == Name) @@ -1321,6 +1322,12 @@ OutputSectionCommand *Writer::findSectionInScript(StringRef Name) { return nullptr; } +template OutputSection *Writer::findSectionInScript(StringRef Name) { + if (OutputSectionCommand *Cmd = findSectionCommand(Name)) + return Cmd->Sec; + return nullptr; +} + template OutputSection *Writer::findSection(StringRef Name) { for (OutputSection *Sec : OutputSections) if (Sec->Name == Name) @@ -1607,7 +1614,7 @@ template uint64_t Writer::getEntryAddr() { return Addr; // Case 4 - if (OutputSection *Sec = findSection(".text")) { + if (OutputSection *Sec = findSectionInScript(".text")) { if (Config->WarnMissingEntry) warn("cannot find entry symbol " + Config->Entry + "; defaulting to 0x" + utohexstr(Sec->Addr)); @@ -1670,7 +1677,7 @@ template void Writer::fixPredefinedSymbols() { } if (ElfSym::Bss) - ElfSym::Bss->Section = findSection(".bss"); + ElfSym::Bss->Section = findSectionInScript(".bss"); // Setup MIPS _gp_disp/__gnu_local_gp symbols which should // be equal to the _gp symbol's value. @@ -1778,7 +1785,7 @@ template void Writer::writeSections() { // PPC64 needs to process relocations in the .opd section // before processing relocations in code-containing sections. - if (auto *OpdCmd = findSectionInScript(".opd")) { + if (auto *OpdCmd = findSectionCommand(".opd")) { Out::Opd = OpdCmd->Sec; Out::OpdBuf = Buf + Out::Opd->Offset; OpdCmd->template writeTo(Buf + Out::Opd->Offset); -- 2.7.4