From 4f17f73d872668dc427d1927029cecaecf1cd002 Mon Sep 17 00:00:00 2001 From: Scott Egerton Date: Mon, 15 Feb 2016 16:11:51 +0000 Subject: [PATCH] [mips] Implemented the .hword directive. Summary: In order to pass the tests, this required marking R_MIPS_16 relocations as needing to point to the symbol and not the section. Reviewers: vkalintiris, dsanders Subscribers: dsanders, llvm-commits Differential Revision: http://reviews.llvm.org/D17200 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260896 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 5 +++++ lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp | 1 + test/MC/Mips/mips-data-directives.s | 11 ++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index 6b812d2f16f..247200b7318 100644 --- a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -6216,6 +6216,11 @@ bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) { return false; } + if (IDVal == ".hword") { + parseDataDirective(2, DirectiveID.getLoc()); + return false; + } + if (IDVal == ".option") return parseDirectiveOption(); diff --git a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp index 8967d8414db..b7b07671f6d 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp @@ -412,6 +412,7 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym, case ELF::R_MICROMIPS_LO16: return true; + case ELF::R_MIPS_16: case ELF::R_MIPS_32: if (cast(Sym).getOther() & ELF::STO_MIPS_MICROMIPS) return true; diff --git a/test/MC/Mips/mips-data-directives.s b/test/MC/Mips/mips-data-directives.s index abff7c21c61..390f463c7cb 100644 --- a/test/MC/Mips/mips-data-directives.s +++ b/test/MC/Mips/mips-data-directives.s @@ -7,14 +7,16 @@ # CHECK-ASM: .4byte 3735929054 # CHECK-ASM: .8byte -2401050962867405073 +# CHECK-ASM: .2byte 49374 # CHECK-ASM: .4byte label # CHECK-ASM: .8byte label +# CHECK-ASM: .2byte label # Checking if the data and reloations were correctly emitted # CHECK-OBJ: Section { # CHECK-OBJ: Name: .data # CHECK-OBJ: SectionData ( -# CHECK-OBJ: 0000: DEADC0DE DEADC0DE DEADBEEF 00000000 +# CHECK-OBJ: 0000: DEADC0DE DEADC0DE DEADBEEF C0DE0000 # CHECK-OBJ: 0010: 00000000 00000000 # CHECK-OBJ: ) # CHECK-OBJ: } @@ -22,8 +24,9 @@ # CHECK-OBJ: Section { # CHECK-OBJ: Name: .rel.data # CHECK-OBJ: Relocations [ -# CHECK-OBJ: 0xC R_MIPS_32 .data 0x0 -# CHECK-OBJ: 0x10 R_MIPS_64 .data 0x0 +# CHECK-OBJ: 0xE R_MIPS_32 .data 0x0 +# CHECK-OBJ: 0x12 R_MIPS_64 .data 0x0 +# CHECK-OBJ: 0x1A R_MIPS_16 .data 0x0 # CHECK-OBJ: ] # CHECK-OBJ: } @@ -31,6 +34,8 @@ label: .word 0xdeadc0de .dword 0xdeadc0dedeadbeef + .hword 0xc0de .word label .dword label + .hword label