From a4b521b7fc53e1bd26a820758eb1cef9b975bd2b Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sun, 15 Sep 2013 19:24:16 +0000 Subject: [PATCH] MC: Add support for '?' flags in .section directives Summary: The '?' flag uses the last section group if the last had a section group. We treat combining an explicit section group and the '?' as a hard error. This fixes PR17198. Reviewers: rafael, bkramer Reviewed By: bkramer CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1686 llvm-svn: 190768 --- llvm/lib/MC/MCParser/ELFAsmParser.cpp | 22 ++++++++++++++++++++-- llvm/test/MC/ELF/comdat.s | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp index 964f915679bb..67b0e5df24aa 100644 --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -16,6 +16,7 @@ #include "llvm/MC/MCParser/MCAsmLexer.h" #include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCStreamer.h" +#include "llvm/MC/MCSymbol.h" #include "llvm/Support/ELF.h" using namespace llvm; @@ -278,7 +279,7 @@ static SectionKind computeSectionKind(unsigned Flags) { return SectionKind::getDataRel(); } -static int parseSectionFlags(StringRef flagsStr) { +static int parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) { int flags = 0; for (unsigned i = 0; i < flagsStr.size(); i++) { @@ -310,6 +311,9 @@ static int parseSectionFlags(StringRef flagsStr) { case 'G': flags |= ELF::SHF_GROUP; break; + case '?': + *UseLastGroup = true; + break; default: return -1; } @@ -351,6 +355,7 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush) { StringRef GroupName; unsigned Flags = 0; const MCExpr *Subsection = 0; + bool UseLastGroup = false; // Set the defaults first. if (SectionName == ".fini" || SectionName == ".init" || @@ -376,13 +381,16 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush) { StringRef FlagsStr = getTok().getStringContents(); Lex(); - int extraFlags = parseSectionFlags(FlagsStr); + int extraFlags = parseSectionFlags(FlagsStr, &UseLastGroup); if (extraFlags < 0) return TokError("unknown flag"); Flags |= extraFlags; bool Mergeable = Flags & ELF::SHF_MERGE; bool Group = Flags & ELF::SHF_GROUP; + if (Group && UseLastGroup) + return TokError("Section cannot specifiy a group name while also acting " + "as a member of the last group"); if (getLexer().isNot(AsmToken::Comma)) { if (Mergeable) @@ -460,6 +468,16 @@ EndStmt: return TokError("unknown section type"); } + if (UseLastGroup) { + MCSectionSubPair CurrentSection = getStreamer().getCurrentSection(); + if (const MCSectionELF *Section = + cast_or_null(CurrentSection.first)) + if (const MCSymbol *Group = Section->getGroup()) { + GroupName = Group->getName(); + Flags |= ELF::SHF_GROUP; + } + } + SectionKind Kind = computeSectionKind(Flags); getStreamer().SwitchSection(getContext().getELFSection(SectionName, Type, Flags, Kind, Size, diff --git a/llvm/test/MC/ELF/comdat.s b/llvm/test/MC/ELF/comdat.s index 6dbe583df015..3e4a001f05ad 100644 --- a/llvm/test/MC/ELF/comdat.s +++ b/llvm/test/MC/ELF/comdat.s @@ -82,7 +82,7 @@ g1: nop - .section .bar,"axG",@progbits,g1,comdat + .section .bar,"ax?",@progbits nop .section .zed,"axG",@progbits,g2,comdat