diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp --- a/llvm/lib/Target/X86/X86TargetMachine.cpp +++ b/llvm/lib/Target/X86/X86TargetMachine.cpp @@ -100,8 +100,10 @@ return std::make_unique(); if (TT.isOSFuchsia()) return std::make_unique(); - if (TT.isOSBinFormatELF()) + if (TT.isOSNetBSD()) return std::make_unique(); + if (TT.isOSBinFormatELF()) + return std::make_unique(); if (TT.isOSBinFormatCOFF()) return std::make_unique(); llvm_unreachable("unknown subtarget type"); diff --git a/llvm/lib/Target/X86/X86TargetObjectFile.h b/llvm/lib/Target/X86/X86TargetObjectFile.h --- a/llvm/lib/Target/X86/X86TargetObjectFile.h +++ b/llvm/lib/Target/X86/X86TargetObjectFile.h @@ -49,6 +49,12 @@ const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const override; }; + /// X86BinFormatELFTargetObjectFile - This implementation is used for OS + /// which uses ELF Binary Format on x86 and x86-64. + class X86BinFormatELFTargetObjectFile : public X86ELFTargetObjectFile { + void Initialize(MCContext &Ctx, const TargetMachine &TM) override; + }; + /// X86FreeBSDTargetObjectFile - This implementation is used for FreeBSD /// on x86 and x86-64. class X86FreeBSDTargetObjectFile : public X86ELFTargetObjectFile { diff --git a/llvm/lib/Target/X86/X86TargetObjectFile.cpp b/llvm/lib/Target/X86/X86TargetObjectFile.cpp --- a/llvm/lib/Target/X86/X86TargetObjectFile.cpp +++ b/llvm/lib/Target/X86/X86TargetObjectFile.cpp @@ -64,6 +64,13 @@ return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext()); } +void +X86BinFormatELFTargetObjectFile::Initialize(MCContext &Ctx, + const TargetMachine &TM) { + TargetLoweringObjectFileELF::Initialize(Ctx, TM); + InitializeELF(TM.Options.UseInitArray); +} + void X86FreeBSDTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) {