[llvm] e76ac80 - [llvm][orc] Consider other ELF init sections as well
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 26 13:44:48 PDT 2023
Author: Jeff Niu
Date: 2023-07-26T13:44:41-07:00
New Revision: e76ac8074f8534eb40bbcca99617eded70c9c21b
URL: https://github.com/llvm/llvm-project/commit/e76ac8074f8534eb40bbcca99617eded70c9c21b
DIFF: https://github.com/llvm/llvm-project/commit/e76ac8074f8534eb40bbcca99617eded70c9c21b.diff
LOG: [llvm][orc] Consider other ELF init sections as well
ELF object files can contain `.ctors` and `.dtors` sections that also
participate as initializers.
Reviewed By: lhames
Differential Revision: https://reviews.llvm.org/D154802
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h
llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp
llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h
index b7bc54b465a004..e5b95858013a86 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h
@@ -51,7 +51,15 @@ extern StringRef MachOInitSectionNames[19];
// 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[3];
extern StringRef ELFThreadBSSSectionName;
extern StringRef ELFThreadDataSectionName;
diff --git a/llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp b/llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp
index ecf5e291577340..9955130fc3b19d 100644
--- a/llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp
@@ -56,7 +56,19 @@ StringRef MachOInitSectionNames[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[3]{
+ ELFInitArrayFuncSectionName,
+ ELFInitFuncSectionName,
+ ELFCtorArrayFuncSectionName,
+};
StringRef ELFThreadBSSSectionName = ".tbss";
StringRef ELFThreadDataSectionName = ".tdata";
@@ -80,9 +92,11 @@ bool isMachOInitializerSection(StringRef QualifiedName) {
}
bool isELFInitializerSection(StringRef SecName) {
- if (SecName.consume_front(ELFInitArrayFuncSectionName) &&
- (SecName.empty() || SecName[0] == '.'))
- return true;
+ for (StringRef InitSection : ELFInitSectionNames) {
+ StringRef Name = SecName;
+ if (Name.consume_front(InitSection) && (Name.empty() || Name[0] == '.'))
+ return true;
+ }
return false;
}
diff --git a/llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp
index 13cffb1a02f5ad..b1ff1f2fbc3f8e 100644
--- a/llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp
@@ -28,6 +28,7 @@ TEST(ObjectFormatsTest, ELFInitializerSections) {
EXPECT_TRUE(isELFInitializerSection(".init_array"));
EXPECT_TRUE(isELFInitializerSection(".init_array.0"));
EXPECT_FALSE(isELFInitializerSection(".text"));
+ EXPECT_TRUE(isELFInitializerSection(".ctors.0"));
}
} // end anonymous namespace
More information about the llvm-commits
mailing list