Skip to content

Commit 480fa7c

Browse files
z0w0graydon
authored andcommitted
Only initialize targets that are actually supported / linked to in RustWrapper
1 parent de5c15e commit 480fa7c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/rustllvm/RustWrapper.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ extern "C" bool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src) {
7575
return true;
7676
}
7777

78+
void LLVMInitializeX86TargetInfo();
79+
void LLVMInitializeX86Target();
80+
void LLVMInitializeX86TargetMC();
81+
void LLVMInitializeX86AsmPrinter();
82+
void LLVMInitializeX86AsmParser();
83+
7884
extern "C" bool
7985
LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
8086
LLVMModuleRef M,
@@ -84,10 +90,16 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
8490
CodeGenOpt::Level OptLevel,
8591
bool EnableSegmentedStacks) {
8692

87-
InitializeAllTargets();
88-
InitializeAllTargetMCs();
89-
InitializeAllAsmPrinters();
90-
InitializeAllAsmParsers();
93+
// Only initialize the platforms supported by Rust here,
94+
// because using --llvm-root will have multiple platforms
95+
// that rustllvm doesn't actually link to and it's pointless to put target info
96+
// into the registry that Rust can not generate machine code for.
97+
98+
LLVMInitializeX86TargetInfo();
99+
LLVMInitializeX86Target();
100+
LLVMInitializeX86TargetMC();
101+
LLVMInitializeX86AsmPrinter();
102+
LLVMInitializeX86AsmParser();
91103

92104
TargetOptions Options;
93105
Options.NoFramePointerElim = true;

src/rustllvm/rustllvm.def.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ LLVMInitializeX86Disassembler
390390
LLVMInitializeX86Disassembler
391391
LLVMInitializeX86Target
392392
LLVMInitializeX86Target
393+
LLVMInitializeX86TargetMC
394+
LLVMInitializeX86TargetMC
393395
LLVMInitializeX86TargetInfo
394396
LLVMInitializeX86TargetInfo
395397
LLVMInsertBasicBlock

0 commit comments

Comments
 (0)