Index: include/llvm/MC/MCContext.h =================================================================== --- include/llvm/MC/MCContext.h +++ include/llvm/MC/MCContext.h @@ -380,6 +380,14 @@ const char *BeginSymName, const MCSectionELF *Associated); + /// Get a section with the provided group identifier. This section is + /// named by concatenating \p Prefix with '.' then \p Suffix. The \p Type + /// describes the type of the section and \p Flags are used to further + /// configure this named section. + MCSectionELF *getELFNamedSection(StringRef Prefix, StringRef Suffix, + unsigned Type, unsigned Flags, + unsigned EntrySize = 0); + MCSectionELF *createELFRelSection(StringRef Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -69,11 +69,9 @@ cast(getContext().getOrCreateSymbol(NameData)); Streamer.EmitSymbolAttribute(Label, MCSA_Hidden); Streamer.EmitSymbolAttribute(Label, MCSA_Weak); - StringRef Prefix = ".data."; - NameData.insert(NameData.begin(), Prefix.begin(), Prefix.end()); unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP; - MCSection *Sec = getContext().getELFSection(NameData, ELF::SHT_PROGBITS, - Flags, 0, Label->getName()); + MCSection *Sec = getContext().getELFNamedSection(".data", Label->getName(), + ELF::SHT_PROGBITS, Flags, 0); unsigned Size = DL.getPointerSize(); Streamer.SwitchSection(Sec); Streamer.EmitValueToAlignment(DL.getPointerABIAlignment()); Index: lib/MC/MCContext.cpp =================================================================== --- lib/MC/MCContext.cpp +++ lib/MC/MCContext.cpp @@ -322,6 +322,15 @@ EntrySize, Group, true, nullptr, Associated); } +MCSectionELF *MCContext::getELFNamedSection(StringRef Prefix, StringRef Suffix, + unsigned Type, unsigned Flags, + unsigned EntrySize) { + SmallString<64> FullName(Prefix); + FullName += "."; + FullName += Suffix; + return getELFSection(FullName, Type, Flags, EntrySize, Suffix); +} + MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type, unsigned Flags, unsigned EntrySize, StringRef Group, unsigned UniqueID,