LLVM API Documentation
00001 //===- lib/MC/MCSectionCOFF.cpp - COFF Code Section Representation --------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #include "llvm/MC/MCSectionCOFF.h" 00011 #include "llvm/MC/MCAsmInfo.h" 00012 #include "llvm/MC/MCContext.h" 00013 #include "llvm/MC/MCSymbol.h" 00014 #include "llvm/Support/raw_ostream.h" 00015 using namespace llvm; 00016 00017 MCSectionCOFF::~MCSectionCOFF() {} // anchor. 00018 00019 // ShouldOmitSectionDirective - Decides whether a '.section' directive 00020 // should be printed before the section name 00021 bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name, 00022 const MCAsmInfo &MAI) const { 00023 00024 // FIXME: Does .section .bss/.data/.text work everywhere?? 00025 if (Name == ".text" || Name == ".data" || Name == ".bss") 00026 return true; 00027 00028 return false; 00029 } 00030 00031 void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, 00032 raw_ostream &OS, 00033 const MCExpr *Subsection) const { 00034 00035 // standard sections don't require the '.section' 00036 if (ShouldOmitSectionDirective(SectionName, MAI)) { 00037 OS << '\t' << getSectionName() << '\n'; 00038 return; 00039 } 00040 00041 OS << "\t.section\t" << getSectionName() << ",\""; 00042 if (getKind().isText()) 00043 OS << 'x'; 00044 if (getKind().isWriteable()) 00045 OS << 'w'; 00046 else 00047 OS << 'r'; 00048 if (getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) 00049 OS << 'n'; 00050 OS << "\"\n"; 00051 00052 if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) { 00053 switch (Selection) { 00054 case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES: 00055 OS << "\t.linkonce one_only\n"; 00056 break; 00057 case COFF::IMAGE_COMDAT_SELECT_ANY: 00058 OS << "\t.linkonce discard\n"; 00059 break; 00060 case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE: 00061 OS << "\t.linkonce same_size\n"; 00062 break; 00063 case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH: 00064 OS << "\t.linkonce same_contents\n"; 00065 break; 00066 //NOTE: as of binutils 2.20, there is no way to specifiy select largest 00067 // with the .linkonce directive. For now, we treat it as an invalid 00068 // comdat selection value. 00069 case COFF::IMAGE_COMDAT_SELECT_LARGEST: 00070 // OS << "\t.linkonce largest\n"; 00071 // break; 00072 default: 00073 assert (0 && "unsupported COFF selection type"); 00074 break; 00075 } 00076 } 00077 } 00078 00079 bool MCSectionCOFF::UseCodeAlign() const { 00080 return getKind().isText(); 00081 } 00082 00083 bool MCSectionCOFF::isVirtualSection() const { 00084 return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA; 00085 }