[llvm] r260498 - [MC][ELF] Handle MIPS specific .sdata and .sbss directives
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 10 22:45:54 PST 2016
Author: atanasyan
Date: Thu Feb 11 00:45:54 2016
New Revision: 260498
URL: http://llvm.org/viewvc/llvm-project?rev=260498&view=rev
Log:
[MC][ELF] Handle MIPS specific .sdata and .sbss directives
MIPS specific .sdata and .sbss directives create corresponding sections
with proper initialized ELF flags including ELF::SHF_MIPS_GPREL.
Differential Revision: http://reviews.llvm.org/D17001
Added:
llvm/trunk/test/CodeGen/Mips/mips-shf-gprel.s
Removed:
llvm/trunk/test/CodeGen/Mips/mips-shf-gprel.ll
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=260498&r1=260497&r2=260498&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp Thu Feb 11 00:45:54 2016
@@ -23,10 +23,12 @@
#include "llvm/MC/MCParser/MCAsmLexer.h"
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
+#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/ELF.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetRegistry.h"
@@ -266,6 +268,7 @@ class MipsAsmParser : public MCTargetAsm
bool parseDirectiveSet();
bool parseDirectiveOption();
bool parseInsnDirective();
+ bool parseSSectionDirective(StringRef Section, unsigned Type);
bool parseSetAtDirective();
bool parseSetNoAtDirective();
@@ -5734,6 +5737,24 @@ bool MipsAsmParser::parseInsnDirective()
return false;
}
+/// parseSSectionDirective
+/// ::= .sbss
+/// ::= .sdata
+bool MipsAsmParser::parseSSectionDirective(StringRef Section, unsigned Type) {
+ // 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, Type, ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_MIPS_GPREL);
+ getParser().getStreamer().SwitchSection(ELFSection);
+
+ getParser().Lex(); // Eat EndOfStatement token.
+ return false;
+}
+
/// parseDirectiveModule
/// ::= .module oddspreg
/// ::= .module nooddspreg
@@ -6224,6 +6245,11 @@ bool MipsAsmParser::ParseDirective(AsmTo
if (IDVal == ".insn")
return parseInsnDirective();
+ if (IDVal == ".sbss")
+ return parseSSectionDirective(IDVal, ELF::SHT_NOBITS);
+ if (IDVal == ".sdata")
+ return parseSSectionDirective(IDVal, ELF::SHT_PROGBITS);
+
return true;
}
Removed: llvm/trunk/test/CodeGen/Mips/mips-shf-gprel.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/mips-shf-gprel.ll?rev=260497&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/mips-shf-gprel.ll (original)
+++ llvm/trunk/test/CodeGen/Mips/mips-shf-gprel.ll (removed)
@@ -1,24 +0,0 @@
-; Check that .sdata section has SHF_MIPS_GPREL flag.
-
-; RUN: llc -mips-ssection-threshold=16 -mgpopt -mattr=noabicalls \
-; RUN: -relocation-model=static -march=mips -o - %s -filetype=obj \
-; RUN: | llvm-readobj -s | FileCheck %s
-
- at data1 = global [4 x i32] [i32 1, i32 2, i32 3, i32 4], align 4
- at date2 = global [4 x i32] zeroinitializer, align 4
-
-; CHECK: Name: .sdata
-; CHECK-NEXT: Type: SHT_PROGBITS
-; CHECK-NEXT: Flags [ (0x10000003)
-; CHECK-NEXT: SHF_ALLOC
-; CHECK-NEXT: SHF_MIPS_GPREL
-; CHECK-NEXT: SHF_WRITE
-; CHECK-NEXT: ]
-
-; CHECK: Name: .sbss
-; CHECK-NEXT: Type: SHT_NOBITS
-; CHECK-NEXT: Flags [ (0x10000003)
-; CHECK-NEXT: SHF_ALLOC
-; CHECK-NEXT: SHF_MIPS_GPREL
-; CHECK-NEXT: SHF_WRITE
-; CHECK-NEXT: ]
Added: llvm/trunk/test/CodeGen/Mips/mips-shf-gprel.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/mips-shf-gprel.s?rev=260498&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/mips-shf-gprel.s (added)
+++ llvm/trunk/test/CodeGen/Mips/mips-shf-gprel.s Thu Feb 11 00:45:54 2016
@@ -0,0 +1,27 @@
+# Check that .sdata and .sbss sections have SHF_MIPS_GPREL flags
+# and proper section types.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o - \
+# RUN: | llvm-readobj -s | FileCheck %s
+
+ .sdata
+ .word 0
+
+ .sbss
+ .zero 4
+
+# CHECK: Name: .sdata
+# CHECK-NEXT: Type: SHT_PROGBITS
+# CHECK-NEXT: Flags [ (0x10000003)
+# CHECK-NEXT: SHF_ALLOC
+# CHECK-NEXT: SHF_MIPS_GPREL
+# CHECK-NEXT: SHF_WRITE
+# CHECK-NEXT: ]
+
+# CHECK: Name: .sbss
+# CHECK-NEXT: Type: SHT_NOBITS
+# CHECK-NEXT: Flags [ (0x10000003)
+# CHECK-NEXT: SHF_ALLOC
+# CHECK-NEXT: SHF_MIPS_GPREL
+# CHECK-NEXT: SHF_WRITE
+# CHECK-NEXT: ]
More information about the llvm-commits
mailing list