blob: 6cedf0655cfd47806559fa6be555f2f9e6019a0c [file] [log] [blame]
Chris Lattnereb40a0f2010-05-07 17:17:41 +00001//===- 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"
15using namespace llvm;
16
17MCSectionCOFF::~MCSectionCOFF() {} // anchor.
18
19// ShouldOmitSectionDirective - Decides whether a '.section' directive
20// should be printed before the section name
21bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name,
22 const MCAsmInfo &MAI) const {
Jim Grosbach2684d9e2012-05-11 01:41:30 +000023
Chris Lattnereb40a0f2010-05-07 17:17:41 +000024 // 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
31void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI,
Peter Collingbournedf39be62013-04-17 21:18:16 +000032 raw_ostream &OS,
33 const MCExpr *Subsection) const {
Jim Grosbach2684d9e2012-05-11 01:41:30 +000034
Nathan Jeffords72e57f92010-05-09 05:49:00 +000035 // standard sections don't require the '.section'
Chris Lattnereb40a0f2010-05-07 17:17:41 +000036 if (ShouldOmitSectionDirective(SectionName, MAI)) {
37 OS << '\t' << getSectionName() << '\n';
38 return;
39 }
40
41 OS << "\t.section\t" << getSectionName() << ",\"";
42 if (getKind().isText())
43 OS << 'x';
44 if (getKind().isWriteable())
45 OS << 'w';
46 else
47 OS << 'r';
Daniel Dunbar94610582010-07-01 20:07:24 +000048 if (getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE)
Chris Lattnereb40a0f2010-05-07 17:17:41 +000049 OS << 'n';
50 OS << "\"\n";
Jim Grosbach2684d9e2012-05-11 01:41:30 +000051
Daniel Dunbar94610582010-07-01 20:07:24 +000052 if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
Nathan Jeffords871bb942010-05-12 04:26:09 +000053 switch (Selection) {
Daniel Dunbar94610582010-07-01 20:07:24 +000054 case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES:
Nathan Jeffords871bb942010-05-12 04:26:09 +000055 OS << "\t.linkonce one_only\n";
56 break;
Daniel Dunbar94610582010-07-01 20:07:24 +000057 case COFF::IMAGE_COMDAT_SELECT_ANY:
Nathan Jeffords871bb942010-05-12 04:26:09 +000058 OS << "\t.linkonce discard\n";
59 break;
Daniel Dunbar94610582010-07-01 20:07:24 +000060 case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE:
Nathan Jeffords871bb942010-05-12 04:26:09 +000061 OS << "\t.linkonce same_size\n";
62 break;
Daniel Dunbar94610582010-07-01 20:07:24 +000063 case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH:
Nathan Jeffords871bb942010-05-12 04:26:09 +000064 OS << "\t.linkonce same_contents\n";
65 break;
Nathan Jeffords62d50e82010-05-12 07:36:03 +000066 //NOTE: as of binutils 2.20, there is no way to specifiy select largest
67 // with the .linkonce directive. For now, we treat it as an invalid
68 // comdat selection value.
Daniel Dunbar94610582010-07-01 20:07:24 +000069 case COFF::IMAGE_COMDAT_SELECT_LARGEST:
Nathan Jeffords871bb942010-05-12 04:26:09 +000070 // OS << "\t.linkonce largest\n";
71 // break;
Nathan Jeffords62d50e82010-05-12 07:36:03 +000072 default:
73 assert (0 && "unsupported COFF selection type");
74 break;
Nathan Jeffords871bb942010-05-12 04:26:09 +000075 }
76 }
Chris Lattnereb40a0f2010-05-07 17:17:41 +000077}
Jan Wen Voung083cf152010-10-04 17:32:41 +000078
79bool MCSectionCOFF::UseCodeAlign() const {
80 return getKind().isText();
81}
Rafael Espindolaf2dc4aa2010-11-17 20:03:54 +000082
83bool MCSectionCOFF::isVirtualSection() const {
84 return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
85}