aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp42
1 files changed, 26 insertions, 16 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index cccac07..eef0555 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -315,7 +315,7 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
if (NamedMDNode *DependentLibraries = M.getNamedMetadata("llvm.dependent-libraries")) {
auto *S = C.getELFSection(".deplibs", ELF::SHT_LLVM_DEPENDENT_LIBRARIES,
- ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
+ ELF::SHF_MERGE | ELF::SHF_STRINGS, 1);
Streamer.SwitchSection(S);
@@ -522,9 +522,11 @@ static const Comdat *getELFComdat(const GlobalValue *GV) {
if (!C)
return nullptr;
- if (C->getSelectionKind() != Comdat::Any)
- report_fatal_error("ELF COMDATs only support SelectionKind::Any, '" +
- C->getName() + "' cannot be lowered.");
+ if (C->getSelectionKind() != Comdat::Any &&
+ C->getSelectionKind() != Comdat::NoDuplicates)
+ report_fatal_error("ELF COMDATs only support SelectionKind::Any and "
+ "SelectionKind::NoDuplicates, '" + C->getName() +
+ "' cannot be lowered.");
return C;
}
@@ -669,9 +671,11 @@ MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
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;
}
@@ -730,8 +734,8 @@ MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
}
MCSectionELF *Section = getContext().getELFSection(
- SectionName, getELFSectionType(SectionName, Kind), Flags,
- EntrySize, Group, UniqueID, LinkedToSym);
+ SectionName, getELFSectionType(SectionName, Kind), Flags, EntrySize,
+ Group, IsComdat, UniqueID, LinkedToSym);
// Make sure that we did not get some other section with incompatible sh_link.
// This should not be possible due to UniqueID code above.
assert(Section->getLinkedToSymbol() == LinkedToSym &&
@@ -763,9 +767,11 @@ static MCSectionELF *selectELFSectionForGlobal(
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;
}
// Get the section entry size based on the kind.
@@ -788,7 +794,8 @@ static MCSectionELF *selectELFSectionForGlobal(
if (Kind.isExecuteOnly())
UniqueID = 0;
return Ctx.getELFSection(Name, getELFSectionType(Name, Kind), Flags,
- EntrySize, Group, UniqueID, AssociatedSymbol);
+ EntrySize, Group, IsComdat, UniqueID,
+ AssociatedSymbol);
}
MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal(
@@ -843,11 +850,13 @@ MCSection *TargetLoweringObjectFileELF::getSectionForLSDA(
const auto *LSDA = cast<MCSectionELF>(LSDASection);
unsigned Flags = LSDA->getFlags();
- StringRef Group;
const MCSymbolELF *LinkedToSym = nullptr;
- if (F.hasComdat()) {
- Group = F.getComdat()->getName();
+ StringRef Group;
+ bool IsComdat = false;
+ if (const Comdat *C = getELFComdat(&F)) {
Flags |= ELF::SHF_GROUP;
+ Group = C->getName();
+ IsComdat = C->getSelectionKind() == Comdat::Any;
}
// Use SHF_LINK_ORDER to facilitate --gc-sections if we can use GNU ld>=2.36
// or LLD, which support mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER.
@@ -863,7 +872,8 @@ MCSection *TargetLoweringObjectFileELF::getSectionForLSDA(
return getContext().getELFSection(
(TM.getUniqueSectionNames() ? LSDA->getName() + "." + F.getName()
: LSDA->getName()),
- LSDA->getType(), Flags, 0, Group, MCSection::NonUniqueID, LinkedToSym);
+ LSDA->getType(), Flags, 0, Group, F.hasComdat(), MCSection::NonUniqueID,
+ LinkedToSym);
}
bool TargetLoweringObjectFileELF::shouldPutJumpTableInFunctionSection(
@@ -929,8 +939,8 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
GroupName = F.getComdat()->getName().str();
}
return getContext().getELFSection(Name, ELF::SHT_PROGBITS, Flags,
- 0 /* Entry Size */, GroupName, UniqueID,
- nullptr);
+ 0 /* Entry Size */, GroupName,
+ F.hasComdat(), UniqueID, nullptr);
}
static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray,
@@ -939,7 +949,7 @@ static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray,
std::string Name;
unsigned Type;
unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE;
- StringRef COMDAT = KeySym ? KeySym->getName() : "";
+ StringRef Comdat = KeySym ? KeySym->getName() : "";
if (KeySym)
Flags |= ELF::SHF_GROUP;
@@ -968,7 +978,7 @@ static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray,
Type = ELF::SHT_PROGBITS;
}
- return Ctx.getELFSection(Name, Type, Flags, 0, COMDAT);
+ return Ctx.getELFSection(Name, Type, Flags, 0, Comdat, /*IsComdat=*/true);
}
MCSection *TargetLoweringObjectFileELF::getStaticCtorSection(
@@ -1022,7 +1032,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForCommandLines() const {
// -frecord-gcc-switches which in turn attempts to mimic GCC's switch of the
// same name.
return getContext().getELFSection(".GCC.command.line", ELF::SHT_PROGBITS,
- ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
+ ELF::SHF_MERGE | ELF::SHF_STRINGS, 1);
}
void