[llvm] r305995 - [mips] Implement the ".rdata" MIPS assembly directive.

Simon Dardis via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 22 03:41:51 PDT 2017


Author: sdardis
Date: Thu Jun 22 05:41:51 2017
New Revision: 305995

URL: http://llvm.org/viewvc/llvm-project?rev=305995&view=rev
Log:
[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


Added:
    llvm/trunk/test/MC/Mips/mips-rdata.s
Modified:
    llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

Modified: llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp?rev=305995&r1=305994&r2=305995&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp Thu Jun 22 05:41:51 2017
@@ -322,6 +322,7 @@ class MipsAsmParser : public MCTargetAsm
   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(AsmTo
     parseInsnDirective();
     return false;
   }
+  if (IDVal == ".rdata") {
+    parseRSectionDirective(".rodata");
+    return false;
+  }
   if (IDVal == ".sbss") {
     parseSSectionDirective(IDVal, ELF::SHT_NOBITS);
     return false;

Added: llvm/trunk/test/MC/Mips/mips-rdata.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/mips-rdata.s?rev=305995&view=auto
==============================================================================
--- llvm/trunk/test/MC/Mips/mips-rdata.s (added)
+++ llvm/trunk/test/MC/Mips/mips-rdata.s Thu Jun 22 05:41:51 2017
@@ -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: ]




More information about the llvm-commits mailing list