Example #1
0
void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI,
                                        raw_ostream &OS,
                                        const MCExpr *Subsection) const {

  if (ShouldOmitSectionDirective(SectionName, MAI)) {
    OS << '\t' << getSectionName();
    if (Subsection) {
      OS << '\t';
      Subsection->print(OS, &MAI);
    }
    OS << '\n';
    return;
  }

  OS << "\t.section\t";
  printName(OS, getSectionName());

  // Handle the weird solaris syntax if desired.
  if (MAI.usesSunStyleELFSectionSwitchSyntax() &&
      !(Flags & ELF::SHF_MERGE)) {
    if (Flags & ELF::SHF_ALLOC)
      OS << ",#alloc";
    if (Flags & ELF::SHF_EXECINSTR)
      OS << ",#execinstr";
    if (Flags & ELF::SHF_WRITE)
      OS << ",#write";
    if (Flags & ELF::SHF_EXCLUDE)
      OS << ",#exclude";
    if (Flags & ELF::SHF_TLS)
      OS << ",#tls";
    OS << '\n';
    return;
  }

  OS << ",\"";
  if (Flags & ELF::SHF_ALLOC)
    OS << 'a';
  if (Flags & ELF::SHF_EXCLUDE)
    OS << 'e';
  if (Flags & ELF::SHF_EXECINSTR)
    OS << 'x';
  if (Flags & ELF::SHF_GROUP)
    OS << 'G';
  if (Flags & ELF::SHF_WRITE)
    OS << 'w';
  if (Flags & ELF::SHF_MERGE)
    OS << 'M';
  if (Flags & ELF::SHF_STRINGS)
    OS << 'S';
  if (Flags & ELF::SHF_TLS)
    OS << 'T';

  // If there are target-specific flags, print them.
  if (Flags & ELF::XCORE_SHF_CP_SECTION)
    OS << 'c';
  if (Flags & ELF::XCORE_SHF_DP_SECTION)
    OS << 'd';

  OS << '"';

  OS << ',';

  // If comment string is '@', e.g. as on ARM - use '%' instead
  if (MAI.getCommentString()[0] == '@')
    OS << '%';
  else
    OS << '@';

  if (Type == ELF::SHT_INIT_ARRAY)
    OS << "init_array";
  else if (Type == ELF::SHT_FINI_ARRAY)
    OS << "fini_array";
  else if (Type == ELF::SHT_PREINIT_ARRAY)
    OS << "preinit_array";
  else if (Type == ELF::SHT_NOBITS)
    OS << "nobits";
  else if (Type == ELF::SHT_NOTE)
    OS << "note";
  else if (Type == ELF::SHT_PROGBITS)
    OS << "progbits";

  if (EntrySize) {
    assert(Flags & ELF::SHF_MERGE);
    OS << "," << EntrySize;
  }

  if (Flags & ELF::SHF_GROUP) {
    OS << ",";
    printName(OS, Group->getName());
    OS << ",comdat";
  }

  if (isUnique())
    OS << ",unique," << UniqueID;

  OS << '\n';

  if (Subsection) {
    OS << "\t.subsection\t";
    Subsection->print(OS, &MAI);
    OS << '\n';
  }
}
Example #2
0
void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
                                        raw_ostream &OS,
                                        const MCExpr *Subsection) const {
  if (ShouldOmitSectionDirective(SectionName, MAI)) {
    OS << '\t' << getSectionName();
    if (Subsection) {
      OS << '\t';
      Subsection->print(OS, &MAI);
    }
    OS << '\n';
    return;
  }

  OS << "\t.section\t";
  printName(OS, getSectionName());

  // Handle the weird solaris syntax if desired.
  if (MAI.usesSunStyleELFSectionSwitchSyntax() &&
      !(Flags & ELF::SHF_MERGE)) {
    if (Flags & ELF::SHF_ALLOC)
      OS << ",#alloc";
    if (Flags & ELF::SHF_EXECINSTR)
      OS << ",#execinstr";
    if (Flags & ELF::SHF_WRITE)
      OS << ",#write";
    if (Flags & ELF::SHF_EXCLUDE)
      OS << ",#exclude";
    if (Flags & ELF::SHF_TLS)
      OS << ",#tls";
    OS << '\n';
    return;
  }

  OS << ",\"";
  if (Flags & ELF::SHF_ALLOC)
    OS << 'a';
  if (Flags & ELF::SHF_EXCLUDE)
    OS << 'e';
  if (Flags & ELF::SHF_EXECINSTR)
    OS << 'x';
  if (Flags & ELF::SHF_GROUP)
    OS << 'G';
  if (Flags & ELF::SHF_WRITE)
    OS << 'w';
  if (Flags & ELF::SHF_MERGE)
    OS << 'M';
  if (Flags & ELF::SHF_STRINGS)
    OS << 'S';
  if (Flags & ELF::SHF_TLS)
    OS << 'T';
  if (Flags & ELF::SHF_LINK_ORDER)
    OS << 'o';

  // If there are target-specific flags, print them.
  Triple::ArchType Arch = T.getArch();
  if (Arch == Triple::xcore) {
    if (Flags & ELF::XCORE_SHF_CP_SECTION)
      OS << 'c';
    if (Flags & ELF::XCORE_SHF_DP_SECTION)
      OS << 'd';
  } else if (T.isARM() || T.isThumb()) {
    if (Flags & ELF::SHF_ARM_PURECODE)
      OS << 'y';
  }

  OS << '"';

  OS << ',';

  // If comment string is '@', e.g. as on ARM - use '%' instead
  if (MAI.getCommentString()[0] == '@')
    OS << '%';
  else
    OS << '@';

  if (Type == ELF::SHT_INIT_ARRAY)
    OS << "init_array";
  else if (Type == ELF::SHT_FINI_ARRAY)
    OS << "fini_array";
  else if (Type == ELF::SHT_PREINIT_ARRAY)
    OS << "preinit_array";
  else if (Type == ELF::SHT_NOBITS)
    OS << "nobits";
  else if (Type == ELF::SHT_NOTE)
    OS << "note";
  else if (Type == ELF::SHT_PROGBITS)
    OS << "progbits";
  else if (Type == ELF::SHT_X86_64_UNWIND)
    OS << "unwind";
  else if (Type == ELF::SHT_MIPS_DWARF)
    // Print hex value of the flag while we do not have
    // any standard symbolic representation of the flag.
    OS << "0x7000001e";
  else if (Type == ELF::SHT_LLVM_ODRTAB)
    OS << "llvm_odrtab";
  else if (Type == ELF::SHT_LLVM_LINKER_OPTIONS)
    OS << "llvm_linker_options";
  else if (Type == ELF::SHT_LLVM_CALL_GRAPH_PROFILE)
    OS << "llvm_call_graph_profile";
  else
    report_fatal_error("unsupported type 0x" + Twine::utohexstr(Type) +
                       " for section " + getSectionName());

  if (EntrySize) {
    assert(Flags & ELF::SHF_MERGE);
    OS << "," << EntrySize;
  }

  if (Flags & ELF::SHF_GROUP) {
    OS << ",";
    printName(OS, Group->getName());
    OS << ",comdat";
  }

  if (Flags & ELF::SHF_LINK_ORDER) {
    assert(AssociatedSymbol);
    OS << ",";
    printName(OS, AssociatedSymbol->getName());
  }

  if (isUnique())
    OS << ",unique," << UniqueID;

  OS << '\n';

  if (Subsection) {
    OS << "\t.subsection\t";
    Subsection->print(OS, &MAI);
    OS << '\n';
  }
}
Example #3
0
void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI,
                                        raw_ostream &OS) const {
   
  if (ShouldOmitSectionDirective(SectionName, MAI)) {
    OS << '\t' << getSectionName() << '\n';
    return;
  }

  StringRef name = getSectionName();
  OS << "\t.section\t\"";
  for (const char *b = name.begin(), *e = name.end(); b < e; ++b) {
    if (*b == '"') // Unquoted "
      OS << "\\\"";
    else if (*b != '\\') // Neither " or backslash
      OS << *b;
    else if (b + 1 == e) // Trailing backslash
      OS << "\\\\";
    else {
      OS << b[0] << b[1]; // Quoted character
      ++b;
    }
  }
  OS << '"';

  // Handle the weird solaris syntax if desired.
  if (MAI.usesSunStyleELFSectionSwitchSyntax() && 
      !(Flags & ELF::SHF_MERGE)) {
    if (Flags & ELF::SHF_ALLOC)
      OS << ",#alloc";
    if (Flags & ELF::SHF_EXECINSTR)
      OS << ",#execinstr";
    if (Flags & ELF::SHF_WRITE)
      OS << ",#write";
    if (Flags & ELF::SHF_TLS)
      OS << ",#tls";
    OS << '\n';
    return;
  }
  
  OS << ",\"";
  if (Flags & ELF::SHF_ALLOC)
    OS << 'a';
  if (Flags & ELF::SHF_EXECINSTR)
    OS << 'x';
  if (Flags & ELF::SHF_GROUP)
    OS << 'G';
  if (Flags & ELF::SHF_WRITE)
    OS << 'w';
  if (Flags & ELF::SHF_MERGE)
    OS << 'M';
  if (Flags & ELF::SHF_STRINGS)
    OS << 'S';
  if (Flags & ELF::SHF_TLS)
    OS << 'T';
  
  // If there are target-specific flags, print them.
  if (Flags & ELF::XCORE_SHF_CP_SECTION)
    OS << 'c';
  if (Flags & ELF::XCORE_SHF_DP_SECTION)
    OS << 'd';
  
  OS << '"';

  OS << ',';

  // If comment string is '@', e.g. as on ARM - use '%' instead
  if (MAI.getCommentString()[0] == '@')
    OS << '%';
  else
    OS << '@';

  if (Type == ELF::SHT_INIT_ARRAY)
    OS << "init_array";
  else if (Type == ELF::SHT_FINI_ARRAY)
    OS << "fini_array";
  else if (Type == ELF::SHT_PREINIT_ARRAY)
    OS << "preinit_array";
  else if (Type == ELF::SHT_NOBITS)
    OS << "nobits";
  else if (Type == ELF::SHT_NOTE)
    OS << "note";
  else if (Type == ELF::SHT_PROGBITS)
    OS << "progbits";

  if (EntrySize) {
    assert(Flags & ELF::SHF_MERGE);
    OS << "," << EntrySize;
  }

  if (Flags & ELF::SHF_GROUP)
    OS << "," << Group->getName() << ",comdat";
  OS << '\n';
}
Example #4
0
void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI,
                                        raw_ostream &OS) const {
   
  if (ShouldOmitSectionDirective(SectionName.c_str(), MAI)) {
    OS << '\t' << getSectionName() << '\n';
    return;
  }

  OS << "\t.section\t" << getSectionName();
  
  // Handle the weird solaris syntax if desired.
  if (MAI.usesSunStyleELFSectionSwitchSyntax() && 
      !(Flags & MCSectionELF::SHF_MERGE)) {
    if (Flags & MCSectionELF::SHF_ALLOC)
      OS << ",#alloc";
    if (Flags & MCSectionELF::SHF_EXECINSTR)
      OS << ",#execinstr";
    if (Flags & MCSectionELF::SHF_WRITE)
      OS << ",#write";
    if (Flags & MCSectionELF::SHF_TLS)
      OS << ",#tls";
  } else {
    OS << ",\"";
    if (Flags & MCSectionELF::SHF_ALLOC)
      OS << 'a';
    if (Flags & MCSectionELF::SHF_EXECINSTR)
      OS << 'x';
    if (Flags & MCSectionELF::SHF_WRITE)
      OS << 'w';
    if (Flags & MCSectionELF::SHF_MERGE)
      OS << 'M';
    if (Flags & MCSectionELF::SHF_STRINGS)
      OS << 'S';
    if (Flags & MCSectionELF::SHF_TLS)
      OS << 'T';
    
    // If there are target-specific flags, print them.
    if (Flags & ~MCSectionELF::TARGET_INDEP_SHF)
      PrintTargetSpecificSectionFlags(MAI, OS);
    
    OS << '"';

    if (ShouldPrintSectionType(Type)) {
      OS << ',';
   
      // If comment string is '@', e.g. as on ARM - use '%' instead
      if (MAI.getCommentString()[0] == '@')
        OS << '%';
      else
        OS << '@';
    
      if (Type == MCSectionELF::SHT_INIT_ARRAY)
        OS << "init_array";
      else if (Type == MCSectionELF::SHT_FINI_ARRAY)
        OS << "fini_array";
      else if (Type == MCSectionELF::SHT_PREINIT_ARRAY)
        OS << "preinit_array";
      else if (Type == MCSectionELF::SHT_NOBITS)
        OS << "nobits";
      else if (Type == MCSectionELF::SHT_PROGBITS)
        OS << "progbits";
    
      if (getKind().isMergeable1ByteCString()) {
        OS << ",1";
      } else if (getKind().isMergeable2ByteCString()) {
        OS << ",2";
      } else if (getKind().isMergeable4ByteCString() || 
                 getKind().isMergeableConst4()) {
        OS << ",4";
      } else if (getKind().isMergeableConst8()) {
        OS << ",8";
      } else if (getKind().isMergeableConst16()) {
        OS << ",16";
      }
    }
  }
  
  OS << '\n';
}