[ELF] Optimization to LinkerScript::computeInputSections NFC

Moved the section name check ahead of any filename matching or
exclusion. Firstly, this reduces the need to retrieve the filename and
secondly, reduces the amount of potentially expensive filename pattern
matching if such rules are present in the linker script.

The impact of this change is particularly significant when linking
objects built with -ffunction-sections and -fstack-size-section, using a
linker script that includes non-trivial filename patterns. In a number
of such cases, the link time is halved.

Differential Revision: https://reviews.llvm.org/D72775
This commit is contained in:
Andrew Ng 2020-01-15 11:48:37 +00:00
parent d54d71b67e
commit d36b2649e5
1 changed files with 5 additions and 3 deletions

View File

@ -426,10 +426,12 @@ LinkerScript::computeInputSections(const InputSectionDescription *cmd) {
cast<InputSection>(sec)->getRelocatedSection())
continue;
// Check the name early to improve performance in the common case.
if (!pat.sectionPat.match(sec->name))
continue;
std::string filename = getFilename(sec->file);
if (!cmd->filePat.match(filename) ||
pat.excludedFilePat.match(filename) ||
!pat.sectionPat.match(sec->name))
if (!cmd->filePat.match(filename) || pat.excludedFilePat.match(filename))
continue;
ret.push_back(sec);