Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp =================================================================== --- lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -2708,7 +2708,7 @@ if (getParser().parseExpression(Value)) return true; - getParser().getStreamer().EmitValue(Value, Size); + getTargetStreamer().emitAlignedDataDirective(Value, Size); if (getLexer().is(AsmToken::EndOfStatement)) break; Index: lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp =================================================================== --- lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp +++ lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp @@ -29,6 +29,10 @@ MipsTargetStreamer::MipsTargetStreamer(MCStreamer &S) : MCTargetStreamer(S), canHaveModuleDirective(true) {} + +void MipsTargetStreamer::emitAlignedDataDirective(const MCExpr *Value, + unsigned Size) {} + void MipsTargetStreamer::emitDirectiveSetMicroMips() {} void MipsTargetStreamer::emitDirectiveSetNoMicroMips() {} void MipsTargetStreamer::emitDirectiveSetMips16() {} @@ -69,6 +73,23 @@ formatted_raw_ostream &OS) : MipsTargetStreamer(S), OS(OS) {} +void MipsTargetAsmStreamer::emitAlignedDataDirective(const MCExpr *Value, + unsigned Size) { + switch (Size) { + case 4: + OS << "\t.word\t"; + break; + case 8: + OS << "\t.dword\t"; + break; + default: + llvm_unreachable("Unexpected alignment"); + } + + Value->print(OS); + OS << "\n"; +} + void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() { OS << "\t.set\tmicromips\n"; setCanHaveModuleDir(false); @@ -404,6 +425,12 @@ return static_cast(Streamer); } +void MipsTargetELFStreamer::emitAlignedDataDirective(const MCExpr *Value, + unsigned Size) { + getStreamer().EmitValueToAlignment(Size, 0, 1, 0); + getStreamer().EmitValue(Value, Size); +} + void MipsTargetELFStreamer::emitDirectiveSetMicroMips() { MicroMipsEnabled = true; Index: lib/Target/Mips/MipsTargetStreamer.h =================================================================== --- lib/Target/Mips/MipsTargetStreamer.h +++ lib/Target/Mips/MipsTargetStreamer.h @@ -21,6 +21,9 @@ class MipsTargetStreamer : public MCTargetStreamer { public: MipsTargetStreamer(MCStreamer &S); + + virtual void emitAlignedDataDirective(const MCExpr *Value, unsigned Size); + virtual void emitDirectiveSetMicroMips(); virtual void emitDirectiveSetNoMicroMips(); virtual void emitDirectiveSetMips16(); @@ -97,6 +100,9 @@ public: MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); + + void emitAlignedDataDirective(const MCExpr *Value, unsigned Size) override; + void emitDirectiveSetMicroMips() override; void emitDirectiveSetNoMicroMips() override; void emitDirectiveSetMips16() override; @@ -154,6 +160,8 @@ void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override; void finish() override; + void emitAlignedDataDirective(const MCExpr *Value, unsigned Size) override; + void emitDirectiveSetMicroMips() override; void emitDirectiveSetNoMicroMips() override; void emitDirectiveSetMips16() override; Index: test/MC/Mips/aligned_data.s =================================================================== --- /dev/null +++ test/MC/Mips/aligned_data.s @@ -0,0 +1,50 @@ +# Test that the .text and .data sections are padded to the AddressAlignment +# before finishing the ELF + +# RUN: llvm-mc %s -arch=mips -mcpu=mips32r2 | FileCheck %s -check-prefix=CHECK-ASM +# +# RUN: llvm-mc %s -arch=mips -mcpu=mips32r2 -filetype=obj -o - | \ +# RUN: llvm-readobj -sections -section-data - | \ +# RUN: FileCheck %s -check-prefix=CHECK-OBJ + +# CHECK-ASM: .text +# CHECK-ASM: .byte 1 +# CHECK-ASM: .word 2 +# CHECK-ASM: .word 3 +# CHECK-ASM: .data +# CHECK-ASM: .byte 1 +# CHECK-ASM: .byte 2 +# CHECK-ASM: .word 3 +# CHECK-ASM: .word 4 + +# CHECK-OBJ: Section { +# CHECK-OBJ-LABEL: Name: .text +# CHECK-OBJ: AddressAlignment: 16 +# CHECK-OBJ: SectionData ( +# CHECK-OBJ: 0000: 01000000 00000002 00000003 00000000 |................| +# CHECK-OBJ: 0010: 00000000 00000004 00000000 00000005 |................| +# CHECK-OBJ: ) +# CHECK-OBJ-LABEL: } +# CHECK-OBJ: Section { +# CHECK-OBJ-LABEL: Name: .data +# CHECK-OBJ: AddressAlignment: 16 +# CHECK-OBJ: SectionData ( +# CHECK-OBJ: 0000: 01020000 00000003 00000004 00000000 |................| +# CHECK-OBJ: 0010: 00000000 00000005 00000000 00000006 |................| +# CHECK-OBJ: ) +# CHECK-OBJ-LABEL: } + + .text + .byte 1 + .word 2 + .word 3 + .dword 4 + .dword 5 + + .data + .byte 1 + .byte 2 + .word 3 + .word 4 + .dword 5 + .dword 6 Index: test/MC/Mips/mips-data-directives.s =================================================================== --- test/MC/Mips/mips-data-directives.s +++ test/MC/Mips/mips-data-directives.s @@ -5,25 +5,25 @@ # RUN: llvm-readobj -sections -section-data -section-relocations - | \ # RUN: FileCheck %s -check-prefix=CHECK-OBJ -# CHECK-ASM: .4byte 3735929054 -# CHECK-ASM: .8byte -2401050962867405073 -# CHECK-ASM: .4byte label -# CHECK-ASM: .8byte label +# CHECK-ASM: .word 3735929054 +# CHECK-ASM: .dword -2401050962867405073 +# CHECK-ASM: .word label +# CHECK-ASM: .dword label # Checking if the data and reloations were correctly emitted # CHECK-OBJ: Section { # CHECK-OBJ: Name: .data (66) # CHECK-OBJ: SectionData ( -# CHECK-OBJ: 0000: DEADC0DE DEADC0DE DEADBEEF 00000000 -# CHECK-OBJ: 0010: 00000000 00000000 +# CHECK-OBJ: 0000: DEADC0DE 00000000 DEADC0DE DEADBEEF +# CHECK-OBJ: 0010: 00000000 00000000 00000000 00000000 # CHECK-OBJ: ) # CHECK-OBJ: } # CHECK-OBJ: Section { # CHECK-OBJ: Name: .rel.data (62) # CHECK-OBJ: Relocations [ -# CHECK-OBJ: 0xC R_MIPS_32 .data 0x0 -# CHECK-OBJ: 0x10 R_MIPS_64 .data 0x0 +# CHECK-OBJ: 0x10 R_MIPS_32 .data 0x0 +# CHECK-OBJ: 0x18 R_MIPS_64 .data 0x0 # CHECK-OBJ: ] # CHECK-OBJ: } Index: test/MC/Mips/mips_directives.s =================================================================== --- test/MC/Mips/mips_directives.s +++ test/MC/Mips/mips_directives.s @@ -30,7 +30,7 @@ .word 0x77fffffc # CHECK: $JTI0_0: # CHECK: .gpword ($BB0_2) -# CHECK: .4byte 2013265916 +# CHECK: .word 2013265916 .set at=$12 .set macro # CHECK: .set reorder