[PATCH] D29719: [MC] Accept and print a numeric value as an ELF section header's type
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 24 04:57:33 PST 2017
Wouldn't it be better to define a @newtype value?
Cheers,
Rafael
Simon Atanasyan via Phabricator <reviews at reviews.llvm.org> writes:
> atanasyan created this revision.
>
> GAS supports specification of section header's type using a numeric value [1]. This patch brings the same functionality to LLVM. That allows to setup and print some target-specific section types belong to the SHT_LOPROC - SHT_HIPROC range.
>
>
>
> [1] https://sourceware.org/binutils/docs/as/Section.html
>
>
> Repository:
> rL LLVM
>
> https://reviews.llvm.org/D29719
>
> Files:
> lib/MC/MCParser/ELFAsmParser.cpp
> lib/MC/MCSectionELF.cpp
> test/MC/ELF/section-numeric-type.s
>
>
> Index: test/MC/ELF/section-numeric-type.s
> ===================================================================
> --- /dev/null
> +++ test/MC/ELF/section-numeric-type.s
> @@ -0,0 +1,26 @@
> +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux-gnu %s -o - \
> +// RUN: | llvm-readobj -s -t | FileCheck --check-prefix=OBJ %s
> +
> +// RUN: llvm-mc -filetype=asm -triple=x86_64-pc-linux-gnu %s -o - \
> +// RUN: | FileCheck --check-prefix=ASM %s
> +
> + .section .sec1,"a", at 0x70000001
> + .section .sec2,"a", at 1879048193
> + .section .sec3,"a", at 0x7fffffff
> +
> +// OBJ: Section {
> +// OBJ: Name: .sec1
> +// OBJ-NEXT: Type: SHT_X86_64_UNWIND (0x70000001)
> +// OBJ: }
> +// OBJ: Section {
> +// OBJ: Name: .sec2
> +// OBJ-NEXT: Type: SHT_X86_64_UNWIND (0x70000001)
> +// OBJ: }
> +// OBJ: Section {
> +// OBJ: Name: .sec3
> +// OBJ-NEXT: Type: (0x7FFFFFFF)
> +// OBJ: }
> +
> +// ASM: .section .sec1,"a", at unwind
> +// ASM: .section .sec2,"a", at unwind
> +// ASM: .section .sec3,"a", at 0x7fffffff
> Index: lib/MC/MCSectionELF.cpp
> ===================================================================
> --- lib/MC/MCSectionELF.cpp
> +++ lib/MC/MCSectionELF.cpp
> @@ -13,6 +13,7 @@
> #include "llvm/MC/MCExpr.h"
> #include "llvm/MC/MCSymbol.h"
> #include "llvm/Support/ELF.h"
> +#include "llvm/Support/Format.h"
> #include "llvm/Support/raw_ostream.h"
>
> using namespace llvm;
> @@ -142,6 +143,8 @@
> OS << "progbits";
> else if (Type == ELF::SHT_X86_64_UNWIND)
> OS << "unwind";
> + else
> + OS << format_hex(Type, 0);
>
> if (EntrySize) {
> assert(Flags & ELF::SHF_MERGE);
> Index: lib/MC/MCParser/ELFAsmParser.cpp
> ===================================================================
> --- lib/MC/MCParser/ELFAsmParser.cpp
> +++ lib/MC/MCParser/ELFAsmParser.cpp
> @@ -391,7 +391,10 @@
> return TokError("expected '@<type>', '%<type>' or \"<type>\"");
> if (!L.is(AsmToken::String))
> Lex();
> - if (getParser().parseIdentifier(TypeName))
> + if (L.is(AsmToken::Integer)) {
> + TypeName = getTok().getString();
> + Lex();
> + } else if (getParser().parseIdentifier(TypeName))
> return TokError("expected identifier in directive");
> return false;
> }
> @@ -557,7 +560,7 @@
> Type = ELF::SHT_NOTE;
> else if (TypeName == "unwind")
> Type = ELF::SHT_X86_64_UNWIND;
> - else
> + else if (TypeName.getAsInteger(0, Type))
> return TokError("unknown section type");
> }
>
>
>
> Index: test/MC/ELF/section-numeric-type.s
> ===================================================================
> --- /dev/null
> +++ test/MC/ELF/section-numeric-type.s
> @@ -0,0 +1,26 @@
> +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux-gnu %s -o - \
> +// RUN: | llvm-readobj -s -t | FileCheck --check-prefix=OBJ %s
> +
> +// RUN: llvm-mc -filetype=asm -triple=x86_64-pc-linux-gnu %s -o - \
> +// RUN: | FileCheck --check-prefix=ASM %s
> +
> + .section .sec1,"a", at 0x70000001
> + .section .sec2,"a", at 1879048193
> + .section .sec3,"a", at 0x7fffffff
> +
> +// OBJ: Section {
> +// OBJ: Name: .sec1
> +// OBJ-NEXT: Type: SHT_X86_64_UNWIND (0x70000001)
> +// OBJ: }
> +// OBJ: Section {
> +// OBJ: Name: .sec2
> +// OBJ-NEXT: Type: SHT_X86_64_UNWIND (0x70000001)
> +// OBJ: }
> +// OBJ: Section {
> +// OBJ: Name: .sec3
> +// OBJ-NEXT: Type: (0x7FFFFFFF)
> +// OBJ: }
> +
> +// ASM: .section .sec1,"a", at unwind
> +// ASM: .section .sec2,"a", at unwind
> +// ASM: .section .sec3,"a", at 0x7fffffff
> Index: lib/MC/MCSectionELF.cpp
> ===================================================================
> --- lib/MC/MCSectionELF.cpp
> +++ lib/MC/MCSectionELF.cpp
> @@ -13,6 +13,7 @@
> #include "llvm/MC/MCExpr.h"
> #include "llvm/MC/MCSymbol.h"
> #include "llvm/Support/ELF.h"
> +#include "llvm/Support/Format.h"
> #include "llvm/Support/raw_ostream.h"
>
> using namespace llvm;
> @@ -142,6 +143,8 @@
> OS << "progbits";
> else if (Type == ELF::SHT_X86_64_UNWIND)
> OS << "unwind";
> + else
> + OS << format_hex(Type, 0);
>
> if (EntrySize) {
> assert(Flags & ELF::SHF_MERGE);
> Index: lib/MC/MCParser/ELFAsmParser.cpp
> ===================================================================
> --- lib/MC/MCParser/ELFAsmParser.cpp
> +++ lib/MC/MCParser/ELFAsmParser.cpp
> @@ -391,7 +391,10 @@
> return TokError("expected '@<type>', '%<type>' or \"<type>\"");
> if (!L.is(AsmToken::String))
> Lex();
> - if (getParser().parseIdentifier(TypeName))
> + if (L.is(AsmToken::Integer)) {
> + TypeName = getTok().getString();
> + Lex();
> + } else if (getParser().parseIdentifier(TypeName))
> return TokError("expected identifier in directive");
> return false;
> }
> @@ -557,7 +560,7 @@
> Type = ELF::SHT_NOTE;
> else if (TypeName == "unwind")
> Type = ELF::SHT_X86_64_UNWIND;
> - else
> + else if (TypeName.getAsInteger(0, Type))
> return TokError("unknown section type");
> }
>
More information about the llvm-commits
mailing list