[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.
This commit is contained in:
Lang Hames 2020-08-03 11:55:57 -07:00
parent 4ea5511359
commit ec5336f4a3
2 changed files with 17 additions and 7 deletions

View File

@ -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(),

View File

@ -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());