[PATCH] D154802: [llvm][orc] Consider other ELF init sections as well

Jeff Niu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 9 15:24:34 PDT 2023


Mogball created this revision.
Mogball added reviewers: rriddle, bzcheeseman.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Mogball requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

ELF object files can contain `.ctors` and `.dtors` sections that also
participate as initializers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154802

Files:
  llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h
  llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp
  llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp


Index: llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp
===================================================================
--- llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp
+++ llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp
@@ -28,6 +28,7 @@
   EXPECT_TRUE(isELFInitializerSection(".init_array"));
   EXPECT_TRUE(isELFInitializerSection(".init_array.0"));
   EXPECT_FALSE(isELFInitializerSection(".text"));
+  EXPECT_TRUE(isELFInitializerSection(".ctors.0"));
 }
 
 } // end anonymous namespace
Index: llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp
===================================================================
--- llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp
+++ llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp
@@ -56,7 +56,19 @@
 };
 
 StringRef ELFEHFrameSectionName = ".eh_frame";
+
 StringRef ELFInitArrayFuncSectionName = ".init_array";
+StringRef ELFInitFuncSectionName = ".init";
+StringRef ELFFiniArrayFuncSectionName = ".fini_array";
+StringRef ELFFiniFuncSectionName = ".fini";
+StringRef ELFCtorArrayFuncSectionName = ".ctors";
+StringRef ELFDtorArrayFuncSectionName = ".dtors";
+
+StringRef ELFInitSectionNames[6]{
+    ELFInitArrayFuncSectionName, ELFInitFuncSectionName,
+    ELFFiniArrayFuncSectionName, ELFFiniFuncSectionName,
+    ELFCtorArrayFuncSectionName, ELFDtorArrayFuncSectionName,
+};
 
 StringRef ELFThreadBSSSectionName = ".tbss";
 StringRef ELFThreadDataSectionName = ".tdata";
@@ -80,9 +92,14 @@
 }
 
 bool isELFInitializerSection(StringRef SecName) {
-  if (SecName.consume_front(ELFInitArrayFuncSectionName) &&
-      (SecName.empty() || SecName[0] == '.'))
-    return true;
+  // Relocation tables for initializer sections also count.
+  if (SecName.startswith(".rela."))
+    SecName.consume_front(".rela");
+  for (StringRef InitSection : ELFInitSectionNames) {
+    StringRef Name = SecName;
+    if (Name.consume_front(InitSection) && (Name.empty() || Name[0] == '.'))
+      return true;
+  }
   return false;
 }
 
Index: llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h
===================================================================
--- llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h
+++ llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h
@@ -51,7 +51,15 @@
 
 // ELF section names.
 extern StringRef ELFEHFrameSectionName;
+
 extern StringRef ELFInitArrayFuncSectionName;
+extern StringRef ELFInitFuncSectionName;
+extern StringRef ELFFiniArrayFuncSectionName;
+extern StringRef ELFFiniFuncSectionName;
+extern StringRef ELFCtorArrayFuncSectionName;
+extern StringRef ELFDtorArrayFuncSectionName;
+
+extern StringRef ELFInitSectionNames[6];
 
 extern StringRef ELFThreadBSSSectionName;
 extern StringRef ELFThreadDataSectionName;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154802.538459.patch
Type: text/x-patch
Size: 2770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230709/2e213033/attachment.bin>


More information about the llvm-commits mailing list