Beispiel #1
0
  // For llc. Set a group of ELF header flags
  void
  MipsELFStreamer::emitELFHeaderFlagsCG(const MipsSubtarget &Subtarget) {

    if (hasRawTextSupport())
      return;

    // Update e_header flags
    MCAssembler& MCA = getAssembler();
    unsigned EFlags = MCA.getELFHeaderEFlags();

    // TODO: Need to add -mabicalls and -mno-abicalls flags.
    // Currently we assume that -mabicalls is the default.
    EFlags |= ELF::EF_MIPS_CPIC;

    if (Subtarget.inMips16Mode())
      EFlags |= ELF::EF_MIPS_ARCH_ASE_M16;
    else
      EFlags |= ELF::EF_MIPS_NOREORDER;

    // Architecture
    if (Subtarget.hasMips64r2())
      EFlags |= ELF::EF_MIPS_ARCH_64R2;
    else if (Subtarget.hasMips64())
      EFlags |= ELF::EF_MIPS_ARCH_64;
    else if (Subtarget.hasMips32r2())
      EFlags |= ELF::EF_MIPS_ARCH_32R2;
    else
      EFlags |= ELF::EF_MIPS_ARCH_32;

    if (Subtarget.inMicroMipsMode())
      EFlags |= ELF::EF_MIPS_MICROMIPS;

    // ABI
    if (Subtarget.isABI_O32())
      EFlags |= ELF::EF_MIPS_ABI_O32;

    // Relocation Model
    Reloc::Model RM = Subtarget.getRelocationModel();
    if (RM == Reloc::PIC_ || RM == Reloc::Default)
      EFlags |= ELF::EF_MIPS_PIC;
    else if (RM == Reloc::Static)
      ; // Do nothing for Reloc::Static
    else
      llvm_unreachable("Unsupported relocation model for e_flags");

    MCA.setELFHeaderEFlags(EFlags);
  }
void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) {

  // Compute MIPS architecture attributes based on the default subtarget
  // that we'd have constructed. Module level directives aren't LTO
  // clean anyhow.
  // FIXME: For ifunc related functions we could iterate over and look
  // for a feature string that doesn't match the default one.
  const Triple &TT = TM.getTargetTriple();
  StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
  StringRef FS = TM.getTargetFeatureString();
  const MipsTargetMachine &MTM = static_cast<const MipsTargetMachine &>(TM);
  const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM);

  bool IsABICalls = STI.isABICalls();
  const MipsABIInfo &ABI = MTM.getABI();
  if (IsABICalls) {
    getTargetStreamer().emitDirectiveAbiCalls();
    Reloc::Model RM = TM.getRelocationModel();
    // FIXME: This condition should be a lot more complicated that it is here.
    //        Ideally it should test for properties of the ABI and not the ABI
    //        itself.
    //        For the moment, I'm only correcting enough to make MIPS-IV work.
    if (RM == Reloc::Static && !ABI.IsN64())
      getTargetStreamer().emitDirectiveOptionPic0();
  }

  // Tell the assembler which ABI we are using
  std::string SectionName = std::string(".mdebug.") + getCurrentABIString();
  OutStreamer->SwitchSection(
      OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, 0));

  // NaN: At the moment we only support:
  // 1. .nan legacy (default)
  // 2. .nan 2008
  STI.isNaN2008() ? getTargetStreamer().emitDirectiveNaN2008()
                  : getTargetStreamer().emitDirectiveNaNLegacy();

  // TODO: handle O64 ABI

  if (ABI.IsEABI()) {
    if (STI.isGP32bit())
      OutStreamer->SwitchSection(OutContext.getELFSection(".gcc_compiled_long32",
                                                          ELF::SHT_PROGBITS, 0));
    else
      OutStreamer->SwitchSection(OutContext.getELFSection(".gcc_compiled_long64",
                                                          ELF::SHT_PROGBITS, 0));
  }

  // RICH: Need to tell the assembler which processor we're using.
  MipsTargetStreamer &TS = getTargetStreamer();
  if (STI.hasMips64r2()) {
    TS.emitDirectiveSetMips64R2();
  } else if (STI.hasMips64()) {
    TS.emitDirectiveSetMips64();
  } else if (STI.hasMips32r2()) {
    TS.emitDirectiveSetMips32R2();
  }

  getTargetStreamer().updateABIInfo(STI);

  // We should always emit a '.module fp=...' but binutils 2.24 does not accept
  // it. We therefore emit it when it contradicts the ABI defaults (-mfpxx or
  // -mfp64) and omit it otherwise.
  if (ABI.IsO32() && (STI.isABI_FPXX() || STI.isFP64bit()))
    getTargetStreamer().emitDirectiveModuleFP();

  // We should always emit a '.module [no]oddspreg' but binutils 2.24 does not
  // accept it. We therefore emit it when it contradicts the default or an
  // option has changed the default (i.e. FPXX) and omit it otherwise.
  if (ABI.IsO32() && (!STI.useOddSPReg() || STI.isABI_FPXX()))
    getTargetStreamer().emitDirectiveModuleOddSPReg();
}