Skip to content

Commit

Permalink
[ELF][gcc compatibility]: support section names with special characte…
Browse files Browse the repository at this point in the history
…rs (e.g. "/")

Adding support for section names with special characters in them (e.g. "/").
GCC successfully compiles such section names.
This also fixes PR24520.

Differential Revision: http://reviews.llvm.org/D15678

llvm-svn: 264038
  • Loading branch information
Marina Yatsina committed Mar 22, 2016
1 parent 976921d commit 33ef7da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 9 additions & 8 deletions llvm/lib/MC/MCParser/ELFAsmParser.cpp
Expand Up @@ -229,22 +229,23 @@ bool ELFAsmParser::ParseSectionName(StringRef &SectionName) {
}

for (;;) {
unsigned CurSize;


SMLoc PrevLoc = getLexer().getLoc();
if (getLexer().is(AsmToken::Minus)) {
CurSize = 1;
Lex(); // Consume the "-".
} else if (getLexer().is(AsmToken::String)) {
if (getLexer().is(AsmToken::Comma) ||
getLexer().is(AsmToken::EndOfStatement))
break;

unsigned CurSize;
if (getLexer().is(AsmToken::String)) {
CurSize = getTok().getIdentifier().size() + 2;
Lex();
} else if (getLexer().is(AsmToken::Identifier)) {
CurSize = getTok().getIdentifier().size();
Lex();
} else {
break;
CurSize = getTok().getString().size();
Lex();
}

Size += CurSize;
SectionName = StringRef(FirstLoc.getPointer(), Size);

Expand Down
4 changes: 4 additions & 0 deletions llvm/test/MC/ELF/section.s
Expand Up @@ -6,11 +6,15 @@
.section .note.GNU-stack2,"",%progbits
.section .note.GNU-,"",@progbits
.section -.note.GNU,"","progbits"
.section src/stack.c,"",@progbits
.section ~!@$%^&*()_-+={[}]|\\:<>,"",@progbits

// CHECK: Name: .note.GNU-stack
// CHECK: Name: .note.GNU-stack2
// CHECK: Name: .note.GNU-
// CHECK: Name: -.note.GNU
// CHECK: Name: src/stack.c
// CHECK: Name: ~!@$%^&*()_-+={[}]|\\:<>

// Test that the defaults are used

Expand Down

0 comments on commit 33ef7da

Please sign in to comment.