llvm.org GIT mirror llvm / 5356e75
Implement the missing bits corresponding to .mips_hack_elf_flags. These were: * noreorder handling on the target object streamer and asm parser. * setting the initial flag bits based on the enabled features. * setting the elf header flag for micromips It is *really* depressing I am the one doing this instead of someone at mips actually taking the time to understand the infrastructure. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200138 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
13 changed file(s) with 136 addition(s) and 119 deletion(s). Raw diff Collapse all Expand all
804804 EF_MIPS_NOREORDER = 0x00000001, // Don't reorder instructions
805805 EF_MIPS_PIC = 0x00000002, // Position independent code
806806 EF_MIPS_CPIC = 0x00000004, // Call object with Position independent code
807 EF_MIPS_ABI2 = 0x00000020,
808 EF_MIPS_32BITMODE = 0x00000100,
807809 EF_MIPS_ABI_O32 = 0x00001000, // This file follows the first MIPS 32 bit ABI
808810
809811 //ARCH_ASE
193193
194194 bool isEvaluated(const MCExpr *Expr);
195195 bool parseDirectiveSet();
196 bool parseDirectiveMipsHackELFFlags();
197196 bool parseDirectiveOption();
198197
199198 bool parseSetAtDirective();
23102309 return false;
23112310 }
23122311 Options.setNoreorder();
2312 getTargetStreamer().emitDirectiveSetNoReorder();
23132313 Parser.Lex(); // Consume the EndOfStatement.
23142314 return false;
23152315 }
24282428 return true;
24292429 }
24302430
2431 bool MipsAsmParser::parseDirectiveMipsHackELFFlags() {
2432 int64_t Flags = 0;
2433 if (Parser.parseAbsoluteExpression(Flags)) {
2434 TokError("unexpected token");
2435 return false;
2436 }
2437
2438 getTargetStreamer().emitMipsHackELFFlags(Flags);
2439 return false;
2440 }
2441
24422431 /// parseDirectiveWord
24432432 /// ::= .word [ expression (, expression)* ]
24442433 bool MipsAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
25572546 return false;
25582547 }
25592548
2560 if (IDVal == ".mips_hack_elf_flags")
2561 return parseDirectiveMipsHackELFFlags();
2562
25632549 if (IDVal == ".option")
25642550 return parseDirectiveOption();
25652551
133133 bool RelaxAll, bool NoExecStack) {
134134 MCStreamer *S =
135135 createELFStreamer(Context, MAB, OS, Emitter, RelaxAll, NoExecStack);
136 new MipsTargetELFStreamer(*S);
136 new MipsTargetELFStreamer(*S, STI);
137137 return S;
138138 }
139139
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "MipsTargetStreamer.h"
14 #include "MipsMCTargetDesc.h"
1415 #include "llvm/MC/MCELF.h"
1516 #include "llvm/MC/MCSymbol.h"
17 #include "llvm/MC/MCSubtargetInfo.h"
1618 #include "llvm/Support/CommandLine.h"
1719 #include "llvm/Support/ELF.h"
1820 #include "llvm/Support/ErrorHandling.h"
2022
2123 using namespace llvm;
2224
23 static cl::opt PrintHackDirectives("print-hack-directives",
24 cl::init(false), cl::Hidden);
25
2625 // Pin vtable to this file.
2726 void MipsTargetStreamer::anchor() {}
2827
3231 formatted_raw_ostream &OS)
3332 : MipsTargetStreamer(S), OS(OS) {}
3433
35 void MipsTargetAsmStreamer::emitMipsHackELFFlags(unsigned Flags) {
36 if (!PrintHackDirectives)
37 return;
38
39 OS << "\t.mips_hack_elf_flags 0x";
40 OS.write_hex(Flags);
41 OS << '\n';
42 }
43
4434 void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
4535 OS << "\t.set\tmicromips\n";
4636 }
9585 }
9686
9787 // This part is for ELF object output.
98 MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S)
99 : MipsTargetStreamer(S), MicroMipsEnabled(false) {}
88 MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
89 const MCSubtargetInfo &STI)
90 : MipsTargetStreamer(S), MicroMipsEnabled(false) {
91 MCAssembler &MCA = getStreamer().getAssembler();
92 uint64_t Features = STI.getFeatureBits();
93 Triple T(STI.getTargetTriple());
94
95 // Update e_header flags
96 unsigned EFlags = 0;
97
98 // Architecture
99 if (Features & Mips::FeatureMips64r2)
100 EFlags |= ELF::EF_MIPS_ARCH_64R2;
101 else if (Features & Mips::FeatureMips64)
102 EFlags |= ELF::EF_MIPS_ARCH_64;
103 else if (Features & Mips::FeatureMips32r2)
104 EFlags |= ELF::EF_MIPS_ARCH_32R2;
105 else if (Features & Mips::FeatureMips32)
106 EFlags |= ELF::EF_MIPS_ARCH_32;
107
108 if (T.isArch64Bit()) {
109 EFlags |= ELF::EF_MIPS_ABI2;
110 } else {
111 if (Features & Mips::FeatureMips64r2 || Features & Mips::FeatureMips64)
112 EFlags |= ELF::EF_MIPS_32BITMODE;
113
114 // ABI
115 EFlags |= ELF::EF_MIPS_ABI_O32;
116 }
117
118 MCA.setELFHeaderEFlags(EFlags);
119 }
100120
101121 void MipsTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
102122 if (!isMicroMipsEnabled())
116136 return static_cast(Streamer);
117137 }
118138
119 void MipsTargetELFStreamer::emitMipsHackELFFlags(unsigned Flags) {
120 MCAssembler &MCA = getStreamer().getAssembler();
121 MCA.setELFHeaderEFlags(Flags);
122 }
123
124139 void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
125140 MicroMipsEnabled = true;
141
142 MCAssembler &MCA = getStreamer().getAssembler();
143 unsigned Flags = MCA.getELFHeaderEFlags();
144 Flags |= ELF::EF_MIPS_MICROMIPS;
145 MCA.setELFHeaderEFlags(Flags);
126146 }
127147
128148 void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
145165 }
146166
147167 void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
148 // FIXME: implement.
168 MCAssembler &MCA = getStreamer().getAssembler();
169 unsigned Flags = MCA.getELFHeaderEFlags();
170 Flags |= ELF::EF_MIPS_NOREORDER;
171 MCA.setELFHeaderEFlags(Flags);
149172 }
150173
151174 void MipsTargetELFStreamer::emitDirectiveSetMacro() {
175198 void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
176199 MCAssembler &MCA = getStreamer().getAssembler();
177200 unsigned Flags = MCA.getELFHeaderEFlags();
178 Flags |= ELF::EF_MIPS_CPIC;
201 Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
179202 MCA.setELFHeaderEFlags(Flags);
180203 }
181204 void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
635635
636636 }
637637
638 static void emitELFHeaderFlagsCG(MipsTargetStreamer &TargetStreamer,
639 const MipsSubtarget &Subtarget) {
640 // Update e_header flags
641 unsigned EFlags = 0;
642
643 // TODO: Need to add -mabicalls and -mno-abicalls flags.
644 // Currently we assume that -mabicalls is the default.
645 EFlags |= ELF::EF_MIPS_CPIC;
646
647 if (Subtarget.inMips16Mode())
648 EFlags |= ELF::EF_MIPS_ARCH_ASE_M16;
649 else
650 EFlags |= ELF::EF_MIPS_NOREORDER;
651
652 // Architecture
653 if (Subtarget.hasMips64r2())
654 EFlags |= ELF::EF_MIPS_ARCH_64R2;
655 else if (Subtarget.hasMips64())
656 EFlags |= ELF::EF_MIPS_ARCH_64;
657 else if (Subtarget.hasMips32r2())
658 EFlags |= ELF::EF_MIPS_ARCH_32R2;
659 else
660 EFlags |= ELF::EF_MIPS_ARCH_32;
661
662 if (Subtarget.inMicroMipsMode())
663 EFlags |= ELF::EF_MIPS_MICROMIPS;
664
665 // ABI
666 if (Subtarget.isABI_O32())
667 EFlags |= ELF::EF_MIPS_ABI_O32;
668
669 // Relocation Model
670 Reloc::Model RM = Subtarget.getRelocationModel();
671 if (RM == Reloc::PIC_ || RM == Reloc::Default)
672 EFlags |= ELF::EF_MIPS_PIC;
673 else if (RM == Reloc::Static)
674 ; // Do nothing for Reloc::Static
675 else
676 llvm_unreachable("Unsupported relocation model for e_flags");
677
678 TargetStreamer.emitMipsHackELFFlags(EFlags);
679 }
680
681638 void MipsAsmPrinter::EmitEndOfAsmFile(Module &M) {
682639 // Emit Mips ELF register info
683640 Subtarget->getMReginfo().emitMipsReginfoSectionCG(
684641 OutStreamer, getObjFileLowering(), *Subtarget);
685 emitELFHeaderFlagsCG(getTargetStreamer(), *Subtarget);
686642 }
687643
688644 void MipsAsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
1818
1919 public:
2020 MipsTargetStreamer(MCStreamer &S);
21 virtual void emitMipsHackELFFlags(unsigned Flags) = 0;
2221 virtual void emitDirectiveSetMicroMips() = 0;
2322 virtual void emitDirectiveSetNoMicroMips() = 0;
2423 virtual void emitDirectiveSetMips16() = 0;
4342
4443 public:
4544 MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
46 virtual void emitMipsHackELFFlags(unsigned Flags);
4745 virtual void emitDirectiveSetMicroMips();
4846 virtual void emitDirectiveSetNoMicroMips();
4947 virtual void emitDirectiveSetMips16();
6967 public:
7068 bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
7169 MCELFStreamer &getStreamer();
72 MipsTargetELFStreamer(MCStreamer &S);
70 MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
7371
7472 virtual void emitLabel(MCSymbol *Symbol) LLVM_OVERRIDE;
7573
76 // FIXME: emitMipsHackELFFlags() will be removed from this class.
77 virtual void emitMipsHackELFFlags(unsigned Flags);
7874 virtual void emitDirectiveSetMicroMips();
7975 virtual void emitDirectiveSetNoMicroMips();
8076 virtual void emitDirectiveSetMips16();
1515 ; Note that EF_MIPS_CPIC is set by -mabicalls which is the default on Linux
1616 ; TODO need to support -mno-abicalls
1717
18 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32 -relocation-model=static %s -print-hack-directives -o - | FileCheck -check-prefix=CHECK-BE32 %s
19 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32 -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-BE32_PIC %s
20 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -relocation-model=static %s -print-hack-directives -o - | FileCheck -check-prefix=CHECK-BE32R2 %s
21 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-BE32R2_PIC %s
22 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+micromips -relocation-model=static -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-BE32R2-MICROMIPS %s
23 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+micromips -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-BE32R2-MICROMIPS_PIC %s
18 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32 -relocation-model=static %s -o - | FileCheck -check-prefix=CHECK-BE32 %s
19 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32 %s -o - | FileCheck -check-prefix=CHECK-BE32_PIC %s
20 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -relocation-model=static %s -o - | FileCheck -check-prefix=CHECK-BE32R2 %s
21 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 %s -o - | FileCheck -check-prefix=CHECK-BE32R2_PIC %s
22 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+micromips -relocation-model=static %s -o - | FileCheck -check-prefix=CHECK-BE32R2-MICROMIPS %s
23 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+micromips %s -o - | FileCheck -check-prefix=CHECK-BE32R2-MICROMIPS_PIC %s
2424
25 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64 -relocation-model=static %s -print-hack-directives -o - | FileCheck -check-prefix=CHECK-BE64 %s
26 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64 %s -print-hack-directives -o - | FileCheck -check-prefix=CHECK-BE64_PIC %s
27 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64r2 -relocation-model=static -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-BE64R2 %s
28 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64r2 -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-BE64R2_PIC %s
25 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64 -relocation-model=static %s -o - | FileCheck -check-prefix=CHECK-BE64 %s
26 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64 %s -o - | FileCheck -check-prefix=CHECK-BE64_PIC %s
27 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64r2 -relocation-model=static %s -o - | FileCheck -check-prefix=CHECK-BE64R2 %s
28 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64r2 %s -o - | FileCheck -check-prefix=CHECK-BE64R2_PIC %s
2929
30 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+mips16 -relocation-model=pic -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-LE32R2-MIPS16 %s
30 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+mips16 -relocation-model=pic %s -o - | FileCheck -check-prefix=CHECK-LE32R2-MIPS16 %s
3131
3232 ; 32(R1) bit with NO_REORDER and static
33 ; CHECK-BE32: .mips_hack_elf_flags 0x50001005
33 ; CHECK-BE32: .abicalls
34 ; CHECK-BE32: .option pic0
35 ; CHECK-BE32: .set noreorder
3436 ;
3537 ; 32(R1) bit with NO_REORDER and PIC
36 ; CHECK-BE32_PIC: .mips_hack_elf_flags 0x50001007
38 ; CHECK-BE32_PIC: .abicalls
39 ; CHECK-BE32_PIC: .set noreorder
3740 ;
3841 ; 32R2 bit with NO_REORDER and static
39 ; CHECK-BE32R2: .mips_hack_elf_flags 0x70001005
42 ; CHECK-BE32R2: .abicalls
43 ; CHECK-BE32R2: .option pic0
44 ; CHECK-BE32R2: .set noreorder
4045 ;
4146 ; 32R2 bit with NO_REORDER and PIC
42 ; CHECK-BE32R2_PIC: .mips_hack_elf_flags 0x70001007
47 ; CHECK-BE32R2_PIC: .abicalls
48 ; CHECK-BE32R2_PIC: .set noreorder
4349 ;
4450 ; 32R2 bit MICROMIPS with NO_REORDER and static
45 ; CHECK-BE32R2-MICROMIPS: .mips_hack_elf_flags 0x72001005
51 ; CHECK-BE32R2-MICROMIPS: .abicalls
52 ; CHECK-BE32R2-MICROMIPS: .option pic0
53 ; CHECK-BE32R2-MICROMIPS: .set micromips
4654 ;
4755 ; 32R2 bit MICROMIPS with NO_REORDER and PIC
48 ; CHECK-BE32R2-MICROMIPS_PIC: .mips_hack_elf_flags 0x72001007
56 ; CHECK-BE32R2-MICROMIPS_PIC: .abicalls
57 ; CHECK-BE32R2-MICROMIPS_PIC: .set micromips
4958 ;
5059 ; 64(R1) bit with NO_REORDER and static
51 ; CHECK-BE64: .mips_hack_elf_flags 0x60000005
60 ; CHECK-BE64: .abicalls
61 ; CHECK-BE64: .set noreorder
5262 ;
5363 ; 64(R1) bit with NO_REORDER and PIC
54 ; CHECK-BE64_PIC: .mips_hack_elf_flags 0x60000007
64 ; CHECK-BE64_PIC: .abicalls
65 ; CHECK-BE64_PIC: .set noreorder
5566 ;
5667 ; 64R2 bit with NO_REORDER and static
57 ; CHECK-BE64R2: .mips_hack_elf_flags 0x80000005
68 ; CHECK-BE64R2: .abicalls
69 ; CHECK-BE64R2: .set noreorder
5870 ;
5971 ; 64R2 bit with NO_REORDER and PIC
60 ; CHECK-BE64R2_PIC: .mips_hack_elf_flags 0x80000007
72 ; CHECK-BE64R2_PIC: .abicalls
73 ; CHECK-BE64R2_PIC: .set noreorder
6174 ;
6275 ; 32R2 bit MIPS16 with PIC
63 ; CHECK-LE32R2-MIPS16: .mips_hack_elf_flags 0x74001006
76 ; CHECK-LE32R2-MIPS16: .abicalls
77 ; CHECK-LE32R2-MIPS16: .set mips16
6478
6579 define i32 @main() nounwind {
6680 entry:
None // RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux %s -o -| llvm-readobj -h | FileCheck %s
1 // The initial value will be set at 0x50001003 and
2 // we will override that with the negation of 0x2 (option pic0
3 // the addition of 0x4 (.abicalls)
0 # These *MUST* match the output of gas compiled with the same triple and
1 # corresponding options (-mcpu=mips32 -> -mips32 for example).
42
5 .mips_hack_elf_flags 0x50001003
3 # RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux -mcpu=mips64r2 %s -o -| llvm-readobj -h | FileCheck --check-prefix=MIPSEL-MIPS64R2 %s
4 # MIPSEL-MIPS64R2: Flags [ (0x80001100)
65
7 // CHECK: Flags [ (0x54001005)
6 # RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux -mcpu=mips64 %s -o -| llvm-readobj -h | FileCheck --check-prefix=MIPSEL-MIPS64 %s
7 # MIPSEL-MIPS64: Flags [ (0x60001100)
88
9 .abicalls
9 # RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux -mcpu=mips32r2 %s -o -| llvm-readobj -h | FileCheck --check-prefix=MIPSEL-MIPS32R2 %s
10 # MIPSEL-MIPS32R2: Flags [ (0x70001000)
1011
11 .option pic0
12
13 // Set EF_MIPS_ARCH_ASE_M16 (0x04000000)
14 .set mips16
12 # RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux -mcpu=mips32 %s -o -| llvm-readobj -h | FileCheck --check-prefix=MIPSEL-MIPS32 %s
13 # MIPSEL-MIPS32: Flags [ (0x50001000)
14
15 # RUN: llvm-mc -filetype=obj -triple mips64el-unknown-linux -mcpu=mips64r2 %s -o -| llvm-readobj -h | FileCheck --check-prefix=MIPS64EL-MIPS64R2 %s
16 # MIPS64EL-MIPS64R2: Flags [ (0x80000020)
17
18 # RUN: llvm-mc -filetype=obj -triple mips64el-unknown-linux -mcpu=mips64 %s -o -| llvm-readobj -h | FileCheck --check-prefix=MIPS64EL-MIPS64 %s
19 # MIPS64EL-MIPS64: Flags [ (0x60000020)
0 # RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux -mcpu=mips32 %s -o -| llvm-readobj -h | FileCheck %s
1
2 # This *MUST* match the output of gas compiled with the same triple.
3 # CHECK: Flags [ (0x50001006)
4
5 .abicalls
0 # RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux -mcpu=mips32 %s -o -| llvm-readobj -h | FileCheck %s
1
2 # This *MUST* match the output of gas compiled with the same triple.
3 # CHECK: Flags [ (0x52001000)
4
5 .set micromips
6 f:
7 nop
0 # RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux -mcpu=mips32 %s -o -| llvm-readobj -h | FileCheck %s
1
2 # This *MUST* match the output of gas compiled with the same triple.
3 # CHECK: Flags [ (0x54001000)
4
5 .set mips16
6 f:
7 nop
0 # RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux -mcpu=mips32 %s -o -| llvm-readobj -h | FileCheck %s
1
2 # This *MUST* match the output of gas compiled with the same triple.
3 # CHECK: Flags [ (0x50001001)
4
5 .set noreorder
0 # RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux -mcpu=mips32 %s -o -| llvm-readobj -h | FileCheck %s
1
2 # This *MUST* match the output of gas compiled with the same triple.
3 # CHECK: Flags [ (0x50001004)
4
5 .abicalls
6 .option pic0