mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-03 05:32:24 +00:00
[llvm-libtools-darwin] Don't use global LLVMContext
Fixes some initialization order fiasco issues https://lab.llvm.org/buildbot#builders/5/builds/20996
This commit is contained in:
parent
a3248e4b28
commit
3210647e5b
@ -32,8 +32,6 @@
|
||||
using namespace llvm;
|
||||
using namespace llvm::object;
|
||||
|
||||
static LLVMContext LLVMCtx;
|
||||
|
||||
class NewArchiveMemberList;
|
||||
typedef std::map<uint64_t, NewArchiveMemberList> MembersPerArchitectureMap;
|
||||
|
||||
@ -269,7 +267,8 @@ public:
|
||||
// the user.
|
||||
class MembersBuilder {
|
||||
public:
|
||||
MembersBuilder(const Config &C) : C(C) {}
|
||||
MembersBuilder(LLVMContext &LLVMCtx, const Config &C)
|
||||
: LLVMCtx(LLVMCtx), C(C) {}
|
||||
|
||||
Expected<MembersData> build() {
|
||||
for (StringRef FileName : InputFiles)
|
||||
@ -396,7 +395,7 @@ private:
|
||||
Error verifyAndAddIRObject(NewArchiveMember Member) {
|
||||
auto MBRef = Member.Buf->getMemBufferRef();
|
||||
Expected<std::unique_ptr<object::IRObjectFile>> IROrErr =
|
||||
object::IRObjectFile::create(MBRef, LLVMCtx);
|
||||
object::IRObjectFile::create(MBRef, Builder.LLVMCtx);
|
||||
|
||||
// Throw error if not a valid IR object file.
|
||||
if (!IROrErr)
|
||||
@ -488,7 +487,7 @@ private:
|
||||
}
|
||||
|
||||
Expected<std::unique_ptr<IRObjectFile>> IRObjectOrError =
|
||||
O.getAsIRObject(LLVMCtx);
|
||||
O.getAsIRObject(Builder.LLVMCtx);
|
||||
if (IRObjectOrError) {
|
||||
// A universal file member can be a MachOObjectFile, an IRObject or an
|
||||
// Archive. In case we can successfully cast the member as an
|
||||
@ -533,11 +532,13 @@ private:
|
||||
};
|
||||
|
||||
MembersData Data;
|
||||
LLVMContext &LLVMCtx;
|
||||
const Config &C;
|
||||
};
|
||||
|
||||
static Expected<SmallVector<Slice, 2>>
|
||||
buildSlices(ArrayRef<OwningBinary<Archive>> OutputBinaries) {
|
||||
buildSlices(LLVMContext &LLVMCtx,
|
||||
ArrayRef<OwningBinary<Archive>> OutputBinaries) {
|
||||
SmallVector<Slice, 2> Slices;
|
||||
|
||||
for (const auto &OB : OutputBinaries) {
|
||||
@ -585,8 +586,8 @@ checkForDuplicates(const MembersPerArchitectureMap &MembersPerArch) {
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
static Error createStaticLibrary(const Config &C) {
|
||||
MembersBuilder Builder(C);
|
||||
static Error createStaticLibrary(LLVMContext &LLVMCtx, const Config &C) {
|
||||
MembersBuilder Builder(LLVMCtx, C);
|
||||
auto DataOrError = Builder.build();
|
||||
if (auto Error = DataOrError.takeError())
|
||||
return Error;
|
||||
@ -627,7 +628,7 @@ static Error createStaticLibrary(const Config &C) {
|
||||
OwningBinary<Archive>(std::move(A), std::move(OutputBuffer)));
|
||||
}
|
||||
|
||||
Expected<SmallVector<Slice, 2>> Slices = buildSlices(OutputBinaries);
|
||||
Expected<SmallVector<Slice, 2>> Slices = buildSlices(LLVMCtx, OutputBinaries);
|
||||
if (!Slices)
|
||||
return Slices.takeError();
|
||||
|
||||
@ -702,12 +703,13 @@ int main(int Argc, char **Argv) {
|
||||
llvm::InitializeAllTargetMCs();
|
||||
llvm::InitializeAllAsmParsers();
|
||||
|
||||
LLVMContext LLVMCtx;
|
||||
Config C = *ConfigOrErr;
|
||||
switch (LibraryOperation) {
|
||||
case Operation::None:
|
||||
break;
|
||||
case Operation::Static:
|
||||
if (Error E = createStaticLibrary(C)) {
|
||||
if (Error E = createStaticLibrary(LLVMCtx, C)) {
|
||||
WithColor::defaultErrorHandler(std::move(E));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user