[lld] e6382d2 - [lld-macho][nfc] Simplify unwind section lookup

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 22 12:37:02 PDT 2022


Author: Jez Ng
Date: 2022-04-22T15:36:53-04:00
New Revision: e6382d23fcc8138d7dec4b23cb1b7f4e5cb4c335

URL: https://github.com/llvm/llvm-project/commit/e6382d23fcc8138d7dec4b23cb1b7f4e5cb4c335
DIFF: https://github.com/llvm/llvm-project/commit/e6382d23fcc8138d7dec4b23cb1b7f4e5cb4c335.diff

LOG: [lld-macho][nfc] Simplify unwind section lookup

Previously, we stored a pointer from the ObjFile to its compact unwind
section in order to avoid iterating over the file's sections a second
time. However, given the small number of sections (not subsections) per
file, this caching was really quite unnecessary. We will soon do lookups
for more sections (such as the `__eh_frame` section), so let's simplify
the code first.

Reviewed By: #lld-macho, Roger

Differential Revision: https://reviews.llvm.org/D123434

Added: 
    

Modified: 
    lld/MachO/InputFiles.cpp
    lld/MachO/InputFiles.h

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 3a7025795be63..c57ce60a7898f 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -344,8 +344,6 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
       section.subsections.push_back({0, isec});
     } else if (auto recordSize = getRecordSize(segname, name)) {
       splitRecords(*recordSize);
-      if (name == section_names::compactUnwind)
-        compactUnwindSection = §ion;
     } else if (segname == segment_names::llvm) {
       if (config->callGraphProfileSort && name == section_names::cgProfile)
         checkError(parseCallGraph(data, callGraph));
@@ -917,8 +915,19 @@ template <class LP> void ObjFile::parse() {
       parseRelocations(sectionHeaders, sectionHeaders[i], *sections[i]);
 
   parseDebugInfo();
+
+  Section *ehFrameSection = nullptr;
+  Section *compactUnwindSection = nullptr;
+  for (Section *sec : sections) {
+    Section **s = StringSwitch<Section **>(sec->name)
+                      .Case(section_names::compactUnwind, &compactUnwindSection)
+                      .Case(section_names::ehFrame, &ehFrameSection)
+                      .Default(nullptr);
+    if (s)
+      *s = sec;
+  }
   if (compactUnwindSection)
-    registerCompactUnwind();
+    registerCompactUnwind(*compactUnwindSection);
 }
 
 template <class LP> void ObjFile::parseLazy() {
@@ -981,8 +990,8 @@ ArrayRef<data_in_code_entry> ObjFile::getDataInCode() const {
 }
 
 // Create pointers from symbols to their associated compact unwind entries.
-void ObjFile::registerCompactUnwind() {
-  for (const Subsection &subsection : compactUnwindSection->subsections) {
+void ObjFile::registerCompactUnwind(Section &compactUnwindSection) {
+  for (const Subsection &subsection : compactUnwindSection.subsections) {
     ConcatInputSection *isec = cast<ConcatInputSection>(subsection.isec);
     // Hack!! Since each CUE contains a 
diff erent function address, if ICF
     // operated naively and compared the entire contents of each CUE, entries

diff  --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h
index 5d455d277b6f2..725f02af7b9a5 100644
--- a/lld/MachO/InputFiles.h
+++ b/lld/MachO/InputFiles.h
@@ -151,8 +151,6 @@ class ObjFile final : public InputFile {
   std::vector<CallGraphEntry> callGraph;
 
 private:
-  Section *compactUnwindSection = nullptr;
-
   template <class LP> void parseLazy();
   template <class SectionHeader> void parseSections(ArrayRef<SectionHeader>);
   template <class LP>
@@ -165,7 +163,7 @@ class ObjFile final : public InputFile {
   void parseRelocations(ArrayRef<SectionHeader> sectionHeaders,
                         const SectionHeader &, Section &);
   void parseDebugInfo();
-  void registerCompactUnwind();
+  void registerCompactUnwind(Section &compactUnwindSection);
 };
 
 // command-line -sectcreate file


        


More information about the llvm-commits mailing list