aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp91
1 files changed, 63 insertions, 28 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index ce350034d073..f3d68bd9c92d 100644
--- a/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -310,7 +310,7 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
auto *S = C.getELFSection(".linker-options", ELF::SHT_LLVM_LINKER_OPTIONS,
ELF::SHF_EXCLUDE);
- Streamer.SwitchSection(S);
+ Streamer.switchSection(S);
for (const auto *Operand : LinkerOptions->operands()) {
if (cast<MDNode>(Operand)->getNumOperands() != 2)
@@ -326,7 +326,7 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
auto *S = C.getELFSection(".deplibs", ELF::SHT_LLVM_DEPENDENT_LIBRARIES,
ELF::SHF_MERGE | ELF::SHF_STRINGS, 1);
- Streamer.SwitchSection(S);
+ Streamer.switchSection(S);
for (const auto *Operand : DependentLibraries->operands()) {
Streamer.emitBytes(
@@ -350,7 +350,7 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
auto *S = C.getObjectFileInfo()->getPseudoProbeDescSection(
TM->getFunctionSections() ? Name->getString() : StringRef());
- Streamer.SwitchSection(S);
+ Streamer.switchSection(S);
Streamer.emitInt64(GUID->getZExtValue());
Streamer.emitInt64(Hash->getZExtValue());
Streamer.emitULEB128IntValue(Name->getString().size());
@@ -365,11 +365,11 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
GetObjCImageInfo(M, Version, Flags, Section);
if (!Section.empty()) {
auto *S = C.getELFSection(Section, ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
- Streamer.SwitchSection(S);
+ Streamer.switchSection(S);
Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
Streamer.emitInt32(Version);
Streamer.emitInt32(Flags);
- Streamer.AddBlankLine();
+ Streamer.addBlankLine();
}
emitCGProfileMetadata(Streamer, M);
@@ -399,7 +399,7 @@ void TargetLoweringObjectFileELF::emitPersonalityValue(
MCSection *Sec = getContext().getELFNamedSection(".data", Label->getName(),
ELF::SHT_PROGBITS, Flags, 0);
unsigned Size = DL.getPointerSize();
- Streamer.SwitchSection(Sec);
+ Streamer.switchSection(Sec);
Streamer.emitValueToAlignment(DL.getPointerABIAlignment(0).value());
Streamer.emitSymbolAttribute(Label, MCSA_ELF_TypeObject);
const MCExpr *E = MCConstantExpr::create(Size, getContext());
@@ -449,6 +449,9 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) {
Name == ".llvmbc" || Name == ".llvmcmd")
return SectionKind::getMetadata();
+ if (Name == ".llvm.offloading")
+ return SectionKind::getExclude();
+
if (Name.empty() || Name[0] != '.') return K;
// Default implementation based on some magic section names.
@@ -507,9 +510,12 @@ static unsigned getELFSectionType(StringRef Name, SectionKind K) {
static unsigned getELFSectionFlags(SectionKind K) {
unsigned Flags = 0;
- if (!K.isMetadata())
+ if (!K.isMetadata() && !K.isExclude())
Flags |= ELF::SHF_ALLOC;
+ if (K.isExclude())
+ Flags |= ELF::SHF_EXCLUDE;
+
if (K.isText())
Flags |= ELF::SHF_EXECINSTR;
@@ -681,9 +687,10 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
}
if (Retain) {
- if ((Ctx.getAsmInfo()->useIntegratedAssembler() ||
- Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36)) &&
- !TM.getTargetTriple().isOSSolaris())
+ if (TM.getTargetTriple().isOSSolaris())
+ Flags |= ELF::SHF_SUNW_NODISCARD;
+ else if (Ctx.getAsmInfo()->useIntegratedAssembler() ||
+ Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36))
Flags |= ELF::SHF_GNU_RETAIN;
return NextUniqueID++;
}
@@ -860,12 +867,15 @@ static MCSection *selectELFSectionForGlobal(
EmitUniqueSection = true;
Flags |= ELF::SHF_LINK_ORDER;
}
- if (Retain &&
- (Ctx.getAsmInfo()->useIntegratedAssembler() ||
- Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36)) &&
- !TM.getTargetTriple().isOSSolaris()) {
- EmitUniqueSection = true;
- Flags |= ELF::SHF_GNU_RETAIN;
+ if (Retain) {
+ if (TM.getTargetTriple().isOSSolaris()) {
+ EmitUniqueSection = true;
+ Flags |= ELF::SHF_SUNW_NODISCARD;
+ } else if (Ctx.getAsmInfo()->useIntegratedAssembler() ||
+ Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36)) {
+ EmitUniqueSection = true;
+ Flags |= ELF::SHF_GNU_RETAIN;
+ }
}
MCSectionELF *Section = selectELFSectionForGlobal(
@@ -1171,6 +1181,15 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
}
+MCSection *TargetLoweringObjectFileMachO::getStaticDtorSection(
+ unsigned Priority, const MCSymbol *KeySym) const {
+ // TODO(yln): Remove -lower-global-dtors-via-cxa-atexit fallback flag
+ // (LowerGlobalDtorsViaCxaAtExit) and always issue a fatal error here.
+ if (TM->Options.LowerGlobalDtorsViaCxaAtExit)
+ report_fatal_error("@llvm.global_dtors should have been lowered already");
+ return StaticDtorSection;
+}
+
void TargetLoweringObjectFileMachO::emitModuleMetadata(MCStreamer &Streamer,
Module &M) const {
// Emit the linker options if present.
@@ -1207,12 +1226,12 @@ void TargetLoweringObjectFileMachO::emitModuleMetadata(MCStreamer &Streamer,
// Get the section.
MCSectionMachO *S = getContext().getMachOSection(
Segment, Section, TAA, StubSize, SectionKind::getData());
- Streamer.SwitchSection(S);
+ Streamer.switchSection(S);
Streamer.emitLabel(getContext().
getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
Streamer.emitInt32(VersionVal);
Streamer.emitInt32(ImageInfoFlags);
- Streamer.AddBlankLine();
+ Streamer.addBlankLine();
}
static void checkMachOComdat(const GlobalValue *GV) {
@@ -1520,6 +1539,9 @@ getCOFFSectionFlags(SectionKind K, const TargetMachine &TM) {
if (K.isMetadata())
Flags |=
COFF::IMAGE_SCN_MEM_DISCARDABLE;
+ else if (K.isExclude())
+ Flags |=
+ COFF::IMAGE_SCN_LNK_REMOVE | COFF::IMAGE_SCN_MEM_DISCARDABLE;
else if (K.isText())
Flags |=
COFF::IMAGE_SCN_MEM_EXECUTE |
@@ -1755,11 +1777,11 @@ void TargetLoweringObjectFileCOFF::emitModuleMetadata(MCStreamer &Streamer,
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
- Streamer.SwitchSection(S);
+ Streamer.switchSection(S);
Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
Streamer.emitInt32(Version);
Streamer.emitInt32(Flags);
- Streamer.AddBlankLine();
+ Streamer.addBlankLine();
}
emitCGProfileMetadata(Streamer, M);
@@ -1772,7 +1794,7 @@ void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
// spec, this section is a space-separated string containing flags for
// linker.
MCSection *Sec = getDrectveSection();
- Streamer.SwitchSection(Sec);
+ Streamer.switchSection(Sec);
for (const auto *Option : LinkerOptions->operands()) {
for (const auto &Piece : cast<MDNode>(Option)->operands()) {
// Lead with a space for consistency with our dllexport implementation.
@@ -1791,7 +1813,7 @@ void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
getMangler());
OS.flush();
if (!Flags.empty()) {
- Streamer.SwitchSection(getDrectveSection());
+ Streamer.switchSection(getDrectveSection());
Streamer.emitBytes(Flags);
}
Flags.clear();
@@ -1817,7 +1839,7 @@ void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
OS.flush();
if (!Flags.empty()) {
- Streamer.SwitchSection(getDrectveSection());
+ Streamer.switchSection(getDrectveSection());
Streamer.emitBytes(Flags);
}
Flags.clear();
@@ -2170,8 +2192,7 @@ MCSection *TargetLoweringObjectFileWasm::getStaticCtorSection(
MCSection *TargetLoweringObjectFileWasm::getStaticDtorSection(
unsigned Priority, const MCSymbol *KeySym) const {
- llvm_unreachable("@llvm.global_dtors should have been lowered already");
- return nullptr;
+ report_fatal_error("@llvm.global_dtors should have been lowered already");
}
//===----------------------------------------------------------------------===//
@@ -2544,10 +2565,24 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
XCOFF::XTY_SD));
}
+MCSection *TargetLoweringObjectFileXCOFF::getSectionForLSDA(
+ const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
+ auto *LSDA = cast<MCSectionXCOFF>(LSDASection);
+ if (TM.getFunctionSections()) {
+ // If option -ffunction-sections is on, append the function name to the
+ // name of the LSDA csect so that each function has its own LSDA csect.
+ // This helps the linker to garbage-collect EH info of unused functions.
+ SmallString<128> NameStr = LSDA->getName();
+ raw_svector_ostream(NameStr) << '.' << F.getName();
+ LSDA = getContext().getXCOFFSection(NameStr, LSDA->getKind(),
+ LSDA->getCsectProp());
+ }
+ return LSDA;
+}
//===----------------------------------------------------------------------===//
// GOFF
//===----------------------------------------------------------------------===//
-TargetLoweringObjectFileGOFF::TargetLoweringObjectFileGOFF() {}
+TargetLoweringObjectFileGOFF::TargetLoweringObjectFileGOFF() = default;
MCSection *TargetLoweringObjectFileGOFF::getExplicitSectionGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
@@ -2558,8 +2593,8 @@ MCSection *TargetLoweringObjectFileGOFF::SelectSectionForGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
auto *Symbol = TM.getSymbol(GO);
if (Kind.isBSS())
- return getContext().getGOFFSection(Symbol->getName(),
- SectionKind::getBSS());
+ return getContext().getGOFFSection(Symbol->getName(), SectionKind::getBSS(),
+ nullptr, nullptr);
return getContext().getObjectFileInfo()->getTextSection();
}