From 00619943f0910f485f2fdb8f9563d840f0127c1b Mon Sep 17 00:00:00 2001 From: Simon Dardis Date: Thu, 22 Jun 2017 10:41:51 +0000 Subject: [PATCH] [mips] Implement the ".rdata" MIPS assembly directive. Rather than creating a separate ".rdata" section distinct from the customary ".rodata" in ELF, ".rdata" switches to the ".rodata" section. This patch relands r305949 and r305950 with the correct commit message and addresses nit raised during review. Patch By: John Baldwin! Differential Revision: https://reviews.llvm.org/D34452 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305995 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 22 +++++++++++++++++++++ test/MC/Mips/mips-rdata.s | 13 ++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/MC/Mips/mips-rdata.s diff --git a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index 694c201cbe8..8a8cf562abe 100644 --- a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -322,6 +322,7 @@ class MipsAsmParser : public MCTargetAsmParser { bool parseDirectiveSet(); bool parseDirectiveOption(); bool parseInsnDirective(); + bool parseRSectionDirective(StringRef Section); bool parseSSectionDirective(StringRef Section, unsigned Type); bool parseSetAtDirective(); @@ -6952,6 +6953,23 @@ bool MipsAsmParser::parseInsnDirective() { return false; } +/// parseRSectionDirective +/// ::= .rdata +bool MipsAsmParser::parseRSectionDirective(StringRef Section) { + // If this is not the end of the statement, report an error. + if (getLexer().isNot(AsmToken::EndOfStatement)) { + reportParseError("unexpected token, expected end of statement"); + return false; + } + + MCSection *ELFSection = getContext().getELFSection( + Section, ELF::SHT_PROGBITS, ELF::SHF_ALLOC); + getParser().getStreamer().SwitchSection(ELFSection); + + getParser().Lex(); // Eat EndOfStatement token. + return false; +} + /// parseSSectionDirective /// ::= .sbss /// ::= .sdata @@ -7499,6 +7517,10 @@ bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) { parseInsnDirective(); return false; } + if (IDVal == ".rdata") { + parseRSectionDirective(".rodata"); + return false; + } if (IDVal == ".sbss") { parseSSectionDirective(IDVal, ELF::SHT_NOBITS); return false; diff --git a/test/MC/Mips/mips-rdata.s b/test/MC/Mips/mips-rdata.s new file mode 100644 index 00000000000..89f96195297 --- /dev/null +++ b/test/MC/Mips/mips-rdata.s @@ -0,0 +1,13 @@ +# Check that .rdata sections have proper name, flags, and section types. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o - \ +# RUN: | llvm-readobj -s | FileCheck %s + + .rdata + .word 0 + +# CHECK: Name: .rodata +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ (0x2) +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] -- 2.40.0