1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00

Make sure that names like .note.GNU-stack are accepted as valid section names.

llvm-svn: 114091
This commit is contained in:
Rafael Espindola 2010-09-16 17:05:55 +00:00
parent 58aa9e8010
commit fa964e153e
2 changed files with 48 additions and 2 deletions

View File

@ -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;

11
test/MC/ELF/section.s Normal file
View File

@ -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,"",@progbits
.section .note.GNU-,"",@progbits
.section -.note.GNU,"",@progbits
// CHECK: ('sh_name', 18) # '.note.GNU-stack'
// CHECK: ('sh_name', 34) # '.note.GNU-'
// CHECK: ('sh_name', 45) # '-.note.GNU'