[PATCH] D78954: [LLD][ELF] Add isDebug flag to SectionBase.

Alexey Lapshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 27 12:55:44 PDT 2020


avl created this revision.
avl added reviewers: ruiu, grimar, MaskRay.
avl added projects: LLVM, lld.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.

Add isDebug flag to SectionBase to avoid multiplue string
comparisions by isDebugSection() function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78954

Files:
  lld/ELF/Driver.cpp
  lld/ELF/InputSection.cpp
  lld/ELF/InputSection.h


Index: lld/ELF/InputSection.h
===================================================================
--- lld/ELF/InputSection.h
+++ lld/ELF/InputSection.h
@@ -33,6 +33,10 @@
 
 extern std::vector<Partition> partitions;
 
+inline bool isDebugSection(const StringRef &name) {
+  return name.startswith(".debug") || name.startswith(".zdebug");
+}
+
 // This is the base class of all sections that lld handles. Some are sections in
 // input files, some are sections in the produced output file and some exist
 // just as a convenience for implementing special ways of combining some
@@ -62,6 +66,9 @@
   // Set for sections that should not be folded by ICF.
   unsigned keepUnique : 1;
 
+  // True if that section is a debug section.
+  unsigned isDebug : 1;
+
   // The 1-indexed partition that this section is assigned to by the garbage
   // collector, or 0 if this section is dead. Normally there is only one
   // partition, so this will either be 0 or 1.
@@ -96,8 +103,9 @@
               uint64_t entsize, uint64_t alignment, uint32_t type,
               uint32_t info, uint32_t link)
       : name(name), repl(this), sectionKind(sectionKind), bss(false),
-        keepUnique(false), partition(0), alignment(alignment), flags(flags),
-        entsize(entsize), type(type), link(link), info(info) {}
+        keepUnique(false), isDebug(isDebugSection(name)), partition(0),
+        alignment(alignment), flags(flags), entsize(entsize), type(type),
+        link(link), info(info) {}
 };
 
 // This corresponds to a section of an input file.
@@ -390,10 +398,6 @@
   template <class ELFT> void copyShtGroup(uint8_t *buf);
 };
 
-inline bool isDebugSection(const InputSectionBase &sec) {
-  return sec.name.startswith(".debug") || sec.name.startswith(".zdebug");
-}
-
 // The list of all input sections.
 extern std::vector<InputSectionBase *> inputSections;
 
Index: lld/ELF/InputSection.cpp
===================================================================
--- lld/ELF/InputSection.cpp
+++ lld/ELF/InputSection.cpp
@@ -441,7 +441,7 @@
       // See the comment in maybeReportUndefined for PPC32 .got2 and PPC64 .toc
       auto *d = dyn_cast<Defined>(&sym);
       if (!d) {
-        if (!isDebugSection(*sec) && sec->name != ".eh_frame" &&
+        if (!sec->isDebug && sec->name != ".eh_frame" &&
             sec->name != ".gcc_except_table" && sec->name != ".got2" &&
             sec->name != ".toc") {
           uint32_t secIdx = cast<Undefined>(sym).discardedSecIdx;
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -1984,11 +1984,11 @@
     if (config->strip == StripPolicy::None)
       return false;
 
-    if (isDebugSection(*s))
+    if (s->isDebug)
       return true;
     if (auto *isec = dyn_cast<InputSection>(s))
       if (InputSectionBase *rel = isec->getRelocatedSection())
-        if (isDebugSection(*rel))
+        if (rel->isDebug)
           return true;
 
     return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78954.260408.patch
Type: text/x-patch
Size: 3000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200427/3adc1618/attachment.bin>


More information about the llvm-commits mailing list