diff options
author | Lang Hames <lhames@gmail.com> | 2021-12-16 17:55:02 +1100 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2021-12-16 19:46:51 +1100 |
commit | 02fc8d5c9eb0703bb1863f22c2d27ff7a580f537 (patch) | |
tree | a3cb0ad653509622b8ceba845a75de2794e956ab /llvm/lib/ExecutionEngine/Orc | |
parent | 3eeeb6ec933366a1b4d5482f07ddc724001a6079 (diff) | |
download | llvm-02fc8d5c9eb0703bb1863f22c2d27ff7a580f537.zip llvm-02fc8d5c9eb0703bb1863f22c2d27ff7a580f537.tar.gz llvm-02fc8d5c9eb0703bb1863f22c2d27ff7a580f537.tar.bz2 |
[ORC] Add custom object interface support to StaticLibaryDefinitionGenerator.
This adds a GetObjectFileInterface callback member to
StaticLibraryDefinitionGenerator, and adds an optional argument for initializing
that member to StaticLibraryDefinitionGenerator's named constructors. If not
supplied, it will default to getObjectFileInterface from ObjectFileInterface.h.
To enable testing a `-hidden-l<x>` option is added to the llvm-jitlink tool.
This allows archives to be loaded with all contained symbol visibilities demoted
to hidden.
The ObjectLinkingLayer::setOverrideObjectFlagsWithResponsibilityFlags method is
(belatedly) hooked up, and enabled in llvm-jitlink when `-hidden-l<x>` is used
so that the demotion is also applied at symbol resolution time (avoiding any
"mismatched symbol flags" crashes).
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc')
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp | 44 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp | 11 |
2 files changed, 40 insertions, 15 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp index 2ab9ed4..ae2d47f 100644 --- a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp @@ -8,6 +8,7 @@ #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h" #include "llvm/ExecutionEngine/Orc/Layer.h" +#include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalVariable.h" @@ -269,25 +270,30 @@ Error DynamicLibrarySearchGenerator::tryToGenerate( } Expected<std::unique_ptr<StaticLibraryDefinitionGenerator>> -StaticLibraryDefinitionGenerator::Load(ObjectLayer &L, const char *FileName) { +StaticLibraryDefinitionGenerator::Load( + ObjectLayer &L, const char *FileName, + GetObjectFileInterface GetObjFileInterface) { auto ArchiveBuffer = errorOrToExpected(MemoryBuffer::getFile(FileName)); if (!ArchiveBuffer) return ArchiveBuffer.takeError(); - return Create(L, std::move(*ArchiveBuffer)); + return Create(L, std::move(*ArchiveBuffer), std::move(GetObjFileInterface)); } Expected<std::unique_ptr<StaticLibraryDefinitionGenerator>> -StaticLibraryDefinitionGenerator::Load(ObjectLayer &L, const char *FileName, - const Triple &TT) { +StaticLibraryDefinitionGenerator::Load( + ObjectLayer &L, const char *FileName, const Triple &TT, + GetObjectFileInterface GetObjFileInterface) { + auto B = object::createBinary(FileName); if (!B) return B.takeError(); // If this is a regular archive then create an instance from it. if (isa<object::Archive>(B->getBinary())) - return Create(L, std::move(B->takeBinary().second)); + return Create(L, std::move(B->takeBinary().second), + std::move(GetObjFileInterface)); // If this is a universal binary then search for a slice matching the given // Triple. @@ -309,7 +315,8 @@ StaticLibraryDefinitionGenerator::Load(ObjectLayer &L, const char *FileName, " .. " + formatv("{0:x}", Obj.getOffset() + Obj.getSize()) + ": " + SliceBuffer.getError().message(), SliceBuffer.getError()); - return Create(L, std::move(*SliceBuffer)); + return Create(L, std::move(*SliceBuffer), + std::move(GetObjFileInterface)); } } @@ -326,11 +333,13 @@ StaticLibraryDefinitionGenerator::Load(ObjectLayer &L, const char *FileName, Expected<std::unique_ptr<StaticLibraryDefinitionGenerator>> StaticLibraryDefinitionGenerator::Create( - ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer) { + ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer, + GetObjectFileInterface GetObjFileInterface) { Error Err = Error::success(); std::unique_ptr<StaticLibraryDefinitionGenerator> ADG( - new StaticLibraryDefinitionGenerator(L, std::move(ArchiveBuffer), Err)); + new StaticLibraryDefinitionGenerator( + L, std::move(ArchiveBuffer), std::move(GetObjFileInterface), Err)); if (Err) return std::move(Err); @@ -371,7 +380,12 @@ Error StaticLibraryDefinitionGenerator::tryToGenerate( MemoryBufferRef ChildBufferRef(ChildBufferInfo.first, ChildBufferInfo.second); - if (auto Err = L.add(JD, MemoryBuffer::getMemBuffer(ChildBufferRef, false))) + auto I = GetObjFileInterface(L.getExecutionSession(), ChildBufferRef); + if (!I) + return I.takeError(); + + if (auto Err = L.add(JD, MemoryBuffer::getMemBuffer(ChildBufferRef, false), + std::move(*I))) return Err; } @@ -379,9 +393,15 @@ Error StaticLibraryDefinitionGenerator::tryToGenerate( } StaticLibraryDefinitionGenerator::StaticLibraryDefinitionGenerator( - ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer, Error &Err) - : L(L), ArchiveBuffer(std::move(ArchiveBuffer)), - Archive(std::make_unique<object::Archive>(*this->ArchiveBuffer, Err)) {} + ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer, + GetObjectFileInterface GetObjFileInterface, Error &Err) + : L(L), GetObjFileInterface(std::move(GetObjFileInterface)), + ArchiveBuffer(std::move(ArchiveBuffer)), + Archive(std::make_unique<object::Archive>(*this->ArchiveBuffer, Err)) { + + if (!this->GetObjFileInterface) + this->GetObjFileInterface = getObjectFileInterface; +} } // End namespace orc. } // End namespace llvm. diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp index a6d3ca7..0d6a33c 100644 --- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp @@ -249,7 +249,8 @@ public: { - // Check that InternedResult matches up with MR->getSymbols(). + // Check that InternedResult matches up with MR->getSymbols(), overriding + // flags if requested. // This guards against faulty transformations / compilers / object caches. // First check that there aren't any missing symbols. @@ -258,16 +259,20 @@ public: SymbolNameVector MissingSymbols; for (auto &KV : MR->getSymbols()) { + auto I = InternedResult.find(KV.first); + // If this is a materialization-side-effects only symbol then bump // the counter and make sure it's *not* defined, otherwise make // sure that it is defined. if (KV.second.hasMaterializationSideEffectsOnly()) { ++NumMaterializationSideEffectsOnlySymbols; - if (InternedResult.count(KV.first)) + if (I != InternedResult.end()) ExtraSymbols.push_back(KV.first); continue; - } else if (!InternedResult.count(KV.first)) + } else if (I == InternedResult.end()) MissingSymbols.push_back(KV.first); + else if (Layer.OverrideObjectFlags) + I->second.setFlags(KV.second); } // If there were missing symbols then report the error. |