From e0be2901cd2623e072640a04f7f0804b5cf80276 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 21 Nov 2016 02:10:12 +0000 Subject: [PATCH] Simplify. NFC. llvm-svn: 287514 --- lld/ELF/LinkerScript.cpp | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 388640c..5c56388 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -128,17 +128,19 @@ bool BytesDataCommand::classof(const BaseCommand *C) { template LinkerScript::LinkerScript() = default; template LinkerScript::~LinkerScript() = default; +template static StringRef basename(InputSectionBase *S) { + if (S->getFile()) + return sys::path::filename(S->getFile()->getName()); + return ""; +} + template bool LinkerScript::shouldKeep(InputSectionBase *S) { - for (InputSectionDescription *ID : Opt.KeptSections) { - StringRef Filename = S->getFile()->getName(); - if (!ID->FilePat.match(sys::path::filename(Filename))) - continue; - - for (SectionPattern &P : ID->SectionPatterns) - if (P.SectionPat.match(S->Name)) - return true; - } + for (InputSectionDescription *ID : Opt.KeptSections) + if (ID->FilePat.match(basename(S))) + for (SectionPattern &P : ID->SectionPatterns) + if (P.SectionPat.match(S->Name)) + return true; return false; } @@ -202,15 +204,13 @@ void LinkerScript::computeInputSections(InputSectionDescription *I) { if (!S->Live || S->Assigned) continue; - StringRef Filename; - if (elf::ObjectFile *F = S->getFile()) - Filename = sys::path::filename(F->getName()); - - if (I->FilePat.match(Filename) && !Pat.ExcludedFilePat.match(Filename) && - Pat.SectionPat.match(S->Name)) { - I->Sections.push_back(S); - S->Assigned = true; - } + StringRef Filename = basename(S); + if (!I->FilePat.match(Filename) || Pat.ExcludedFilePat.match(Filename)) + continue; + if (!Pat.SectionPat.match(S->Name)) + continue; + I->Sections.push_back(S); + S->Assigned = true; } // Sort sections as instructed by SORT-family commands and --sort-section @@ -343,9 +343,6 @@ void LinkerScript::processCommands(OutputSectionFactory &Factory) { if (shouldDefine(OutCmd)) addSymbol(OutCmd); - if (V.empty()) - continue; - for (InputSectionBase *Sec : V) { addSection(Factory, Sec, Cmd->Name); if (uint32_t Subalign = Cmd->SubalignExpr ? Cmd->SubalignExpr(0) : 0) -- 2.7.4