diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2010-09-16 17:05:55 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2010-09-16 17:05:55 +0000 |
| commit | f7f433200be47ca1db6ebdcd93404cae875b9a38 (patch) | |
| tree | feb5a20365aa3e6480db078e6a14a43211d49ee9 /llvm/lib/MC | |
| parent | 3e9e2fcadd6c700c358bf08af2bbb346900341f9 (diff) | |
| download | bcm5719-llvm-f7f433200be47ca1db6ebdcd93404cae875b9a38.tar.gz bcm5719-llvm-f7f433200be47ca1db6ebdcd93404cae875b9a38.zip | |
Make sure that names like .note.GNU-stack are accepted as valid section names.
llvm-svn: 114091
Diffstat (limited to 'llvm/lib/MC')
| -rw-r--r-- | llvm/lib/MC/MCParser/ELFAsmParser.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp index ddf988faa64..072befadd5f 100644 --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -118,6 +118,9 @@ public: bool ParseDirectiveSection(StringRef, SMLoc); bool ParseDirectiveSize(StringRef, SMLoc); bool ParseDirectivePrevious(StringRef, SMLoc); + +private: + bool ParseSectionName(StringRef &SectionName); }; } @@ -155,11 +158,43 @@ bool ELFAsmParser::ParseDirectiveSize(StringRef, SMLoc) { 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; |

