1 //===-- MipsELFStreamer.cpp - MipsELFStreamer ---------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===-------------------------------------------------------------------===//
9 #include "MCTargetDesc/MipsELFStreamer.h"
10 #include "MipsSubtarget.h"
11 #include "llvm/MC/MCAssembler.h"
12 #include "llvm/MC/MCELF.h"
13 #include "llvm/MC/MCELFSymbolFlags.h"
14 #include "llvm/MC/MCSymbol.h"
15 #include "llvm/Support/ELF.h"
16 #include "llvm/Support/ErrorHandling.h"
20 MCELFStreamer* createMipsELFStreamer(MCContext &Context, MCAsmBackend &TAB,
21 raw_ostream &OS, MCCodeEmitter *Emitter,
22 bool RelaxAll, bool NoExecStack) {
23 MipsELFStreamer *S = new MipsELFStreamer(Context, TAB, OS, Emitter,
24 RelaxAll, NoExecStack);
28 // For llc. Set a group of ELF header flags
30 MipsELFStreamer::emitELFHeaderFlagsCG(const MipsSubtarget &Subtarget) {
32 if (hasRawTextSupport())
35 // Update e_header flags
36 MCAssembler& MCA = getAssembler();
37 unsigned EFlags = MCA.getELFHeaderEFlags();
39 if (Subtarget.inMips16Mode())
40 EFlags |= ELF::EF_MIPS_ARCH_ASE_M16;
42 EFlags |= ELF::EF_MIPS_NOREORDER;
45 if (Subtarget.hasMips64r2())
46 EFlags |= ELF::EF_MIPS_ARCH_64R2;
47 else if (Subtarget.hasMips64())
48 EFlags |= ELF::EF_MIPS_ARCH_64;
49 else if (Subtarget.hasMips32r2())
50 EFlags |= ELF::EF_MIPS_ARCH_32R2;
52 EFlags |= ELF::EF_MIPS_ARCH_32;
54 if (Subtarget.inMicroMipsMode())
55 EFlags |= ELF::EF_MIPS_MICROMIPS;
58 if (Subtarget.isABI_O32())
59 EFlags |= ELF::EF_MIPS_ABI_O32;
62 Reloc::Model RM = Subtarget.getRelocationModel();
63 if (RM == Reloc::PIC_ || RM == Reloc::Default)
64 EFlags |= ELF::EF_MIPS_PIC;
65 else if (RM == Reloc::Static)
66 ; // Do nothing for Reloc::Static
68 llvm_unreachable("Unsupported relocation model for e_flags");
70 MCA.setELFHeaderEFlags(EFlags);
73 // For llc. Set a symbol's STO flags
75 MipsELFStreamer::emitMipsSTOCG(const MipsSubtarget &Subtarget,
79 if (hasRawTextSupport())
82 MCSymbolData &Data = getOrCreateSymbolData(Sym);
83 // The "other" values are stored in the last 6 bits of the second byte
84 // The traditional defines for STO values assume the full byte and thus
85 // the shift to pack it.
86 MCELF::setOther(Data, Val >> 2);