return getGenericObjectFileSymbolInfo(ES, **Obj);
}
+bool hasInitializerSection(jitlink::LinkGraph &G) {
+ bool IsMachO = G.getTargetTriple().isOSBinFormatMachO();
+ bool IsElf = G.getTargetTriple().isOSBinFormatELF();
+ if (!IsMachO && !IsElf)
+ return false;
+
+ for (auto &Sec : G.sections()) {
+ if (IsMachO && std::apply(MachOPlatform::isInitializerSection,
+ Sec.getName().split(",")))
+ return true;
+ if (IsElf && ELFNixPlatform::isInitializerSection(Sec.getName()))
+ return true;
+ }
+
+ return false;
+}
+
} // End namespace orc.
} // End namespace llvm.
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h"
#include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
+#include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h"
#include "llvm/Support/MemoryBuffer.h"
#include <string>
#include <vector>
LGI.SymbolFlags[ES.intern(Sym->getName())] = Flags;
}
- if ((G.getTargetTriple().isOSBinFormatMachO() && hasMachOInitSection(G)) ||
- (G.getTargetTriple().isOSBinFormatELF() && hasELFInitSection(G)))
+ if (hasInitializerSection(G))
LGI.InitSymbol = makeInitSymbol(ES, G);
return LGI;
}
- static bool hasMachOInitSection(LinkGraph &G) {
- for (auto &Sec : G.sections())
- if (Sec.getName() == "__DATA,__objc_selrefs" ||
- Sec.getName() == "__DATA,__objc_classlist" ||
- Sec.getName() == "__TEXT,__swift5_protos" ||
- Sec.getName() == "__TEXT,__swift5_proto" ||
- Sec.getName() == "__TEXT,__swift5_types" ||
- Sec.getName() == "__DATA,__mod_init_func")
- return true;
- return false;
- }
-
- static bool hasELFInitSection(LinkGraph &G) {
- for (auto &Sec : G.sections()) {
- auto SecName = Sec.getName();
- if (SecName.consume_front(".init_array") &&
- (SecName.empty() || SecName[0] == '.'))
- return true;
- }
- return false;
- }
-
static SymbolStringPtr makeInitSymbol(ExecutionSession &ES, LinkGraph &G) {
std::string InitSymString;
raw_string_ostream(InitSymString)
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/JITLink/JITLink.h"
+#include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Memory.h"
EXPECT_EQ(E2->getOffset(), 4U);
}
}
+
+struct InitSymbolsTestParams {
+ InitSymbolsTestParams(StringRef Triple, StringRef Section,
+ bool ExpectedHasInitializerSection)
+ : Triple(Triple), Section(Section),
+ ExpectedHasInitializerSection(ExpectedHasInitializerSection) {}
+
+ StringRef Triple;
+ StringRef Section;
+ bool ExpectedHasInitializerSection;
+};
+
+class InitSymbolsTestFixture
+ : public ::testing::TestWithParam<InitSymbolsTestParams> {};
+
+TEST_P(InitSymbolsTestFixture, InitSymbolSections) {
+ InitSymbolsTestParams Params = GetParam();
+ auto Graph = std::make_unique<LinkGraph>(
+ "foo", Triple(Params.Triple), 8, support::little, getGenericEdgeKindName);
+ Graph->createSection(Params.Section,
+ orc::MemProt::Read | orc::MemProt::Write);
+ EXPECT_EQ(orc::hasInitializerSection(*Graph),
+ Params.ExpectedHasInitializerSection);
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ InitSymbolsTests, InitSymbolsTestFixture,
+ ::testing::Values(
+ InitSymbolsTestParams("x86_64-apple-darwin", "__DATA,__objc_selrefs",
+ true),
+ InitSymbolsTestParams("x86_64-apple-darwin", "__DATA,__mod_init_func",
+ true),
+ InitSymbolsTestParams("x86_64-apple-darwin", "__DATA,__objc_classlist",
+ true),
+ InitSymbolsTestParams("x86_64-apple-darwin", "__TEXT,__swift5_proto",
+ true),
+ InitSymbolsTestParams("x86_64-apple-darwin", "__TEXT,__swift5_protos",
+ true),
+ InitSymbolsTestParams("x86_64-apple-darwin", "__TEXT,__swift5_types",
+ true),
+ InitSymbolsTestParams("x86_64-apple-darwin", "__DATA,__not_an_init_sec",
+ false),
+ InitSymbolsTestParams("x86_64-unknown-linux", ".init_array", true),
+ InitSymbolsTestParams("x86_64-unknown-linux", ".init_array.0", true),
+ InitSymbolsTestParams("x86_64-unknown-linux", ".text", false)));