mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:02:41 +01:00
Re-re-revert "[ORC][ORC-RT] Add initial native-TLV support to MachOPlatform."
This reverts commit 6b2a96285b9bbe92d2c5e21830f21458f8be976d. The ccache builders are still failing. Looks like they need to be updated to get the llvm-zorg config change in 490633945677656ba75d42ff1ca9d4a400b7b243. I'll re-apply this as soon as the builders are updated.
This commit is contained in:
parent
2182633955
commit
549c960a94
@ -29,7 +29,6 @@ namespace orc {
|
||||
|
||||
struct MachOPerObjectSectionsToRegister {
|
||||
ExecutorAddressRange EHFrameSection;
|
||||
ExecutorAddressRange ThreadDataSection;
|
||||
};
|
||||
|
||||
struct MachOJITDylibInitializers {
|
||||
@ -159,7 +158,7 @@ private:
|
||||
void addMachOHeaderSupportPasses(MaterializationResponsibility &MR,
|
||||
jitlink::PassConfiguration &Config);
|
||||
|
||||
void addEHAndTLVSupportPasses(MaterializationResponsibility &MR,
|
||||
void addEHSupportPasses(MaterializationResponsibility &MR,
|
||||
jitlink::PassConfiguration &Config);
|
||||
|
||||
Error preserveInitSections(jitlink::LinkGraph &G,
|
||||
@ -167,8 +166,6 @@ private:
|
||||
|
||||
Error registerInitSections(jitlink::LinkGraph &G, JITDylib &JD);
|
||||
|
||||
Error fixTLVSectionsAndEdges(jitlink::LinkGraph &G, JITDylib &JD);
|
||||
|
||||
std::mutex PluginMutex;
|
||||
MachOPlatform ∓
|
||||
InitSymbolDepMap InitSymbolDeps;
|
||||
@ -216,8 +213,6 @@ private:
|
||||
|
||||
Error registerPerObjectSections(const MachOPerObjectSectionsToRegister &POSR);
|
||||
|
||||
Expected<uint64_t> createPThreadKey();
|
||||
|
||||
ExecutionSession &ES;
|
||||
ObjectLinkingLayer &ObjLinkingLayer;
|
||||
ExecutorProcessControl &EPC;
|
||||
@ -228,7 +223,6 @@ private:
|
||||
ExecutorAddress orc_rt_macho_platform_bootstrap;
|
||||
ExecutorAddress orc_rt_macho_platform_shutdown;
|
||||
ExecutorAddress orc_rt_macho_register_object_sections;
|
||||
ExecutorAddress orc_rt_macho_create_pthread_key;
|
||||
|
||||
DenseMap<JITDylib *, SymbolLookupSet> RegisteredInitSymbols;
|
||||
|
||||
@ -239,13 +233,11 @@ private:
|
||||
std::vector<MachOPerObjectSectionsToRegister> BootstrapPOSRs;
|
||||
|
||||
DenseMap<JITTargetAddress, JITDylib *> HeaderAddrToJITDylib;
|
||||
DenseMap<JITDylib *, uint64_t> JITDylibToPThreadKey;
|
||||
};
|
||||
|
||||
namespace shared {
|
||||
|
||||
using SPSMachOPerObjectSectionsToRegister =
|
||||
SPSTuple<SPSExecutorAddressRange, SPSExecutorAddressRange>;
|
||||
using SPSMachOPerObjectSectionsToRegister = SPSTuple<SPSExecutorAddressRange>;
|
||||
|
||||
template <>
|
||||
class SPSSerializationTraits<SPSMachOPerObjectSectionsToRegister,
|
||||
@ -254,19 +246,19 @@ class SPSSerializationTraits<SPSMachOPerObjectSectionsToRegister,
|
||||
public:
|
||||
static size_t size(const MachOPerObjectSectionsToRegister &MOPOSR) {
|
||||
return SPSMachOPerObjectSectionsToRegister::AsArgList::size(
|
||||
MOPOSR.EHFrameSection, MOPOSR.ThreadDataSection);
|
||||
MOPOSR.EHFrameSection);
|
||||
}
|
||||
|
||||
static bool serialize(SPSOutputBuffer &OB,
|
||||
const MachOPerObjectSectionsToRegister &MOPOSR) {
|
||||
return SPSMachOPerObjectSectionsToRegister::AsArgList::serialize(
|
||||
OB, MOPOSR.EHFrameSection, MOPOSR.ThreadDataSection);
|
||||
OB, MOPOSR.EHFrameSection);
|
||||
}
|
||||
|
||||
static bool deserialize(SPSInputBuffer &IB,
|
||||
MachOPerObjectSectionsToRegister &MOPOSR) {
|
||||
return SPSMachOPerObjectSectionsToRegister::AsArgList::deserialize(
|
||||
IB, MOPOSR.EHFrameSection, MOPOSR.ThreadDataSection);
|
||||
IB, MOPOSR.EHFrameSection);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -313,14 +313,6 @@ private:
|
||||
Addend = *(const little32_t *)FixupContent - 4;
|
||||
Kind = x86_64::RequestGOTAndTransformToDelta32;
|
||||
break;
|
||||
case MachOPCRel32TLV:
|
||||
if (auto TargetSymbolOrErr = findSymbolByIndex(RI.r_symbolnum))
|
||||
TargetSymbol = TargetSymbolOrErr->GraphSymbol;
|
||||
else
|
||||
return TargetSymbolOrErr.takeError();
|
||||
Addend = *(const little32_t *)FixupContent;
|
||||
Kind = x86_64::RequestTLVPAndTransformToPCRel32TLVPLoadRelaxable;
|
||||
break;
|
||||
case MachOPointer32:
|
||||
if (auto TargetSymbolOrErr = findSymbolByIndex(RI.r_symbolnum))
|
||||
TargetSymbol = TargetSymbolOrErr->GraphSymbol;
|
||||
@ -400,6 +392,9 @@ private:
|
||||
assert(TargetSymbol && "No target symbol from parsePairRelocation?");
|
||||
break;
|
||||
}
|
||||
case MachOPCRel32TLV:
|
||||
return make_error<JITLinkError>(
|
||||
"MachO TLV relocations not yet supported");
|
||||
}
|
||||
|
||||
LLVM_DEBUG({
|
||||
|
@ -128,9 +128,6 @@ constexpr MachOHeaderMaterializationUnit::HeaderSymbol
|
||||
|
||||
StringRef EHFrameSectionName = "__TEXT,__eh_frame";
|
||||
StringRef ModInitFuncSectionName = "__DATA,__mod_init_func";
|
||||
StringRef ThreadBSSSectionName = "__DATA,__thread_bss";
|
||||
StringRef ThreadDataSectionName = "__DATA,__thread_data";
|
||||
StringRef ThreadVarsSectionName = "__DATA,__thread_vars";
|
||||
|
||||
StringRef InitSectionNames[] = {ModInitFuncSectionName};
|
||||
|
||||
@ -470,8 +467,7 @@ Error MachOPlatform::bootstrapMachORuntime(JITDylib &PlatformJD) {
|
||||
{"___orc_rt_macho_platform_bootstrap", &orc_rt_macho_platform_bootstrap},
|
||||
{"___orc_rt_macho_platform_shutdown", &orc_rt_macho_platform_shutdown},
|
||||
{"___orc_rt_macho_register_object_sections",
|
||||
&orc_rt_macho_register_object_sections},
|
||||
{"___orc_rt_macho_create_pthread_key", &orc_rt_macho_create_pthread_key}};
|
||||
&orc_rt_macho_register_object_sections}};
|
||||
|
||||
SymbolLookupSet RuntimeSymbols;
|
||||
std::vector<std::pair<SymbolStringPtr, ExecutorAddress *>> AddrsToRecord;
|
||||
@ -566,20 +562,6 @@ Error MachOPlatform::registerPerObjectSections(
|
||||
return ErrResult;
|
||||
}
|
||||
|
||||
Expected<uint64_t> MachOPlatform::createPThreadKey() {
|
||||
if (!orc_rt_macho_create_pthread_key)
|
||||
return make_error<StringError>(
|
||||
"Attempting to create pthread key in target, but runtime support has "
|
||||
"not been loaded yet",
|
||||
inconvertibleErrorCode());
|
||||
|
||||
Expected<uint64_t> Result(0);
|
||||
if (auto Err = EPC.runSPSWrapper<SPSExpected<uint64_t>(void)>(
|
||||
orc_rt_macho_create_pthread_key.getValue(), Result))
|
||||
return std::move(Err);
|
||||
return Result;
|
||||
}
|
||||
|
||||
void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
|
||||
MaterializationResponsibility &MR, jitlink::LinkGraph &LG,
|
||||
jitlink::PassConfiguration &Config) {
|
||||
@ -597,8 +579,8 @@ void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
|
||||
if (MR.getInitializerSymbol())
|
||||
addInitializerSupportPasses(MR, Config);
|
||||
|
||||
// Add passes for eh-frame and TLV support.
|
||||
addEHAndTLVSupportPasses(MR, Config);
|
||||
// Add passes for eh-frame support.
|
||||
addEHSupportPasses(MR, Config);
|
||||
}
|
||||
|
||||
ObjectLinkingLayer::Plugin::SyntheticSymbolDependenciesMap
|
||||
@ -652,18 +634,10 @@ void MachOPlatform::MachOPlatformPlugin::addMachOHeaderSupportPasses(
|
||||
});
|
||||
}
|
||||
|
||||
void MachOPlatform::MachOPlatformPlugin::addEHAndTLVSupportPasses(
|
||||
void MachOPlatform::MachOPlatformPlugin::addEHSupportPasses(
|
||||
MaterializationResponsibility &MR, jitlink::PassConfiguration &Config) {
|
||||
|
||||
// Insert TLV lowering at the start of the PostPrunePasses, since we want
|
||||
// it to run before GOT/PLT lowering.
|
||||
Config.PostPrunePasses.insert(
|
||||
Config.PostPrunePasses.begin(),
|
||||
[this, &JD = MR.getTargetJITDylib()](jitlink::LinkGraph &G) {
|
||||
return fixTLVSectionsAndEdges(G, JD);
|
||||
});
|
||||
|
||||
// Add a pass to register the final addresses of the eh-frame and TLV sections
|
||||
// Add a pass to register the final addresses of the eh-frame sections
|
||||
// with the runtime.
|
||||
Config.PostFixupPasses.push_back([this](jitlink::LinkGraph &G) -> Error {
|
||||
MachOPerObjectSectionsToRegister POSR;
|
||||
@ -675,33 +649,7 @@ void MachOPlatform::MachOPlatformPlugin::addEHAndTLVSupportPasses(
|
||||
ExecutorAddress(R.getEnd())};
|
||||
}
|
||||
|
||||
// Get a pointer to the thread data section if there is one. It will be used
|
||||
// below.
|
||||
jitlink::Section *ThreadDataSection =
|
||||
G.findSectionByName(ThreadDataSectionName);
|
||||
|
||||
// Handle thread BSS section if there is one.
|
||||
if (auto *ThreadBSSSection = G.findSectionByName(ThreadBSSSectionName)) {
|
||||
// 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.
|
||||
if (ThreadDataSection)
|
||||
G.mergeSections(*ThreadDataSection, *ThreadBSSSection);
|
||||
else
|
||||
ThreadDataSection = ThreadBSSSection;
|
||||
}
|
||||
|
||||
// Having merged thread BSS (if present) and thread data (if present),
|
||||
// record the resulting section range.
|
||||
if (ThreadDataSection) {
|
||||
jitlink::SectionRange R(*ThreadDataSection);
|
||||
if (!R.empty())
|
||||
POSR.ThreadDataSection = {ExecutorAddress(R.getStart()),
|
||||
ExecutorAddress(R.getEnd())};
|
||||
}
|
||||
|
||||
if (POSR.EHFrameSection.StartAddress ||
|
||||
POSR.ThreadDataSection.StartAddress) {
|
||||
if (POSR.EHFrameSection.StartAddress) {
|
||||
|
||||
// If we're still bootstrapping the runtime then just record this
|
||||
// frame for now.
|
||||
@ -779,61 +727,5 @@ Error MachOPlatform::MachOPlatformPlugin::registerInitSections(
|
||||
return MP.registerInitInfo(JD, InitSections);
|
||||
}
|
||||
|
||||
Error MachOPlatform::MachOPlatformPlugin::fixTLVSectionsAndEdges(
|
||||
jitlink::LinkGraph &G, JITDylib &JD) {
|
||||
|
||||
// Rename external references to __tlv_bootstrap to ___orc_rt_tlv_get_addr.
|
||||
for (auto *Sym : G.external_symbols())
|
||||
if (Sym->getName() == "__tlv_bootstrap") {
|
||||
Sym->setName("___orc_rt_macho_tlv_get_addr");
|
||||
break;
|
||||
}
|
||||
|
||||
// Store key in __thread_vars struct fields.
|
||||
if (auto *ThreadDataSec = G.findSectionByName(ThreadVarsSectionName)) {
|
||||
Optional<uint64_t> Key;
|
||||
{
|
||||
std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
|
||||
auto I = MP.JITDylibToPThreadKey.find(&JD);
|
||||
if (I != MP.JITDylibToPThreadKey.end())
|
||||
Key = I->second;
|
||||
}
|
||||
|
||||
if (!Key) {
|
||||
if (auto KeyOrErr = MP.createPThreadKey())
|
||||
Key = *KeyOrErr;
|
||||
else
|
||||
return KeyOrErr.takeError();
|
||||
}
|
||||
|
||||
uint64_t PlatformKeyBits =
|
||||
support::endian::byte_swap(*Key, G.getEndianness());
|
||||
|
||||
for (auto *B : ThreadDataSec->blocks()) {
|
||||
if (B->getSize() != 3 * G.getPointerSize())
|
||||
return make_error<StringError>("__thread_vars block at " +
|
||||
formatv("{0:x}", B->getAddress()) +
|
||||
" has unexpected size",
|
||||
inconvertibleErrorCode());
|
||||
|
||||
auto NewBlockContent = G.allocateBuffer(B->getSize());
|
||||
llvm::copy(B->getContent(), NewBlockContent.data());
|
||||
memcpy(NewBlockContent.data() + G.getPointerSize(), &PlatformKeyBits,
|
||||
G.getPointerSize());
|
||||
B->setContent(NewBlockContent);
|
||||
}
|
||||
}
|
||||
|
||||
// Transform any TLV edges into GOT edges.
|
||||
for (auto *B : G.blocks())
|
||||
for (auto &E : B->edges())
|
||||
if (E.getKind() ==
|
||||
jitlink::x86_64::RequestTLVPAndTransformToPCRel32TLVPLoadRelaxable)
|
||||
E.setKind(
|
||||
jitlink::x86_64::RequestGOTAndTransformToPCRel32GOTLoadRelaxable);
|
||||
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
} // End namespace orc.
|
||||
} // End namespace llvm.
|
||||
|
Loading…
Reference in New Issue
Block a user