Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 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 | |
| 10 | #include "llvm/MC/MCSectionCOFF.h" |
| 11 | #include "llvm/MC/MCAsmInfo.h" |
| 12 | #include "llvm/MC/MCContext.h" |
| 13 | #include "llvm/MC/MCSymbol.h" |
| 14 | #include "llvm/Support/raw_ostream.h" |
| 15 | using namespace llvm; |
| 16 | |
| 17 | MCSectionCOFF::~MCSectionCOFF() {} // anchor. |
| 18 | |
| 19 | // ShouldOmitSectionDirective - Decides whether a '.section' directive |
| 20 | // should be printed before the section name |
| 21 | bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name, |
| 22 | const MCAsmInfo &MAI) const { |
| 23 | |
| 24 | // FIXME: Does .section .bss/.data/.text work everywhere?? |
| 25 | if (Name == ".text" || Name == ".data" || Name == ".bss") |
| 26 | return true; |
| 27 | |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, |
| 32 | raw_ostream &OS) const { |
| 33 | |
Nathan Jeffords | 72e57f9 | 2010-05-09 05:49:00 +0000 | [diff] [blame] | 34 | // standard sections don't require the '.section' |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 35 | if (ShouldOmitSectionDirective(SectionName, MAI)) { |
| 36 | OS << '\t' << getSectionName() << '\n'; |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | OS << "\t.section\t" << getSectionName() << ",\""; |
| 41 | if (getKind().isText()) |
| 42 | OS << 'x'; |
| 43 | if (getKind().isWriteable()) |
| 44 | OS << 'w'; |
| 45 | else |
| 46 | OS << 'r'; |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 47 | if (getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 48 | OS << 'n'; |
| 49 | OS << "\"\n"; |
Nathan Jeffords | 871bb94 | 2010-05-12 04:26:09 +0000 | [diff] [blame] | 50 | |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 51 | if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) { |
Nathan Jeffords | 871bb94 | 2010-05-12 04:26:09 +0000 | [diff] [blame] | 52 | switch (Selection) { |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 53 | case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES: |
Nathan Jeffords | 871bb94 | 2010-05-12 04:26:09 +0000 | [diff] [blame] | 54 | OS << "\t.linkonce one_only\n"; |
| 55 | break; |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 56 | case COFF::IMAGE_COMDAT_SELECT_ANY: |
Nathan Jeffords | 871bb94 | 2010-05-12 04:26:09 +0000 | [diff] [blame] | 57 | OS << "\t.linkonce discard\n"; |
| 58 | break; |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 59 | case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE: |
Nathan Jeffords | 871bb94 | 2010-05-12 04:26:09 +0000 | [diff] [blame] | 60 | OS << "\t.linkonce same_size\n"; |
| 61 | break; |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 62 | case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH: |
Nathan Jeffords | 871bb94 | 2010-05-12 04:26:09 +0000 | [diff] [blame] | 63 | OS << "\t.linkonce same_contents\n"; |
| 64 | break; |
Nathan Jeffords | 62d50e8 | 2010-05-12 07:36:03 +0000 | [diff] [blame] | 65 | //NOTE: as of binutils 2.20, there is no way to specifiy select largest |
| 66 | // with the .linkonce directive. For now, we treat it as an invalid |
| 67 | // comdat selection value. |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 68 | case COFF::IMAGE_COMDAT_SELECT_LARGEST: |
Nathan Jeffords | 871bb94 | 2010-05-12 04:26:09 +0000 | [diff] [blame] | 69 | // OS << "\t.linkonce largest\n"; |
| 70 | // break; |
Nathan Jeffords | 62d50e8 | 2010-05-12 07:36:03 +0000 | [diff] [blame] | 71 | default: |
| 72 | assert (0 && "unsupported COFF selection type"); |
| 73 | break; |
Nathan Jeffords | 871bb94 | 2010-05-12 04:26:09 +0000 | [diff] [blame] | 74 | } |
| 75 | } |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 76 | } |