Index: include/llvm/MC/MCELFStreamer.h =================================================================== --- include/llvm/MC/MCELFStreamer.h +++ include/llvm/MC/MCELFStreamer.h @@ -81,6 +81,10 @@ void EmitBundleLock(bool AlignToEnd) override; void EmitBundleUnlock() override; + MCSection *getNamedGroupSection(StringRef Section, StringRef Identifer, + unsigned Type, unsigned Flags, + unsigned EntSize) override; + private: bool isBundleLocked() const; void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override; Index: include/llvm/MC/MCStreamer.h =================================================================== --- include/llvm/MC/MCStreamer.h +++ include/llvm/MC/MCStreamer.h @@ -760,6 +760,16 @@ /// Get the .xdata section used for the given section. MCSection *getAssociatedXDataSection(const MCSection *TextSec); + /// Get a group section with the provided group identifier. This is in ELF, + /// for instance, named by concatenating \p Section with '.' then \p + /// Identifier. The \p Type describes the type of the section and \p Flags are + /// used to further configure this named section. + virtual MCSection *getNamedGroupSection(StringRef Section, + StringRef Identifier, + unsigned Type, + unsigned Flags, + unsigned EntSize); + virtual void EmitSyntaxDirective(); /// \brief Emit a .reloc directive. 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 = Streamer.getNamedGroupSection(".data", Label->getName(), + ELF::SHT_PROGBITS, Flags, 0); unsigned Size = DL.getPointerSize(); Streamer.SwitchSection(Sec); Streamer.EmitValueToAlignment(DL.getPointerABIAlignment()); Index: lib/MC/MCAsmStreamer.cpp =================================================================== --- lib/MC/MCAsmStreamer.cpp +++ lib/MC/MCAsmStreamer.cpp @@ -23,6 +23,7 @@ #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSectionCOFF.h" #include "llvm/MC/MCSectionMachO.h" +#include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbolELF.h" #include "llvm/Support/ErrorHandling.h" @@ -56,6 +57,9 @@ void EmitRegisterName(int64_t Register); void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override; void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override; + MCSection *getNamedGroupSection(StringRef Section, StringRef Identifier, + unsigned Type, unsigned Flags, + unsigned EntSize) override; public: MCAsmStreamer(MCContext &Context, std::unique_ptr os, @@ -1568,3 +1572,13 @@ return new MCAsmStreamer(Context, std::move(OS), isVerboseAsm, useDwarfDirectory, IP, CE, MAB, ShowInst); } + +MCSection *MCAsmStreamer::getNamedGroupSection(StringRef Section, + StringRef Identifier, + unsigned Type, unsigned Flags, + unsigned EntSize) { + SmallString<64> FullName(Section); + FullName += "."; + FullName += Identifier; + return getContext().getELFSection(FullName, Type, Flags, EntSize, Identifier); +} Index: lib/MC/MCELFStreamer.cpp =================================================================== --- lib/MC/MCELFStreamer.cpp +++ lib/MC/MCELFStreamer.cpp @@ -672,3 +672,14 @@ uint64_t Size, unsigned ByteAlignment) { llvm_unreachable("ELF doesn't support this directive"); } + +MCSection *MCELFStreamer::getNamedGroupSection(StringRef Section, + StringRef Identifier, + unsigned Type, + unsigned Flags, + unsigned EntSize) { + SmallString<64> FullName(Section); + FullName += "."; + FullName += Identifier; + return getContext().getELFSection(FullName, Type, Flags, EntSize, Identifier); +} Index: lib/MC/MCStreamer.cpp =================================================================== --- lib/MC/MCStreamer.cpp +++ lib/MC/MCStreamer.cpp @@ -806,3 +806,9 @@ EmitLabel(Sym); return Sym; } + +MCSection *MCStreamer::getNamedGroupSection(StringRef, StringRef, unsigned, + unsigned, unsigned) { + llvm_unreachable("Not implemented."); + return nullptr; +}