MipsELFStreamer.cpp revision 6d389f5ebae9aa08309c5795234cf155054b6b39
1//===-- MipsELFStreamer.cpp - MipsELFStreamer ---------------------------===//
2//
3//                       The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
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"
17
18namespace llvm {
19
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);
25    return S;
26  }
27
28  // For llc. Set a group of ELF header flags
29  void
30  MipsELFStreamer::emitELFHeaderFlagsCG(const MipsSubtarget &Subtarget) {
31
32    if (hasRawTextSupport())
33      return;
34
35    // Update e_header flags
36    MCAssembler& MCA = getAssembler();
37    unsigned EFlags = MCA.getELFHeaderEFlags();
38
39    // TODO: Need to add -mabicalls and -mno-abicalls flags.
40    // Currently we assume that -mabicalls is the default.
41    EFlags |= ELF::EF_MIPS_CPIC;
42
43    if (Subtarget.inMips16Mode())
44      EFlags |= ELF::EF_MIPS_ARCH_ASE_M16;
45    else
46      EFlags |= ELF::EF_MIPS_NOREORDER;
47
48    // Architecture
49    if (Subtarget.hasMips64r2())
50      EFlags |= ELF::EF_MIPS_ARCH_64R2;
51    else if (Subtarget.hasMips64())
52      EFlags |= ELF::EF_MIPS_ARCH_64;
53    else if (Subtarget.hasMips32r2())
54      EFlags |= ELF::EF_MIPS_ARCH_32R2;
55    else
56      EFlags |= ELF::EF_MIPS_ARCH_32;
57
58    if (Subtarget.inMicroMipsMode())
59      EFlags |= ELF::EF_MIPS_MICROMIPS;
60
61    // ABI
62    if (Subtarget.isABI_O32())
63      EFlags |= ELF::EF_MIPS_ABI_O32;
64
65    // Relocation Model
66    Reloc::Model RM = Subtarget.getRelocationModel();
67    if (RM == Reloc::PIC_ || RM == Reloc::Default)
68      EFlags |= ELF::EF_MIPS_PIC;
69    else if (RM == Reloc::Static)
70      ; // Do nothing for Reloc::Static
71    else
72      llvm_unreachable("Unsupported relocation model for e_flags");
73
74    MCA.setELFHeaderEFlags(EFlags);
75  }
76
77  // For llc. Set a symbol's STO flags
78  void
79  MipsELFStreamer::emitMipsSTOCG(const MipsSubtarget &Subtarget,
80                                 MCSymbol *Sym,
81                                 unsigned Val) {
82
83    if (hasRawTextSupport())
84      return;
85
86    MCSymbolData &Data = getOrCreateSymbolData(Sym);
87    // The "other" values are stored in the last 6 bits of the second byte
88    // The traditional defines for STO values assume the full byte and thus
89    // the shift to pack it.
90    MCELF::setOther(Data, Val >> 2);
91  }
92
93} // namespace llvm
94