diff options
author | Kamlesh Kumar <kamleshbhalui@gmail.com> | 2019-12-16 15:14:08 -0800 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2019-12-16 15:21:23 -0800 |
commit | aa5ee8f244441a8ea103a7e0ed8b6f3e74454516 (patch) | |
tree | affd1a1ded3287b70ad2e073109bda3f10656ac7 | |
parent | d7af86bdd0bdc9509fd7fdc3ae34bb0f4b9d269f (diff) | |
download | bcm5719-llvm-aa5ee8f244441a8ea103a7e0ed8b6f3e74454516.tar.gz bcm5719-llvm-aa5ee8f244441a8ea103a7e0ed8b6f3e74454516.zip |
Honor -fuse-init-array when os is not specified on x86
Currently -fuse-init-array option is not effective when target triple
does not specify os, on x86,x86_64.
i.e.
// -fuse-init-array is not honored.
$ clang -target i386 -fuse-init-array test.c -S
// -fuse-init-array is honored.
$ clang -target i386-linux -fuse-init-array test.c -S
This patch fixes first case.
And does cleanup.
Reviewers: rnk, craig.topper, fhahn, echristo
Reviewed By: rnk
Differential Revision: https://reviews.llvm.org/D71360
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Target/Mips/MipsTargetObjectFile.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Target/Sparc/SparcTargetObjectFile.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86TargetMachine.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86TargetObjectFile.cpp | 23 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86TargetObjectFile.h | 24 | ||||
-rw-r--r-- | llvm/test/CodeGen/X86/constructor.ll | 3 | ||||
-rw-r--r-- | llvm/test/CodeGen/X86/init-priority.ll | 2 |
13 files changed, 8 insertions, 64 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index ee9d388131f..34e96663a09 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -97,6 +97,7 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx, TM = &TgtM; CodeModel::Model CM = TgtM.getCodeModel(); + InitializeELF(TgtM.Options.UseInitArray); switch (TgtM.getTargetTriple().getArch()) { case Triple::arm: diff --git a/llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp b/llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp index 54562094fcf..fb37a2ca6dd 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp @@ -20,7 +20,6 @@ using namespace dwarf; 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; diff --git a/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp b/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp index fdcc41a4ca4..1dc1a783e6d 100644 --- a/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp +++ b/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp @@ -112,7 +112,6 @@ static const char *getSectionSuffixForSize(unsigned Size) { void HexagonTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) { TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); SmallDataSection = getContext().getELFSection(".sdata", ELF::SHT_PROGBITS, diff --git a/llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp b/llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp index b0f7c090bb8..d47306c55ba 100644 --- a/llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp +++ b/llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp @@ -28,7 +28,6 @@ static cl::opt<unsigned> SSThreshold( 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); diff --git a/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp b/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp index 0852b5a18c6..ffd7a057bf0 100644 --- a/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp +++ b/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp @@ -44,7 +44,6 @@ EmbeddedData("membedded-data", cl::Hidden, void MipsTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){ TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); SmallDataSection = getContext().getELFSection( ".sdata", ELF::SHT_PROGBITS, diff --git a/llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp b/llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp index e237fab1b26..168630f55b2 100644 --- a/llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp +++ b/llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp @@ -18,7 +18,6 @@ void PPC64LinuxTargetObjectFile:: Initialize(MCContext &Ctx, const TargetMachine &TM) { TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); } MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal( diff --git a/llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp b/llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp index bbd45c970d3..0d1480170fd 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp @@ -17,7 +17,6 @@ using namespace llvm; 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); diff --git a/llvm/lib/Target/Sparc/SparcTargetObjectFile.cpp b/llvm/lib/Target/Sparc/SparcTargetObjectFile.cpp index e6ad4d2d67a..022ee4e9503 100644 --- a/llvm/lib/Target/Sparc/SparcTargetObjectFile.cpp +++ b/llvm/lib/Target/Sparc/SparcTargetObjectFile.cpp @@ -17,7 +17,6 @@ using namespace llvm; void SparcELFTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) { TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); } const MCExpr *SparcELFTargetObjectFile::getTTypeGlobalReference( diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp index 21f1ef9cb06..20ce87941c0 100644 --- a/llvm/lib/Target/X86/X86TargetMachine.cpp +++ b/llvm/lib/Target/X86/X86TargetMachine.cpp @@ -92,19 +92,9 @@ static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) { return std::make_unique<TargetLoweringObjectFileMachO>(); } - if (TT.isOSFreeBSD()) - return std::make_unique<X86FreeBSDTargetObjectFile>(); - if (TT.isOSLinux() || TT.isOSNaCl() || TT.isOSIAMCU()) - return std::make_unique<X86LinuxNaClTargetObjectFile>(); - if (TT.isOSSolaris()) - return std::make_unique<X86SolarisTargetObjectFile>(); - if (TT.isOSFuchsia()) - return std::make_unique<X86FuchsiaTargetObjectFile>(); - if (TT.isOSBinFormatELF()) - return std::make_unique<X86ELFTargetObjectFile>(); if (TT.isOSBinFormatCOFF()) return std::make_unique<TargetLoweringObjectFileCOFF>(); - llvm_unreachable("unknown subtarget type"); + return std::make_unique<X86ELFTargetObjectFile>(); } static std::string computeDataLayout(const Triple &TT) { diff --git a/llvm/lib/Target/X86/X86TargetObjectFile.cpp b/llvm/lib/Target/X86/X86TargetObjectFile.cpp index 44185957686..653658e9e67 100644 --- a/llvm/lib/Target/X86/X86TargetObjectFile.cpp +++ b/llvm/lib/Target/X86/X86TargetObjectFile.cpp @@ -65,28 +65,7 @@ const MCExpr *X86ELFTargetObjectFile::getDebugThreadLocalSymbol( } 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); } diff --git a/llvm/lib/Target/X86/X86TargetObjectFile.h b/llvm/lib/Target/X86/X86TargetObjectFile.h index 1fd0bbf56b1..46d41ccc9b3 100644 --- a/llvm/lib/Target/X86/X86TargetObjectFile.h +++ b/llvm/lib/Target/X86/X86TargetObjectFile.h @@ -44,33 +44,11 @@ namespace llvm { 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 diff --git a/llvm/test/CodeGen/X86/constructor.ll b/llvm/test/CodeGen/X86/constructor.ll index d4518f19b7e..2b6478a4b7b 100644 --- a/llvm/test/CodeGen/X86/constructor.ll +++ b/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 @@ entry: ; COFF-CTOR-NEXT: .section .ctors,"dw" ; COFF-CTOR-NEXT: .p2align 3 ; COFF-CTOR-NEXT: .quad f + +; CHECK: .init_array diff --git a/llvm/test/CodeGen/X86/init-priority.ll b/llvm/test/CodeGen/X86/init-priority.ll index 30e94841f79..47f548cf023 100644 --- a/llvm/test/CodeGen/X86/init-priority.ll +++ b/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. |