From d36b2649e5e4d90a3f439e2a16057cd75566c669 Mon Sep 17 00:00:00 2001 From: Andrew Ng Date: Wed, 15 Jan 2020 11:48:37 +0000 Subject: [PATCH] [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 --- lld/ELF/LinkerScript.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 57e0e1e8acbf..b0d60bc32a9f 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -426,10 +426,12 @@ LinkerScript::computeInputSections(const InputSectionDescription *cmd) { cast(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); -- 2.34.1