From d4a352609f0ebe8bdea2f70d4e0efae9b5db778e Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 12 Nov 2010 15:47:08 +0000 Subject: [PATCH] gnu as support both % and @ before types, do the same. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118893 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCParser/ELFAsmParser.cpp | 14 ++++--------- test/MC/ELF/section.s | 34 +++++++++++++++++--------------- test/MC/ELF/type.s | 29 +++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 test/MC/ELF/type.s diff --git a/lib/MC/MCParser/ELFAsmParser.cpp b/lib/MC/MCParser/ELFAsmParser.cpp index 278f146ad67..b3d5f11e0eb 100644 --- a/lib/MC/MCParser/ELFAsmParser.cpp +++ b/lib/MC/MCParser/ELFAsmParser.cpp @@ -213,12 +213,6 @@ bool ELFAsmParser::ParseDirectiveSection(StringRef, SMLoc) { FlagsStr = getTok().getStringContents(); Lex(); - AsmToken::TokenKind TypeStartToken; - if (getContext().getAsmInfo().getCommentString()[0] == '@') - TypeStartToken = AsmToken::Percent; - else - TypeStartToken = AsmToken::At; - bool Mergeable = FlagsStr.find('M') != StringRef::npos; bool Group = FlagsStr.find('G') != StringRef::npos; @@ -229,8 +223,8 @@ bool ELFAsmParser::ParseDirectiveSection(StringRef, SMLoc) { return TokError("Group section must specify the type"); } else { Lex(); - if (getLexer().isNot(TypeStartToken)) - return TokError("expected the type"); + if (getLexer().isNot(AsmToken::Percent) && getLexer().isNot(AsmToken::At)) + return TokError("expected '@' or '%' before type"); Lex(); if (getParser().ParseIdentifier(TypeName)) @@ -359,8 +353,8 @@ bool ELFAsmParser::ParseDirectiveType(StringRef, SMLoc) { return TokError("unexpected token in '.type' directive"); Lex(); - if (getLexer().isNot(AsmToken::At)) - return TokError("expected '@' before type"); + if (getLexer().isNot(AsmToken::Percent) && getLexer().isNot(AsmToken::At)) + return TokError("expected '@' or '%' before type"); Lex(); StringRef Type; diff --git a/test/MC/ELF/section.s b/test/MC/ELF/section.s index 9e9129df8f3..f3700cae679 100644 --- a/test/MC/ELF/section.s +++ b/test/MC/ELF/section.s @@ -3,12 +3,14 @@ // Test that these names are accepted. .section .note.GNU-stack,"",@progbits +.section .note.GNU-stack2,"",%progbits .section .note.GNU-,"",@progbits .section -.note.GNU,"",@progbits // CHECK: ('sh_name', 0x00000012) # '.note.GNU-stack' -// CHECK: ('sh_name', 0x00000022) # '.note.GNU-' -// CHECK: ('sh_name', 0x0000002d) # '-.note.GNU' +// CHECK: ('sh_name', 0x00000022) # '.note.GNU-stack2' +// CHECK: ('sh_name', 0x00000033) # '.note.GNU-' +// CHECK: ('sh_name', 0x0000003e) # '-.note.GNU' // Test that the dafults are used @@ -16,19 +18,7 @@ .section .fini .section .rodata -// CHECK: (('sh_name', 0x00000038) # '.init' -// CHECK-NEXT: ('sh_type', 0x00000001) -// CHECK-NEXT: ('sh_flags', 0x00000006) -// CHECK-NEXT: ('sh_addr', 0x00000000) -// CHECK-NEXT: ('sh_offset', 0x00000050) -// CHECK-NEXT: ('sh_size', 0x00000000) -// CHECK-NEXT: ('sh_link', 0x00000000) -// CHECK-NEXT: ('sh_info', 0x00000000) -// CHECK-NEXT: ('sh_addralign', 0x00000001) -// CHECK-NEXT: ('sh_entsize', 0x00000000) -// CHECK-NEXT: ), -// CHECK-NEXT: # Section 0x0000000a -// CHECK-NEXT: (('sh_name', 0x0000003e) # '.fini' +// CHECK: (('sh_name', 0x00000049) # '.init' // CHECK-NEXT: ('sh_type', 0x00000001) // CHECK-NEXT: ('sh_flags', 0x00000006) // CHECK-NEXT: ('sh_addr', 0x00000000) @@ -40,7 +30,19 @@ // CHECK-NEXT: ('sh_entsize', 0x00000000) // CHECK-NEXT: ), // CHECK-NEXT: # Section 0x0000000b -// CHECK-NEXT: (('sh_name', 0x00000044) # '.rodata' +// CHECK-NEXT: (('sh_name', 0x0000004f) # '.fini' +// CHECK-NEXT: ('sh_type', 0x00000001) +// CHECK-NEXT: ('sh_flags', 0x00000006) +// CHECK-NEXT: ('sh_addr', 0x00000000) +// CHECK-NEXT: ('sh_offset', 0x00000050) +// CHECK-NEXT: ('sh_size', 0x00000000) +// CHECK-NEXT: ('sh_link', 0x00000000) +// CHECK-NEXT: ('sh_info', 0x00000000) +// CHECK-NEXT: ('sh_addralign', 0x00000001) +// CHECK-NEXT: ('sh_entsize', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Section 0x0000000c +// CHECK-NEXT: (('sh_name', 0x00000055) # '.rodata' // CHECK-NEXT: ('sh_type', 0x00000001) // CHECK-NEXT: ('sh_flags', 0x00000002) // CHECK-NEXT: ('sh_addr', 0x00000000) diff --git a/test/MC/ELF/type.s b/test/MC/ELF/type.s new file mode 100644 index 00000000000..8738433de66 --- /dev/null +++ b/test/MC/ELF/type.s @@ -0,0 +1,29 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +// Test that both % and @ are accepted. + .global foo + .type foo,%function +foo: + + .global bar + .type bar,@object +bar: + +// CHECK: # Symbol 0x00000004 +// CHECK-NEXT: (('st_name', 0x00000005) # 'bar' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000001) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 0x00000005 +// CHECK-NEXT: (('st_name', 0x00000001) # 'foo' +// CHECK-NEXT: ('st_bind', 0x00000001) +// CHECK-NEXT: ('st_type', 0x00000002) +// CHECK-NEXT: ('st_other', 0x00000000) +// CHECK-NEXT: ('st_shndx', 0x00000001) +// CHECK-NEXT: ('st_value', 0x00000000) +// CHECK-NEXT: ('st_size', 0x00000000) +// CHECK-NEXT: ),