[PATCH] MC: Add support for '?' flags in .section directives
David Majnemer
david.majnemer at gmail.com
Fri Sep 13 21:29:09 PDT 2013
Hi rafael,
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.
http://llvm-reviews.chandlerc.com/D1686
Files:
lib/MC/MCParser/ELFAsmParser.cpp
test/MC/ELF/comdat.s
Index: lib/MC/MCParser/ELFAsmParser.cpp
===================================================================
--- lib/MC/MCParser/ELFAsmParser.cpp
+++ 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;
@@ -279,7 +280,7 @@
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++) {
@@ -311,6 +312,9 @@
case 'G':
flags |= ELF::SHF_GROUP;
break;
+ case '?':
+ *UseLastGroup = true;
+ break;
default:
return -1;
}
@@ -352,6 +356,7 @@
StringRef GroupName;
unsigned Flags = 0;
const MCExpr *Subsection = 0;
+ bool UseLastGroup = false;
// Set the defaults first.
if (SectionName == ".fini" || SectionName == ".init" ||
@@ -377,13 +382,16 @@
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)
@@ -461,6 +469,16 @@
return TokError("unknown section type");
}
+ if (UseLastGroup) {
+ MCSectionSubPair CurrentSection = getStreamer().getCurrentSection();
+ if (const MCSectionELF *Section =
+ cast_or_null<MCSectionELF>(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,
Index: test/MC/ELF/comdat.s
===================================================================
--- test/MC/ELF/comdat.s
+++ test/MC/ELF/comdat.s
@@ -82,7 +82,7 @@
g1:
nop
- .section .bar,"axG", at progbits,g1,comdat
+ .section .bar,"ax?", at progbits
nop
.section .zed,"axG", at progbits,g2,comdat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1686.1.patch
Type: text/x-patch
Size: 2645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130913/673abfcd/attachment.bin>
More information about the llvm-commits
mailing list