[llvm-commits] [llvm] r114091 - in /llvm/trunk: lib/MC/MCParser/ELFAsmParser.cpp test/MC/ELF/section.s
Rafael Espindola
rafael.espindola at gmail.com
Thu Sep 16 10:05:56 PDT 2010
Author: rafael
Date: Thu Sep 16 12:05:55 2010
New Revision: 114091
URL: http://llvm.org/viewvc/llvm-project?rev=114091&view=rev
Log:
Make sure that names like .note.GNU-stack are accepted as valid section names.
Added:
llvm/trunk/test/MC/ELF/section.s
Modified:
llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
Modified: llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp?rev=114091&r1=114090&r2=114091&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp Thu Sep 16 12:05:55 2010
@@ -118,6 +118,9 @@
bool ParseDirectiveSection(StringRef, SMLoc);
bool ParseDirectiveSize(StringRef, SMLoc);
bool ParseDirectivePrevious(StringRef, SMLoc);
+
+private:
+ bool ParseSectionName(StringRef &SectionName);
};
}
@@ -155,11 +158,43 @@
return false;
}
+bool ELFAsmParser::ParseSectionName(StringRef &SectionName) {
+ // A section name can contain -, so we cannot just use
+ // ParseIdentifier.
+ SMLoc FirstLoc = getLexer().getLoc();
+ unsigned Size = 0;
+
+ for (;;) {
+ StringRef Tmp;
+ unsigned CurSize;
+
+ SMLoc PrevLoc = getLexer().getLoc();
+ if (getLexer().is(AsmToken::Minus)) {
+ CurSize = 1;
+ Lex(); // Consume the "-".
+ } else if (!getParser().ParseIdentifier(Tmp))
+ CurSize = Tmp.size();
+ else
+ break;
+
+ Size += CurSize;
+ SectionName = StringRef(FirstLoc.getPointer(), Size);
+
+ // Make sure the following token is adjacent.
+ if (PrevLoc.getPointer() + CurSize != getTok().getLoc().getPointer())
+ break;
+ }
+ if (Size == 0)
+ return true;
+
+ return false;
+}
+
// FIXME: This is a work in progress.
bool ELFAsmParser::ParseDirectiveSection(StringRef, SMLoc) {
StringRef SectionName;
- // FIXME: This doesn't parse section names like ".note.GNU-stack" correctly.
- if (getParser().ParseIdentifier(SectionName))
+
+ if (ParseSectionName(SectionName))
return TokError("expected identifier in directive");
std::string FlagsStr;
Added: llvm/trunk/test/MC/ELF/section.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/section.s?rev=114091&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/section.s (added)
+++ llvm/trunk/test/MC/ELF/section.s Thu Sep 16 12:05:55 2010
@@ -0,0 +1,11 @@
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s
+
+// Test that these names are accepted.
+
+.section .note.GNU-stack,"", at progbits
+.section .note.GNU-,"", at progbits
+.section -.note.GNU,"", at progbits
+
+// CHECK: ('sh_name', 18) # '.note.GNU-stack'
+// CHECK: ('sh_name', 34) # '.note.GNU-'
+// CHECK: ('sh_name', 45) # '-.note.GNU'
More information about the llvm-commits
mailing list