[llvm] 85c30f3 - [X86] Reland D71360 Clean up UseInitArray initialization for X86ELFTargetObjectFile
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 20 21:58:26 PDT 2020
Author: Fangrui Song
Date: 2020-03-20T21:57:34-07:00
New Revision: 85c30f3374d9f7f1124241ab09ce377fcb08d24d
URL: https://github.com/llvm/llvm-project/commit/85c30f3374d9f7f1124241ab09ce377fcb08d24d
DIFF: https://github.com/llvm/llvm-project/commit/85c30f3374d9f7f1124241ab09ce377fcb08d24d.diff
LOG: [X86] Reland D71360 Clean up UseInitArray initialization for X86ELFTargetObjectFile
-fuse-init-array is now the CC1 default but TargetLoweringObjectFileELF::UseInitArray still defaults to false.
The following two unknown OS target triples continue using .ctors/.dtors because InitializeELF is not called.
clang -target i386 -c a.c
clang -target x86_64 -c a.c
This cleanup fixes this as a bonus.
X86SpeculativeLoadHardeningPass::tracePredStateThroughCall can call
MCContext::createTempSymbol before TargetLoweringObjectFileELF::Initialize().
We need to call TargetLoweringObjectFileELF::Initialize() ealier.
test/CodeGen/X86/speculative-load-hardening-indirect.ll
Differential Revision: https://reviews.llvm.org/D71360
Added:
Modified:
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp
llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp
llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp
llvm/lib/Target/Mips/MipsTargetObjectFile.cpp
llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp
llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp
llvm/lib/Target/Sparc/SparcTargetObjectFile.cpp
llvm/lib/Target/X86/X86TargetMachine.cpp
llvm/lib/Target/X86/X86TargetObjectFile.cpp
llvm/lib/Target/X86/X86TargetObjectFile.h
llvm/test/CodeGen/X86/constructor.ll
llvm/test/CodeGen/X86/init-priority.ll
llvm/tools/llc/llc.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 8f1c342202d6..dedb6735b470 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -108,6 +108,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 cf049ec274f2..dfc66f0cb4c1 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 fdcc41a4ca41..1dc1a783e6da 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 b0f7c090bb8e..d47306c55bad 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 0852b5a18c68..ffd7a057bf05 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 e237fab1b267..168630f55b24 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 bbd45c970d3d..0d1480170fda 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 e6ad4d2d67aa..022ee4e9503e 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 0cfa7bb04771..0404b4313a02 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 44185957686b..9096649a2207 100644
--- a/llvm/lib/Target/X86/X86TargetObjectFile.cpp
+++ b/llvm/lib/Target/X86/X86TargetObjectFile.cpp
@@ -64,29 +64,7 @@ const MCExpr *X86ELFTargetObjectFile::getDebugThreadLocalSymbol(
return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
}
-void
-X86FreeBSDTargetObjectFile::Initialize(MCContext &Ctx,
- const TargetMachine &TM) {
+void 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 1fd0bbf56b19..46d41ccc9b33 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 d4518f19b7e6..534c452d6548 100644
--- a/llvm/test/CodeGen/X86/constructor.ll
+++ b/llvm/test/CodeGen/X86/constructor.ll
@@ -1,3 +1,4 @@
+; RUN: llc -mtriple x86_64 < %s | FileCheck --check-prefix=INIT-ARRAY %s
; RUN: llc -mtriple x86_64-pc-linux -use-ctors < %s | FileCheck --check-prefix=CTOR %s
; RUN: llc -mtriple x86_64-unknown-freebsd -use-ctors < %s | FileCheck --check-prefix=CTOR %s
; RUN: llc -mtriple x86_64-pc-solaris2.11 -use-ctors < %s | FileCheck --check-prefix=CTOR %s
diff --git a/llvm/test/CodeGen/X86/init-priority.ll b/llvm/test/CodeGen/X86/init-priority.ll
index 30e94841f793..47f548cf0238 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.
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 1e381bb729bd..76dd071bd2c7 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -597,10 +597,10 @@ static int compileModule(char **argv, LLVMContext &Context) {
return 1;
}
+ const_cast<TargetLoweringObjectFile *>(LLVMTM.getObjFileLowering())
+ ->Initialize(MMIWP->getMMI().getContext(), *Target);
if (MIR) {
assert(MMIWP && "Forgot to create MMIWP?");
- const_cast<TargetLoweringObjectFile *>(LLVMTM.getObjFileLowering())
- ->Initialize(MMIWP->getMMI().getContext(), *Target);
if (MIR->parseMachineFunctions(*M, MMIWP->getMMI()))
return 1;
}
More information about the llvm-commits
mailing list