[llvm] 3d4e9d5 - [ORC] Move ORC-specific object format details into OrcShared.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 11 10:52:06 PST 2023
Author: Lang Hames
Date: 2023-02-11T10:51:38-08:00
New Revision: 3d4e9d5eb0f7b0b2ad412b95239752701a734646
URL: https://github.com/llvm/llvm-project/commit/3d4e9d5eb0f7b0b2ad412b95239752701a734646
DIFF: https://github.com/llvm/llvm-project/commit/3d4e9d5eb0f7b0b2ad412b95239752701a734646.diff
LOG: [ORC] Move ORC-specific object format details into OrcShared.
This allows these details to be shared with JITLink, which is allowed to
depend on the OrcShared library (but not on OrcJIT).
Added:
llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h
llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp
llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp
Modified:
llvm/include/llvm/ExecutionEngine/Orc/COFFPlatform.h
llvm/include/llvm/ExecutionEngine/Orc/ELFNixPlatform.h
llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
llvm/include/llvm/ExecutionEngine/Orc/ObjectFileInterface.h
llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp
llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt
llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt
llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/COFFPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/COFFPlatform.h
index 0a9e08fdd6d7..767d33675358 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/COFFPlatform.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/COFFPlatform.h
@@ -67,10 +67,6 @@ class COFFPlatform : public Platform {
static ArrayRef<std::pair<const char *, const char *>>
standardRuntimeUtilityAliases();
- static bool isInitializerSection(StringRef Name) {
- return Name.startswith(".CRT");
- }
-
static StringRef getSEHFrameSectionName() { return ".pdata"; }
private:
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ELFNixPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/ELFNixPlatform.h
index 758c0016e685..4ed3461540eb 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/ELFNixPlatform.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/ELFNixPlatform.h
@@ -119,9 +119,6 @@ class ELFNixPlatform : public Platform {
static ArrayRef<std::pair<const char *, const char *>>
standardRuntimeUtilityAliases();
- /// Returns true if the given section name is an initializer section.
- static bool isInitializerSection(StringRef SecName);
-
private:
// The ELFNixPlatformPlugin scans/modifies LinkGraphs to support ELF
// platform features including initializers, exceptions, TLV, and language
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
index c51608899e04..ad7e3f56f754 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
@@ -103,9 +103,6 @@ class MachOPlatform : public Platform {
static ArrayRef<std::pair<const char *, const char *>>
standardRuntimeUtilityAliases();
- /// Returns true if the given section name is an initializer section.
- static bool isInitializerSection(StringRef SegName, StringRef SectName);
-
private:
// Data needed for bootstrap only.
struct BootstrapInfo {
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ObjectFileInterface.h b/llvm/include/llvm/ExecutionEngine/Orc/ObjectFileInterface.h
index 7d8a3ebbe01b..1bf09069163e 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/ObjectFileInterface.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/ObjectFileInterface.h
@@ -32,8 +32,6 @@ void addInitSymbol(MaterializationUnit::Interface &I, ExecutionSession &ES,
Expected<MaterializationUnit::Interface>
getObjectFileInterface(ExecutionSession &ES, MemoryBufferRef ObjBuffer);
-bool hasInitializerSection(jitlink::LinkGraph &G);
-
} // End namespace orc
} // End namespace llvm
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h
new file mode 100644
index 000000000000..3911bc16f0f1
--- /dev/null
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h
@@ -0,0 +1,55 @@
+//===------ ObjectFormats.h - Object format details for ORC -----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// ORC-specific object format details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_OBJECTFORMATS_H
+#define LLVM_EXECUTIONENGINE_ORC_SHARED_OBJECTFORMATS_H
+
+#include "llvm/ADT/StringRef.h"
+
+namespace llvm {
+namespace orc {
+
+// MachO section names.
+extern StringRef MachODataCommonSectionName;
+extern StringRef MachODataDataSectionName;
+extern StringRef MachOEHFrameSectionName;
+extern StringRef MachOCompactUnwindInfoSectionName;
+extern StringRef MachOModInitFuncSectionName;
+extern StringRef MachOObjCClassListSectionName;
+extern StringRef MachOObjCImageInfoSectionName;
+extern StringRef MachOObjCSelRefsSectionName;
+extern StringRef MachOSwift5ProtoSectionName;
+extern StringRef MachOSwift5ProtosSectionName;
+extern StringRef MachOSwift5TypesSectionName;
+extern StringRef MachOThreadBSSSectionName;
+extern StringRef MachOThreadDataSectionName;
+extern StringRef MachOThreadVarsSectionName;
+extern StringRef MachOInitSectionNames[6];
+
+// ELF section names.
+extern StringRef ELFEHFrameSectionName;
+extern StringRef ELFInitArrayFuncSectionName;
+
+extern StringRef ELFThreadBSSSectionName;
+extern StringRef ELFThreadDataSectionName;
+
+bool isMachOInitializerSection(StringRef SegName, StringRef SecName);
+bool isMachOInitializerSection(StringRef QualifiedName);
+
+bool isELFInitializerSection(StringRef SecName);
+
+bool isCOFFInitializerSection(StringRef Name);
+
+} // end namespace orc
+} // end namespace llvm
+
+#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_MEMORYFLAGS_H
diff --git a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
index 40716a7f9b61..3010370f4e40 100644
--- a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
@@ -10,6 +10,7 @@
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
#include "llvm/ExecutionEngine/Orc/LookupAndRecordAddrs.h"
#include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h"
+#include "llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h"
#include "llvm/Object/COFF.h"
@@ -850,7 +851,7 @@ Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
jitlink::LinkGraph &G, MaterializationResponsibility &MR) {
JITLinkSymbolSet InitSectionSymbols;
for (auto &Sec : G.sections())
- if (COFFPlatform::isInitializerSection(Sec.getName()))
+ if (isCOFFInitializerSection(Sec.getName()))
for (auto *B : Sec.blocks())
if (!B->edges_empty())
InitSectionSymbols.insert(
@@ -885,7 +886,7 @@ Error COFFPlatform::COFFPlatformPlugin::
// Collect static initializers
for (auto &S : G.sections())
- if (COFFPlatform::isInitializerSection(S.getName()))
+ if (isCOFFInitializerSection(S.getName()))
for (auto *B : S.blocks()) {
if (B->edges_empty())
continue;
diff --git a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
index 00032e4dca3f..b695a2184d0a 100644
--- a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
@@ -14,6 +14,7 @@
#include "llvm/ExecutionEngine/JITLink/x86_64.h"
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
+#include "llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h"
#include "llvm/Support/BinaryByteStream.h"
#include "llvm/Support/Debug.h"
#include <optional>
@@ -96,12 +97,6 @@ class DSOHandleMaterializationUnit : public MaterializationUnit {
ELFNixPlatform &ENP;
};
-StringRef EHFrameSectionName = ".eh_frame";
-StringRef InitArrayFuncSectionName = ".init_array";
-
-StringRef ThreadBSSSectionName = ".tbss";
-StringRef ThreadDataSectionName = ".tdata";
-
} // end anonymous namespace
namespace llvm {
@@ -272,13 +267,6 @@ ELFNixPlatform::standardRuntimeUtilityAliases() {
StandardRuntimeUtilityAliases);
}
-bool ELFNixPlatform::isInitializerSection(StringRef SecName) {
- if (SecName.consume_front(InitArrayFuncSectionName) &&
- (SecName.empty() || SecName[0] == '.'))
- return true;
- return false;
-}
-
bool ELFNixPlatform::supportedTarget(const Triple &TT) {
switch (TT.getArch()) {
case Triple::x86_64:
@@ -724,7 +712,7 @@ void ELFNixPlatform::ELFNixPlatformPlugin::addEHAndTLVSupportPasses(
Config.PostFixupPasses.push_back([this](jitlink::LinkGraph &G) -> Error {
ELFPerObjectSectionsToRegister POSR;
- if (auto *EHFrameSection = G.findSectionByName(EHFrameSectionName)) {
+ if (auto *EHFrameSection = G.findSectionByName(ELFEHFrameSectionName)) {
jitlink::SectionRange R(*EHFrameSection);
if (!R.empty())
POSR.EHFrameSection = {ExecutorAddr(R.getStart()),
@@ -734,10 +722,10 @@ void ELFNixPlatform::ELFNixPlatformPlugin::addEHAndTLVSupportPasses(
// Get a pointer to the thread data section if there is one. It will be used
// below.
jitlink::Section *ThreadDataSection =
- G.findSectionByName(ThreadDataSectionName);
+ G.findSectionByName(ELFThreadDataSectionName);
// Handle thread BSS section if there is one.
- if (auto *ThreadBSSSection = G.findSectionByName(ThreadBSSSectionName)) {
+ if (auto *ThreadBSSSection = G.findSectionByName(ELFThreadBSSSectionName)) {
// If there's already a thread data section in this graph then merge the
// thread BSS section content into it, otherwise just treat the thread
// BSS section as the thread data section.
@@ -781,7 +769,7 @@ Error ELFNixPlatform::ELFNixPlatformPlugin::preserveInitSections(
JITLinkSymbolSet InitSectionSymbols;
for (auto &InitSection : G.sections()) {
// Skip non-init sections.
- if (!isInitializerSection(InitSection.getName()))
+ if (!isELFInitializerSection(InitSection.getName()))
continue;
// Make a pass over live symbols in the section: those blocks are already
@@ -819,7 +807,7 @@ Error ELFNixPlatform::ELFNixPlatformPlugin::registerInitSections(
LLVM_DEBUG({ dbgs() << "ELFNixPlatform::registerInitSections\n"; });
for (auto &Sec : G.sections()) {
- if (isInitializerSection(Sec.getName())) {
+ if (isELFInitializerSection(Sec.getName())) {
InitSections.push_back(&Sec);
}
}
diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index 914a1b5afc71..2918d275c092 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -13,6 +13,7 @@
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
#include "llvm/ExecutionEngine/Orc/LookupAndRecordAddrs.h"
+#include "llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h"
#include "llvm/Support/BinaryByteStream.h"
#include "llvm/Support/Debug.h"
#include <optional>
@@ -246,25 +247,6 @@ class MachOPlatformCompleteBootstrapMaterializationUnit
ExecutorAddr MachOHeaderAddr;
};
-StringRef DataCommonSectionName = "__DATA,__common";
-StringRef DataDataSectionName = "__DATA,__data";
-StringRef EHFrameSectionName = "__TEXT,__eh_frame";
-StringRef CompactUnwindInfoSectionName = "__TEXT,__unwind_info";
-StringRef ModInitFuncSectionName = "__DATA,__mod_init_func";
-StringRef ObjCClassListSectionName = "__DATA,__objc_classlist";
-StringRef ObjCImageInfoSectionName = "__DATA,__objc_image_info";
-StringRef ObjCSelRefsSectionName = "__DATA,__objc_selrefs";
-StringRef Swift5ProtoSectionName = "__TEXT,__swift5_proto";
-StringRef Swift5ProtosSectionName = "__TEXT,__swift5_protos";
-StringRef Swift5TypesSectionName = "__TEXT,__swift5_types";
-StringRef ThreadBSSSectionName = "__DATA,__thread_bss";
-StringRef ThreadDataSectionName = "__DATA,__thread_data";
-StringRef ThreadVarsSectionName = "__DATA,__thread_vars";
-
-StringRef InitSectionNames[] = {
- ModInitFuncSectionName, ObjCSelRefsSectionName, ObjCClassListSectionName,
- Swift5ProtosSectionName, Swift5ProtoSectionName, Swift5TypesSectionName};
-
} // end anonymous namespace
namespace llvm {
@@ -398,15 +380,6 @@ MachOPlatform::standardRuntimeUtilityAliases() {
StandardRuntimeUtilityAliases);
}
-bool MachOPlatform::isInitializerSection(StringRef SegName,
- StringRef SectName) {
- for (auto &Name : InitSectionNames) {
- if (Name.startswith(SegName) && Name.substr(7) == SectName)
- return true;
- }
- return false;
-}
-
bool MachOPlatform::supportedTarget(const Triple &TT) {
switch (TT.getArch()) {
case Triple::aarch64:
@@ -902,7 +875,7 @@ Error MachOPlatform::MachOPlatformPlugin::preserveInitSections(
jitlink::LinkGraph &G, MaterializationResponsibility &MR) {
JITLinkSymbolSet InitSectionSymbols;
- for (auto &InitSectionName : InitSectionNames) {
+ for (auto &InitSectionName : MachOInitSectionNames) {
// Skip non-init sections.
auto *InitSection = G.findSectionByName(InitSectionName);
if (!InitSection)
@@ -944,7 +917,7 @@ Error MachOPlatform::MachOPlatformPlugin::processObjCImageInfo(
// OR
// (2) We already have a recorded __objc_imageinfo for this JITDylib,
// in which case we just verify it.
- auto *ObjCImageInfo = G.findSectionByName(ObjCImageInfoSectionName);
+ auto *ObjCImageInfo = G.findSectionByName(MachOObjCImageInfoSectionName);
if (!ObjCImageInfo)
return Error::success();
@@ -952,14 +925,14 @@ Error MachOPlatform::MachOPlatformPlugin::processObjCImageInfo(
// Check that the section is not empty if present.
if (ObjCImageInfoBlocks.empty())
- return make_error<StringError>("Empty " + ObjCImageInfoSectionName +
+ return make_error<StringError>("Empty " + MachOObjCImageInfoSectionName +
" section in " + G.getName(),
inconvertibleErrorCode());
// Check that there's only one block in the section.
if (std::next(ObjCImageInfoBlocks.begin()) != ObjCImageInfoBlocks.end())
return make_error<StringError>("Multiple blocks in " +
- ObjCImageInfoSectionName +
+ MachOObjCImageInfoSectionName +
" section in " + G.getName(),
inconvertibleErrorCode());
@@ -971,7 +944,7 @@ Error MachOPlatform::MachOPlatformPlugin::processObjCImageInfo(
for (auto &E : B->edges())
if (E.getTarget().isDefined() &&
&E.getTarget().getBlock().getSection() == ObjCImageInfo)
- return make_error<StringError>(ObjCImageInfoSectionName +
+ return make_error<StringError>(MachOObjCImageInfoSectionName +
" is referenced within file " +
G.getName(),
inconvertibleErrorCode());
@@ -1024,7 +997,7 @@ Error MachOPlatform::MachOPlatformPlugin::fixTLVSectionsAndEdges(
}
// Store key in __thread_vars struct fields.
- if (auto *ThreadDataSec = G.findSectionByName(ThreadVarsSectionName)) {
+ if (auto *ThreadDataSec = G.findSectionByName(MachOThreadVarsSectionName)) {
std::optional<uint64_t> Key;
{
std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
@@ -1098,10 +1071,11 @@ MachOPlatform::MachOPlatformPlugin::findUnwindSectionInfo(
}
};
- if (Section *EHFrameSec = G.findSectionByName(EHFrameSectionName))
+ if (Section *EHFrameSec = G.findSectionByName(MachOEHFrameSectionName))
ScanUnwindInfoSection(*EHFrameSec, US.DwarfSection);
- if (Section *CUInfoSec = G.findSectionByName(CompactUnwindInfoSectionName))
+ if (Section *CUInfoSec =
+ G.findSectionByName(MachOCompactUnwindInfoSectionName))
ScanUnwindInfoSection(*CUInfoSec, US.CompactUnwindSection);
// If we didn't find any pointed-to code-blocks then there's no need to
@@ -1150,10 +1124,10 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
// Get a pointer to the thread data section if there is one. It will be used
// below.
jitlink::Section *ThreadDataSection =
- G.findSectionByName(ThreadDataSectionName);
+ G.findSectionByName(MachOThreadDataSectionName);
// Handle thread BSS section if there is one.
- if (auto *ThreadBSSSection = G.findSectionByName(ThreadBSSSectionName)) {
+ if (auto *ThreadBSSSection = G.findSectionByName(MachOThreadBSSSectionName)) {
// If there's already a thread data section in this graph then merge the
// thread BSS section content into it, otherwise just treat the thread
// BSS section as the thread data section.
@@ -1166,8 +1140,9 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
SmallVector<std::pair<StringRef, ExecutorAddrRange>, 8> MachOPlatformSecs;
// Collect data sections to register.
- StringRef DataSections[] = {DataDataSectionName, DataCommonSectionName,
- EHFrameSectionName};
+ StringRef DataSections[] = {MachODataDataSectionName,
+ MachODataCommonSectionName,
+ MachOEHFrameSectionName};
for (auto &SecName : DataSections) {
if (auto *Sec = G.findSectionByName(SecName)) {
jitlink::SectionRange R(*Sec);
@@ -1181,16 +1156,16 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
if (ThreadDataSection) {
jitlink::SectionRange R(*ThreadDataSection);
if (!R.empty())
- MachOPlatformSecs.push_back({ThreadDataSectionName, R.getRange()});
+ MachOPlatformSecs.push_back({MachOThreadDataSectionName, R.getRange()});
}
// If any platform sections were found then add an allocation action to call
// the registration function.
StringRef PlatformSections[] = {
- ModInitFuncSectionName, ObjCClassListSectionName,
- ObjCImageInfoSectionName, ObjCSelRefsSectionName,
- Swift5ProtoSectionName, Swift5ProtosSectionName,
- Swift5TypesSectionName,
+ MachOModInitFuncSectionName, MachOObjCClassListSectionName,
+ MachOObjCImageInfoSectionName, MachOObjCSelRefsSectionName,
+ MachOSwift5ProtoSectionName, MachOSwift5ProtosSectionName,
+ MachOSwift5TypesSectionName,
};
for (auto &SecName : PlatformSections) {
diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp
index 0c3beba43a35..7c8fa63477d0 100644
--- a/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp
@@ -10,6 +10,7 @@
#include "llvm/ExecutionEngine/Orc/COFFPlatform.h"
#include "llvm/ExecutionEngine/Orc/ELFNixPlatform.h"
#include "llvm/ExecutionEngine/Orc/MachOPlatform.h"
+#include "llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/MachO.h"
@@ -85,7 +86,7 @@ getMachOObjectFileSymbolInfo(ExecutionSession &ES,
}
auto SegName = Obj.getSectionFinalSegmentName(Sec.getRawDataRefImpl());
auto SecName = cantFail(Obj.getSectionName(Sec.getRawDataRefImpl()));
- if (MachOPlatform::isInitializerSection(SegName, SecName)) {
+ if (isMachOInitializerSection(SegName, SecName)) {
addInitSymbol(I, ES, Obj.getFileName());
break;
}
@@ -138,7 +139,7 @@ getELFObjectFileSymbolInfo(ExecutionSession &ES,
SymbolStringPtr InitSymbol;
for (auto &Sec : Obj.sections()) {
if (auto SecName = Sec.getName()) {
- if (ELFNixPlatform::isInitializerSection(*SecName)) {
+ if (isELFInitializerSection(*SecName)) {
addInitSymbol(I, ES, Obj.getFileName());
break;
}
@@ -219,7 +220,7 @@ getCOFFObjectFileSymbolInfo(ExecutionSession &ES,
SymbolStringPtr InitSymbol;
for (auto &Sec : Obj.sections()) {
if (auto SecName = Sec.getName()) {
- if (COFFPlatform::isInitializerSection(*SecName)) {
+ if (isCOFFInitializerSection(*SecName)) {
addInitSymbol(I, ES, Obj.getFileName());
break;
}
@@ -287,22 +288,5 @@ getObjectFileInterface(ExecutionSession &ES, MemoryBufferRef ObjBuffer) {
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.
diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
index b8899925382c..e7356e5d3151 100644
--- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
@@ -10,6 +10,7 @@
#include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h"
#include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
#include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h"
+#include "llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h"
#include "llvm/Support/MemoryBuffer.h"
#include <string>
#include <vector>
@@ -22,6 +23,22 @@ using namespace llvm::orc;
namespace {
+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 && isMachOInitializerSection(Sec.getName()))
+ return true;
+ if (IsElf && isELFInitializerSection(Sec.getName()))
+ return true;
+ }
+
+ return false;
+}
+
JITSymbolFlags getJITSymbolFlagsForSymbol(Symbol &Sym) {
JITSymbolFlags Flags;
diff --git a/llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt b/llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt
index b4e1b8a88c24..985ac6f1409e 100644
--- a/llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt
+++ b/llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt
@@ -1,5 +1,6 @@
add_llvm_component_library(LLVMOrcShared
AllocationActions.cpp
+ ObjectFormats.cpp
OrcError.cpp
OrcRTBridge.cpp
SimpleRemoteEPCUtils.cpp
diff --git a/llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp b/llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp
new file mode 100644
index 000000000000..2e867f58cc33
--- /dev/null
+++ b/llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp
@@ -0,0 +1,74 @@
+//===---------- ObjectFormats.cpp - Object format details for ORC ---------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// ORC-specific object format details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h"
+
+namespace llvm {
+namespace orc {
+
+StringRef MachODataCommonSectionName = "__DATA,__common";
+StringRef MachODataDataSectionName = "__DATA,__data";
+StringRef MachOEHFrameSectionName = "__TEXT,__eh_frame";
+StringRef MachOCompactUnwindInfoSectionName = "__TEXT,__unwind_info";
+StringRef MachOModInitFuncSectionName = "__DATA,__mod_init_func";
+StringRef MachOObjCClassListSectionName = "__DATA,__objc_classlist";
+StringRef MachOObjCImageInfoSectionName = "__DATA,__objc_image_info";
+StringRef MachOObjCSelRefsSectionName = "__DATA,__objc_selrefs";
+StringRef MachOSwift5ProtoSectionName = "__TEXT,__swift5_proto";
+StringRef MachOSwift5ProtosSectionName = "__TEXT,__swift5_protos";
+StringRef MachOSwift5TypesSectionName = "__TEXT,__swift5_types";
+StringRef MachOThreadBSSSectionName = "__DATA,__thread_bss";
+StringRef MachOThreadDataSectionName = "__DATA,__thread_data";
+StringRef MachOThreadVarsSectionName = "__DATA,__thread_vars";
+
+StringRef MachOInitSectionNames[6] = {
+ MachOModInitFuncSectionName, MachOObjCSelRefsSectionName,
+ MachOObjCClassListSectionName, MachOSwift5ProtosSectionName,
+ MachOSwift5ProtoSectionName, MachOSwift5TypesSectionName};
+
+StringRef ELFEHFrameSectionName = ".eh_frame";
+StringRef ELFInitArrayFuncSectionName = ".init_array";
+
+StringRef ELFThreadBSSSectionName = ".tbss";
+StringRef ELFThreadDataSectionName = ".tdata";
+
+bool isMachOInitializerSection(StringRef SegName, StringRef SecName) {
+ for (auto &InitSection : MachOInitSectionNames) {
+ // Loop below assumes all MachO init sectios have a length-6
+ // segment name.
+ assert(InitSection[6] == ',' && "Init section seg name has length != 6");
+ if (InitSection.starts_with(SegName) && InitSection.substr(7) == SecName)
+ return true;
+ }
+ return false;
+}
+
+bool isMachOInitializerSection(StringRef QualifiedName) {
+ for (auto &InitSection : MachOInitSectionNames)
+ if (InitSection == QualifiedName)
+ return true;
+ return false;
+}
+
+bool isELFInitializerSection(StringRef SecName) {
+ if (SecName.consume_front(ELFInitArrayFuncSectionName) &&
+ (SecName.empty() || SecName[0] == '.'))
+ return true;
+ return false;
+}
+
+bool isCOFFInitializerSection(StringRef SecName) {
+ return SecName.startswith(".CRT");
+}
+
+} // namespace orc
+} // namespace llvm
diff --git a/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt b/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt
index eddcb2ea16ca..1a71a62d3756 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt
+++ b/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt
@@ -2,10 +2,7 @@ set(LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
JITLink
Object
- OrcJIT
OrcShared
- OrcTargetProcess
- RuntimeDyld
Support
TargetParser
)
diff --git a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
index b7a1857b2d8a..6569bb0fd2dd 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
@@ -711,48 +711,3 @@ TEST(LinkGraphTest, SplitBlock) {
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)));
diff --git a/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt b/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
index 7df4213ef4ad..37768e91fd44 100644
--- a/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
+++ b/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
@@ -27,6 +27,7 @@ add_llvm_unittest(OrcJITTests
LookupAndRecordAddrsTest.cpp
MapperJITLinkMemoryManagerTest.cpp
MemoryMapperTest.cpp
+ ObjectFormatsTest.cpp
ObjectLinkingLayerTest.cpp
OrcCAPITest.cpp
OrcTestCommon.cpp
diff --git a/llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp
new file mode 100644
index 000000000000..13cffb1a02f5
--- /dev/null
+++ b/llvm/unittests/ExecutionEngine/Orc/ObjectFormatsTest.cpp
@@ -0,0 +1,33 @@
+//===-------- ObjectLinkingLayerTest.cpp - ObjectLinkingLayer tests -------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::orc;
+
+namespace {
+
+TEST(ObjectFormatsTest, MachOInitializerSections) {
+ EXPECT_TRUE(isMachOInitializerSection("__DATA,__objc_selrefs"));
+ EXPECT_TRUE(isMachOInitializerSection("__DATA,__mod_init_func"));
+ EXPECT_TRUE(isMachOInitializerSection("__DATA,__objc_classlist"));
+ EXPECT_TRUE(isMachOInitializerSection("__TEXT,__swift5_proto"));
+ EXPECT_TRUE(isMachOInitializerSection("__TEXT,__swift5_protos"));
+ EXPECT_TRUE(isMachOInitializerSection("__TEXT,__swift5_types"));
+ EXPECT_FALSE(isMachOInitializerSection("__DATA,__not_an_init_sec"));
+}
+
+TEST(ObjectFormatsTest, ELFInitializerSections) {
+ EXPECT_TRUE(isELFInitializerSection(".init_array"));
+ EXPECT_TRUE(isELFInitializerSection(".init_array.0"));
+ EXPECT_FALSE(isELFInitializerSection(".text"));
+}
+
+} // end anonymous namespace
More information about the llvm-commits
mailing list