[llvm] 777824b - [llvm-jitlink] Add support for static archives and MachO universal archives.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 3 13:00:50 PDT 2020
Author: Lang Hames
Date: 2020-08-03T12:58:00-07:00
New Revision: 777824b49d5d9e1fbc93108107fa6d12a936a2e4
URL: https://github.com/llvm/llvm-project/commit/777824b49d5d9e1fbc93108107fa6d12a936a2e4
DIFF: https://github.com/llvm/llvm-project/commit/777824b49d5d9e1fbc93108107fa6d12a936a2e4.diff
LOG: [llvm-jitlink] Add support for static archives and MachO universal archives.
Archives can now be specified as input files the same way that object
files are. Archives will always be linked after all objects (regardless
of the relative order of the inputs) but before any dynamic libraries or
process symbols.
This patch also relaxes matching for slice triples in
StaticLibraryDefinitionGenerator in order to support this feature:
Vendors need not match if the source vendor is unknown.
Added:
Modified:
llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
llvm/tools/llvm-jitlink/llvm-jitlink.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
index 4d255cd66c1b..278f492f0ebe 100644
--- a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
@@ -322,7 +322,8 @@ StaticLibraryDefinitionGenerator::Load(ObjectLayer &L, const char *FileName,
auto ObjTT = Obj.getTriple();
if (ObjTT.getArch() == TT.getArch() &&
ObjTT.getSubArch() == TT.getSubArch() &&
- ObjTT.getVendor() == TT.getVendor()) {
+ (TT.getVendor() == Triple::UnknownVendor ||
+ ObjTT.getVendor() == TT.getVendor())) {
// We found a match. Create an instance from a buffer covering this
// slice.
auto SliceBuffer = MemoryBuffer::getFileSlice(FileName, Obj.getSize(),
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 798087d8cae7..d5dc661cc69f 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -14,6 +14,7 @@
#include "llvm-jitlink.h"
+#include "llvm/BinaryFormat/Magic.h"
#include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h"
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
#include "llvm/MC/MCAsmInfo.h"
@@ -887,13 +888,20 @@ Error loadObjects(Session &S) {
InputFileItr != InputFileEnd; ++InputFileItr) {
unsigned InputFileArgIdx =
InputFiles.getPosition(InputFileItr - InputFiles.begin());
- StringRef InputFile = *InputFileItr;
+ const std::string &InputFile = *InputFileItr;
auto &JD = *std::prev(IdxToJLD.lower_bound(InputFileArgIdx))->second;
LLVM_DEBUG(dbgs() << " " << InputFileArgIdx << ": \"" << InputFile
<< "\" to " << JD.getName() << "\n";);
auto ObjBuffer =
ExitOnErr(errorOrToExpected(MemoryBuffer::getFile(InputFile)));
- ExitOnErr(S.ObjLayer.add(JD, std::move(ObjBuffer)));
+
+ auto Magic = identify_magic(ObjBuffer->getBuffer());
+ if (Magic == file_magic::archive ||
+ Magic == file_magic::macho_universal_binary)
+ JD.addGenerator(ExitOnErr(StaticLibraryDefinitionGenerator::Load(
+ S.ObjLayer, InputFile.c_str(), S.TT)));
+ else
+ ExitOnErr(S.ObjLayer.add(JD, std::move(ObjBuffer)));
}
// Define absolute symbols.
@@ -1056,6 +1064,11 @@ int main(int argc, char *argv[]) {
ExitOnErr(sanitizeArguments(*S));
+ {
+ TimeRegion TR(Timers ? &Timers->LoadObjectsTimer : nullptr);
+ ExitOnErr(loadObjects(*S));
+ }
+
if (!NoProcessSymbols)
ExitOnErr(loadProcessSymbols(*S));
ExitOnErr(loadDylibs());
@@ -1063,10 +1076,6 @@ int main(int argc, char *argv[]) {
if (PhonyExternals)
addPhonyExternalsGenerator(*S);
- {
- TimeRegion TR(Timers ? &Timers->LoadObjectsTimer : nullptr);
- ExitOnErr(loadObjects(*S));
- }
if (ShowInitialExecutionSessionState)
S->ES.dump(outs());
More information about the llvm-commits
mailing list