[PATCH] D72775: [ELF] Optimization to LinkerScript::computeInputSections NFC

Andrew Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 09:05:47 PST 2020


andrewng created this revision.
andrewng added reviewers: ruiu, MaskRay.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

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.


https://reviews.llvm.org/D72775

Files:
  lld/ELF/LinkerScript.cpp


Index: lld/ELF/LinkerScript.cpp
===================================================================
--- lld/ELF/LinkerScript.cpp
+++ lld/ELF/LinkerScript.cpp
@@ -426,10 +426,12 @@
           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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72775.238285.patch
Type: text/x-patch
Size: 722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200115/d097f83d/attachment.bin>


More information about the llvm-commits mailing list