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.cpp134
1 files changed, 73 insertions, 61 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 4ffffd85ee53..9a0dd92bb58e 100644
--- a/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -472,32 +472,31 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) {
/*AddSegmentInfo=*/false) ||
Name == getInstrProfSectionName(IPSK_covfun, Triple::ELF,
/*AddSegmentInfo=*/false) ||
+ Name == getInstrProfSectionName(IPSK_covdata, Triple::ELF,
+ /*AddSegmentInfo=*/false) ||
+ Name == getInstrProfSectionName(IPSK_covname, Triple::ELF,
+ /*AddSegmentInfo=*/false) ||
Name == ".llvmbc" || Name == ".llvmcmd")
return SectionKind::getMetadata();
if (Name.empty() || Name[0] != '.') return K;
// Default implementation based on some magic section names.
- if (Name == ".bss" ||
- Name.startswith(".bss.") ||
- Name.startswith(".gnu.linkonce.b.") ||
- Name.startswith(".llvm.linkonce.b.") ||
- Name == ".sbss" ||
- Name.startswith(".sbss.") ||
- Name.startswith(".gnu.linkonce.sb.") ||
- Name.startswith(".llvm.linkonce.sb."))
+ if (Name == ".bss" || Name.starts_with(".bss.") ||
+ Name.starts_with(".gnu.linkonce.b.") ||
+ Name.starts_with(".llvm.linkonce.b.") || Name == ".sbss" ||
+ Name.starts_with(".sbss.") || Name.starts_with(".gnu.linkonce.sb.") ||
+ Name.starts_with(".llvm.linkonce.sb."))
return SectionKind::getBSS();
- if (Name == ".tdata" ||
- Name.startswith(".tdata.") ||
- Name.startswith(".gnu.linkonce.td.") ||
- Name.startswith(".llvm.linkonce.td."))
+ if (Name == ".tdata" || Name.starts_with(".tdata.") ||
+ Name.starts_with(".gnu.linkonce.td.") ||
+ Name.starts_with(".llvm.linkonce.td."))
return SectionKind::getThreadData();
- if (Name == ".tbss" ||
- Name.startswith(".tbss.") ||
- Name.startswith(".gnu.linkonce.tb.") ||
- Name.startswith(".llvm.linkonce.tb."))
+ if (Name == ".tbss" || Name.starts_with(".tbss.") ||
+ Name.starts_with(".gnu.linkonce.tb.") ||
+ Name.starts_with(".llvm.linkonce.tb."))
return SectionKind::getThreadBSS();
return K;
@@ -512,7 +511,7 @@ static unsigned getELFSectionType(StringRef Name, SectionKind K) {
// Use SHT_NOTE for section whose name starts with ".note" to allow
// emitting ELF notes from C variable declaration.
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77609
- if (Name.startswith(".note"))
+ if (Name.starts_with(".note"))
return ELF::SHT_NOTE;
if (hasPrefix(Name, ".init_array"))
@@ -616,7 +615,7 @@ static unsigned getEntrySizeForKind(SectionKind Kind) {
/// DataSections.
static StringRef getSectionPrefixForGlobal(SectionKind Kind, bool IsLarge) {
if (Kind.isText())
- return ".text";
+ return IsLarge ? ".ltext" : ".text";
if (Kind.isReadOnly())
return IsLarge ? ".lrodata" : ".rodata";
if (Kind.isBSS())
@@ -650,10 +649,7 @@ getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
Name = ".rodata.cst";
Name += utostr(EntrySize);
} else {
- bool IsLarge = false;
- if (isa<GlobalVariable>(GO))
- IsLarge = TM.isLargeData();
- Name = getSectionPrefixForGlobal(Kind, IsLarge);
+ Name = getSectionPrefixForGlobal(Kind, TM.isLargeGlobalValue(GO));
}
bool HasPrefix = false;
@@ -755,7 +751,7 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
getELFSectionNameForGlobal(GO, Kind, Mang, TM, EntrySize, false);
if (SymbolMergeable &&
Ctx.isELFImplicitMergeableSectionNamePrefix(SectionName) &&
- SectionName.startswith(ImplicitSectionNameStem))
+ SectionName.starts_with(ImplicitSectionNameStem))
return MCContext::GenericSectionID;
// We have seen this section name before, but with different flags or entity
@@ -763,6 +759,21 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
return NextUniqueID++;
}
+static std::tuple<StringRef, bool, unsigned>
+getGlobalObjectInfo(const GlobalObject *GO, const TargetMachine &TM) {
+ StringRef Group = "";
+ bool IsComdat = false;
+ unsigned Flags = 0;
+ if (const Comdat *C = getELFComdat(GO)) {
+ Flags |= ELF::SHF_GROUP;
+ Group = C->getName();
+ IsComdat = C->getSelectionKind() == Comdat::Any;
+ }
+ if (TM.isLargeGlobalValue(GO))
+ Flags |= ELF::SHF_X86_64_LARGE;
+ return {Group, IsComdat, Flags};
+}
+
static MCSection *selectExplicitSectionGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM,
MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID,
@@ -793,14 +804,9 @@ static MCSection *selectExplicitSectionGlobal(
// Infer section flags from the section name if we can.
Kind = getELFKindForNamedSection(SectionName, Kind);
- StringRef Group = "";
- bool IsComdat = false;
unsigned Flags = getELFSectionFlags(Kind);
- if (const Comdat *C = getELFComdat(GO)) {
- Group = C->getName();
- IsComdat = C->getSelectionKind() == Comdat::Any;
- Flags |= ELF::SHF_GROUP;
- }
+ auto [Group, IsComdat, ExtraFlags] = getGlobalObjectInfo(GO, TM);
+ Flags |= ExtraFlags;
unsigned EntrySize = getEntrySizeForKind(Kind);
const unsigned UniqueID = calcUniqueIDUpdateFlagsAndSize(
@@ -848,19 +854,8 @@ static MCSectionELF *selectELFSectionForGlobal(
const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol) {
- StringRef Group = "";
- bool IsComdat = false;
- if (const Comdat *C = getELFComdat(GO)) {
- Flags |= ELF::SHF_GROUP;
- Group = C->getName();
- IsComdat = C->getSelectionKind() == Comdat::Any;
- }
- if (isa<GlobalVariable>(GO) && !cast<GlobalVariable>(GO)->isThreadLocal()) {
- if (TM.isLargeData()) {
- assert(TM.getTargetTriple().getArch() == Triple::x86_64);
- Flags |= ELF::SHF_X86_64_LARGE;
- }
- }
+ auto [Group, IsComdat, ExtraFlags] = getGlobalObjectInfo(GO, TM);
+ Flags |= ExtraFlags;
// Get the section entry size based on the kind.
unsigned EntrySize = getEntrySizeForKind(Kind);
@@ -1038,21 +1033,32 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
// under the .text.eh prefix. For regular sections, we either use a unique
// name, or a unique ID for the section.
SmallString<128> Name;
- if (MBB.getSectionID() == MBBSectionID::ColdSectionID) {
- Name += BBSectionsColdTextPrefix;
- Name += MBB.getParent()->getName();
- } else if (MBB.getSectionID() == MBBSectionID::ExceptionSectionID) {
- Name += ".text.eh.";
- Name += MBB.getParent()->getName();
- } else {
- Name += MBB.getParent()->getSection()->getName();
- if (TM.getUniqueBasicBlockSectionNames()) {
- if (!Name.endswith("."))
- Name += ".";
- Name += MBB.getSymbol()->getName();
+ StringRef FunctionSectionName = MBB.getParent()->getSection()->getName();
+ if (FunctionSectionName.equals(".text") ||
+ FunctionSectionName.starts_with(".text.")) {
+ // Function is in a regular .text section.
+ StringRef FunctionName = MBB.getParent()->getName();
+ if (MBB.getSectionID() == MBBSectionID::ColdSectionID) {
+ Name += BBSectionsColdTextPrefix;
+ Name += FunctionName;
+ } else if (MBB.getSectionID() == MBBSectionID::ExceptionSectionID) {
+ Name += ".text.eh.";
+ Name += FunctionName;
} else {
- UniqueID = NextUniqueID++;
+ Name += FunctionSectionName;
+ if (TM.getUniqueBasicBlockSectionNames()) {
+ if (!Name.ends_with("."))
+ Name += ".";
+ Name += MBB.getSymbol()->getName();
+ } else {
+ UniqueID = NextUniqueID++;
+ }
}
+ } else {
+ // If the original function has a custom non-dot-text section, then emit
+ // all basic block sections into that section too, each with a unique id.
+ Name = FunctionSectionName;
+ UniqueID = NextUniqueID++;
}
unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
@@ -2303,8 +2309,10 @@ bool TargetLoweringObjectFileXCOFF::ShouldSetSSPCanaryBitInTB(
MCSymbol *
TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol(const MachineFunction *MF) {
- return MF->getMMI().getContext().getOrCreateSymbol(
+ MCSymbol *EHInfoSym = MF->getMMI().getContext().getOrCreateSymbol(
"__ehinfo." + Twine(MF->getFunctionNumber()));
+ cast<MCSymbolXCOFF>(EHInfoSym)->setEHInfo();
+ return EHInfoSym;
}
MCSymbol *
@@ -2637,12 +2645,16 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor(
MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
const MCSymbol *Sym, const TargetMachine &TM) const {
// Use TE storage-mapping class when large code model is enabled so that
- // the chance of needing -bbigtoc is decreased.
+ // the chance of needing -bbigtoc is decreased. Also, the toc-entry for
+ // EH info is never referenced directly using instructions so it can be
+ // allocated with TE storage-mapping class.
return getContext().getXCOFFSection(
cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(), SectionKind::getData(),
- XCOFF::CsectProperties(
- TM.getCodeModel() == CodeModel::Large ? XCOFF::XMC_TE : XCOFF::XMC_TC,
- XCOFF::XTY_SD));
+ XCOFF::CsectProperties((TM.getCodeModel() == CodeModel::Large ||
+ cast<MCSymbolXCOFF>(Sym)->isEHInfo())
+ ? XCOFF::XMC_TE
+ : XCOFF::XMC_TC,
+ XCOFF::XTY_SD));
}
MCSection *TargetLoweringObjectFileXCOFF::getSectionForLSDA(