Fix "static initialization order fiasco" for the XCore Target.

I fixed all the other Targets in r283702, and interestingly the
sanitizers are only now "sometimes" catching this bug on the only
one I missed.

llvm-svn: 283914
This commit is contained in:
Mehdi Amini 2016-10-11 18:22:41 +00:00
parent 76952a76e5
commit caec5559cb
6 changed files with 19 additions and 15 deletions

View File

@ -769,7 +769,7 @@ MCDisassembler::DecodeStatus XCoreDisassembler::getInstruction(
}
namespace llvm {
extern Target TheXCoreTarget;
Target &getTheXCoreTarget();
}
static MCDisassembler *createXCoreDisassembler(const Target &T,
@ -780,6 +780,6 @@ static MCDisassembler *createXCoreDisassembler(const Target &T,
extern "C" void LLVMInitializeXCoreDisassembler() {
// Register the disassembler.
TargetRegistry::RegisterMCDisassembler(TheXCoreTarget,
TargetRegistry::RegisterMCDisassembler(getTheXCoreTarget(),
createXCoreDisassembler);
}

View File

@ -124,26 +124,28 @@ static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
// Force static initialization.
extern "C" void LLVMInitializeXCoreTargetMC() {
// Register the MC asm info.
RegisterMCAsmInfoFn X(TheXCoreTarget, createXCoreMCAsmInfo);
RegisterMCAsmInfoFn X(getTheXCoreTarget(), createXCoreMCAsmInfo);
// Register the MC codegen info.
TargetRegistry::registerMCAdjustCodeGenOpts(TheXCoreTarget,
TargetRegistry::registerMCAdjustCodeGenOpts(getTheXCoreTarget(),
adjustCodeGenOpts);
// Register the MC instruction info.
TargetRegistry::RegisterMCInstrInfo(TheXCoreTarget, createXCoreMCInstrInfo);
TargetRegistry::RegisterMCInstrInfo(getTheXCoreTarget(),
createXCoreMCInstrInfo);
// Register the MC register info.
TargetRegistry::RegisterMCRegInfo(TheXCoreTarget, createXCoreMCRegisterInfo);
TargetRegistry::RegisterMCRegInfo(getTheXCoreTarget(),
createXCoreMCRegisterInfo);
// Register the MC subtarget info.
TargetRegistry::RegisterMCSubtargetInfo(TheXCoreTarget,
TargetRegistry::RegisterMCSubtargetInfo(getTheXCoreTarget(),
createXCoreMCSubtargetInfo);
// Register the MCInstPrinter
TargetRegistry::RegisterMCInstPrinter(TheXCoreTarget,
TargetRegistry::RegisterMCInstPrinter(getTheXCoreTarget(),
createXCoreMCInstPrinter);
TargetRegistry::RegisterAsmTargetStreamer(TheXCoreTarget,
TargetRegistry::RegisterAsmTargetStreamer(getTheXCoreTarget(),
createTargetAsmStreamer);
}

View File

@ -18,8 +18,7 @@
namespace llvm {
class Target;
extern Target TheXCoreTarget;
Target &getTheXCoreTarget();
} // End llvm namespace

View File

@ -12,8 +12,11 @@
#include "llvm/Support/TargetRegistry.h"
using namespace llvm;
Target llvm::TheXCoreTarget;
Target &llvm::getTheXCoreTarget() {
static Target TheXCoreTarget;
return TheXCoreTarget;
}
extern "C" void LLVMInitializeXCoreTargetInfo() {
RegisterTarget<Triple::xcore> X(TheXCoreTarget, "xcore", "XCore");
RegisterTarget<Triple::xcore> X(getTheXCoreTarget(), "xcore", "XCore");
}

View File

@ -297,5 +297,5 @@ void XCoreAsmPrinter::EmitInstruction(const MachineInstr *MI) {
// Force static initialization.
extern "C" void LLVMInitializeXCoreAsmPrinter() {
RegisterAsmPrinter<XCoreAsmPrinter> X(TheXCoreTarget);
RegisterAsmPrinter<XCoreAsmPrinter> X(getTheXCoreTarget());
}

View File

@ -89,7 +89,7 @@ void XCorePassConfig::addPreEmitPass() {
// Force static initialization.
extern "C" void LLVMInitializeXCoreTarget() {
RegisterTargetMachine<XCoreTargetMachine> X(TheXCoreTarget);
RegisterTargetMachine<XCoreTargetMachine> X(getTheXCoreTarget());
}
TargetIRAnalysis XCoreTargetMachine::getTargetIRAnalysis() {