Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -90,13 +90,13 @@ //===----------------------------------------------------------------------===// // ELF //===----------------------------------------------------------------------===// - void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx, const TargetMachine &TgtM) { TargetLoweringObjectFile::Initialize(Ctx, TgtM); TM = &TgtM; CodeModel::Model CM = TgtM.getCodeModel(); + InitializeELF(TgtM.Options.UseInitArray); switch (TgtM.getTargetTriple().getArch()) { case Triple::arm: Index: llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp =================================================================== --- llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp +++ llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp @@ -20,7 +20,6 @@ void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) { TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); // AARCH64 ELF ABI does not define static relocation type for TLS offset // within a module. Do not generate AT_location for TLS variables. SupportDebugThreadLocalLocation = false; Index: llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp +++ llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp @@ -112,7 +112,6 @@ void HexagonTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) { TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); SmallDataSection = getContext().getELFSection(".sdata", ELF::SHT_PROGBITS, Index: llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp +++ llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp @@ -28,7 +28,6 @@ void LanaiTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) { TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); SmallDataSection = getContext().getELFSection( ".sdata", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC); Index: llvm/lib/Target/Mips/MipsTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/Mips/MipsTargetObjectFile.cpp +++ llvm/lib/Target/Mips/MipsTargetObjectFile.cpp @@ -44,7 +44,6 @@ void MipsTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){ TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); SmallDataSection = getContext().getELFSection( ".sdata", ELF::SHT_PROGBITS, Index: llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp +++ llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp @@ -18,7 +18,6 @@ PPC64LinuxTargetObjectFile:: Initialize(MCContext &Ctx, const TargetMachine &TM) { TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); } MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal( Index: llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp +++ llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp @@ -17,7 +17,6 @@ void RISCVELFTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) { TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); SmallDataSection = getContext().getELFSection( ".sdata", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC); Index: llvm/lib/Target/Sparc/SparcTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/Sparc/SparcTargetObjectFile.cpp +++ llvm/lib/Target/Sparc/SparcTargetObjectFile.cpp @@ -17,7 +17,6 @@ void SparcELFTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) { TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); } const MCExpr *SparcELFTargetObjectFile::getTTypeGlobalReference( Index: llvm/lib/Target/X86/X86TargetMachine.cpp =================================================================== --- llvm/lib/Target/X86/X86TargetMachine.cpp +++ llvm/lib/Target/X86/X86TargetMachine.cpp @@ -92,19 +92,9 @@ return std::make_unique(); } - if (TT.isOSFreeBSD()) - return std::make_unique(); - if (TT.isOSLinux() || TT.isOSNaCl() || TT.isOSIAMCU()) - return std::make_unique(); - if (TT.isOSSolaris()) - return std::make_unique(); - if (TT.isOSFuchsia()) - return std::make_unique(); - if (TT.isOSBinFormatELF()) - return std::make_unique(); if (TT.isOSBinFormatCOFF()) return std::make_unique(); - llvm_unreachable("unknown subtarget type"); + return std::make_unique(); } static std::string computeDataLayout(const Triple &TT) { Index: llvm/lib/Target/X86/X86TargetObjectFile.h =================================================================== --- llvm/lib/Target/X86/X86TargetObjectFile.h +++ llvm/lib/Target/X86/X86TargetObjectFile.h @@ -44,33 +44,11 @@ X86ELFTargetObjectFile() { PLTRelativeVariantKind = MCSymbolRefExpr::VK_PLT; } - + void Initialize(MCContext &Ctx, const TargetMachine &TM) override; /// Describe a TLS variable address within debug info. const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const override; }; - /// X86FreeBSDTargetObjectFile - This implementation is used for FreeBSD - /// on x86 and x86-64. - class X86FreeBSDTargetObjectFile : public X86ELFTargetObjectFile { - void Initialize(MCContext &Ctx, const TargetMachine &TM) override; - }; - - /// This implementation is used for Fuchsia on x86-64. - class X86FuchsiaTargetObjectFile : public X86ELFTargetObjectFile { - void Initialize(MCContext &Ctx, const TargetMachine &TM) override; - }; - - /// X86LinuxNaClTargetObjectFile - This implementation is used for linux and - /// Native Client on x86 and x86-64. - class X86LinuxNaClTargetObjectFile : public X86ELFTargetObjectFile { - void Initialize(MCContext &Ctx, const TargetMachine &TM) override; - }; - - /// This implementation is used for Solaris on x86/x86-64. - class X86SolarisTargetObjectFile : public X86ELFTargetObjectFile { - void Initialize(MCContext &Ctx, const TargetMachine &TM) override; - }; - } // end namespace llvm #endif Index: llvm/lib/Target/X86/X86TargetObjectFile.cpp =================================================================== --- llvm/lib/Target/X86/X86TargetObjectFile.cpp +++ llvm/lib/Target/X86/X86TargetObjectFile.cpp @@ -65,28 +65,7 @@ } void -X86FreeBSDTargetObjectFile::Initialize(MCContext &Ctx, +X86ELFTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) { TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); -} - -void -X86FuchsiaTargetObjectFile::Initialize(MCContext &Ctx, - const TargetMachine &TM) { - TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); -} - -void -X86LinuxNaClTargetObjectFile::Initialize(MCContext &Ctx, - const TargetMachine &TM) { - TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); -} - -void X86SolarisTargetObjectFile::Initialize(MCContext &Ctx, - const TargetMachine &TM) { - TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); } Index: llvm/test/CodeGen/X86/constructor.ll =================================================================== --- llvm/test/CodeGen/X86/constructor.ll +++ llvm/test/CodeGen/X86/constructor.ll @@ -8,6 +8,7 @@ ; RUN: llc -mtriple i586-intel-elfiamcu -use-ctors < %s | FileCheck %s --check-prefix=MCU-CTORS ; RUN: llc -mtriple i586-intel-elfiamcu < %s | FileCheck %s --check-prefix=MCU-INIT-ARRAY ; RUN: llc -mtriple x86_64-win32-gnu < %s | FileCheck --check-prefix=COFF-CTOR %s +; RUN: llc -mtriple x86_64 -use-ctors=false < %s | FileCheck %s @llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null}, { i32, void ()*, i8* } { i32 15, void ()* @g, i8* @v }, { i32, void ()*, i8* } { i32 55555, void ()* @h, i8* @v }] @v = weak_odr global i8 0 @@ -69,3 +70,5 @@ ; COFF-CTOR-NEXT: .section .ctors,"dw" ; COFF-CTOR-NEXT: .p2align 3 ; COFF-CTOR-NEXT: .quad f + +; CHECK: .init_array Index: llvm/test/CodeGen/X86/init-priority.ll =================================================================== --- llvm/test/CodeGen/X86/init-priority.ll +++ llvm/test/CodeGen/X86/init-priority.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s -mtriple=x86_64-netbsd | FileCheck %s +; RUN: llc < %s -mtriple=x86_64-netbsd -use-ctors | FileCheck %s ; Check that our compiler never emits global constructors ; inside the .init_array section when building for a non supported target.