MCSectionCOFF.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //===- lib/MC/MCSectionCOFF.cpp - COFF Code Section Representation --------===//
  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 "llvm/MC/MCSectionCOFF.h"
  10. #include "llvm/MC/MCAsmInfo.h"
  11. #include "llvm/MC/MCContext.h"
  12. #include "llvm/MC/MCSymbol.h"
  13. #include "llvm/Support/raw_ostream.h"
  14. using namespace llvm;
  15. MCSectionCOFF::~MCSectionCOFF() {} // anchor.
  16. // ShouldOmitSectionDirective - Decides whether a '.section' directive
  17. // should be printed before the section name
  18. bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name,
  19. const MCAsmInfo &MAI) const {
  20. if (COMDATSymbol)
  21. return false;
  22. // FIXME: Does .section .bss/.data/.text work everywhere??
  23. if (Name == ".text" || Name == ".data" || Name == ".bss")
  24. return true;
  25. return false;
  26. }
  27. void MCSectionCOFF::setSelection(int Selection) const {
  28. assert(Selection != 0 && "invalid COMDAT selection type");
  29. this->Selection = Selection;
  30. Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
  31. }
  32. void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI,
  33. raw_ostream &OS,
  34. const MCExpr *Subsection) const {
  35. // standard sections don't require the '.section'
  36. if (ShouldOmitSectionDirective(SectionName, MAI)) {
  37. OS << '\t' << getSectionName() << '\n';
  38. return;
  39. }
  40. OS << "\t.section\t" << getSectionName() << ",\"";
  41. if (getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
  42. OS << 'd';
  43. if (getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
  44. OS << 'b';
  45. if (getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE)
  46. OS << 'x';
  47. if (getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE)
  48. OS << 'w';
  49. else if (getCharacteristics() & COFF::IMAGE_SCN_MEM_READ)
  50. OS << 'r';
  51. else
  52. OS << 'y';
  53. if (getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE)
  54. OS << 'n';
  55. if (getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED)
  56. OS << 's';
  57. OS << '"';
  58. if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
  59. OS << ",";
  60. switch (Selection) {
  61. case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES:
  62. OS << "one_only,";
  63. break;
  64. case COFF::IMAGE_COMDAT_SELECT_ANY:
  65. OS << "discard,";
  66. break;
  67. case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE:
  68. OS << "same_size,";
  69. break;
  70. case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH:
  71. OS << "same_contents,";
  72. break;
  73. case COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE:
  74. OS << "associative,";
  75. break;
  76. case COFF::IMAGE_COMDAT_SELECT_LARGEST:
  77. OS << "largest,";
  78. break;
  79. case COFF::IMAGE_COMDAT_SELECT_NEWEST:
  80. OS << "newest,";
  81. break;
  82. default:
  83. assert (0 && "unsupported COFF selection type");
  84. break;
  85. }
  86. assert(COMDATSymbol);
  87. COMDATSymbol->print(OS, &MAI);
  88. }
  89. OS << '\n';
  90. }
  91. bool MCSectionCOFF::UseCodeAlign() const {
  92. return getKind().isText();
  93. }
  94. bool MCSectionCOFF::isVirtualSection() const {
  95. return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
  96. }