When removing a function from the function set and adding it to deferred, we
[llvm.git] / lib / MC / MCSectionELF.cpp
blobda54106a19f0997547fc2a20e65b2a5021722181
1 //===- lib/MC/MCSectionELF.cpp - ELF 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 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCSectionELF.h"
11 #include "llvm/MC/MCAsmInfo.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCSymbol.h"
14 #include "llvm/Support/ELF.h"
15 #include "llvm/Support/raw_ostream.h"
17 using namespace llvm;
19 MCSectionELF::~MCSectionELF() {} // anchor.
21 // ShouldOmitSectionDirective - Decides whether a '.section' directive
22 // should be printed before the section name
23 bool MCSectionELF::ShouldOmitSectionDirective(StringRef Name,
24 const MCAsmInfo &MAI) const {
26 // FIXME: Does .section .bss/.data/.text work everywhere??
27 if (Name == ".text" || Name == ".data" ||
28 (Name == ".bss" && !MAI.usesELFSectionDirectiveForBSS()))
29 return true;
31 return false;
34 void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI,
35 raw_ostream &OS) const {
37 if (ShouldOmitSectionDirective(SectionName, MAI)) {
38 OS << '\t' << getSectionName() << '\n';
39 return;
42 OS << "\t.section\t" << getSectionName();
44 // Handle the weird solaris syntax if desired.
45 if (MAI.usesSunStyleELFSectionSwitchSyntax() &&
46 !(Flags & ELF::SHF_MERGE)) {
47 if (Flags & ELF::SHF_ALLOC)
48 OS << ",#alloc";
49 if (Flags & ELF::SHF_EXECINSTR)
50 OS << ",#execinstr";
51 if (Flags & ELF::SHF_WRITE)
52 OS << ",#write";
53 if (Flags & ELF::SHF_TLS)
54 OS << ",#tls";
55 OS << '\n';
56 return;
59 OS << ",\"";
60 if (Flags & ELF::SHF_ALLOC)
61 OS << 'a';
62 if (Flags & ELF::SHF_EXECINSTR)
63 OS << 'x';
64 if (Flags & ELF::SHF_WRITE)
65 OS << 'w';
66 if (Flags & ELF::SHF_MERGE)
67 OS << 'M';
68 if (Flags & ELF::SHF_STRINGS)
69 OS << 'S';
70 if (Flags & ELF::SHF_TLS)
71 OS << 'T';
73 // If there are target-specific flags, print them.
74 if (Flags & ELF::XCORE_SHF_CP_SECTION)
75 OS << 'c';
76 if (Flags & ELF::XCORE_SHF_DP_SECTION)
77 OS << 'd';
79 OS << '"';
81 OS << ',';
83 // If comment string is '@', e.g. as on ARM - use '%' instead
84 if (MAI.getCommentString()[0] == '@')
85 OS << '%';
86 else
87 OS << '@';
89 if (Type == ELF::SHT_INIT_ARRAY)
90 OS << "init_array";
91 else if (Type == ELF::SHT_FINI_ARRAY)
92 OS << "fini_array";
93 else if (Type == ELF::SHT_PREINIT_ARRAY)
94 OS << "preinit_array";
95 else if (Type == ELF::SHT_NOBITS)
96 OS << "nobits";
97 else if (Type == ELF::SHT_NOTE)
98 OS << "note";
99 else if (Type == ELF::SHT_PROGBITS)
100 OS << "progbits";
102 if (EntrySize) {
103 assert(Flags & ELF::SHF_MERGE);
104 OS << "," << EntrySize;
107 OS << '\n';
110 bool MCSectionELF::UseCodeAlign() const {
111 return getFlags() & ELF::SHF_EXECINSTR;
114 bool MCSectionELF::isVirtualSection() const {
115 return getType() == ELF::SHT_NOBITS;
118 // HasCommonSymbols - True if this section holds common symbols, this is
119 // indicated on the ELF object file by a symbol with SHN_COMMON section
120 // header index.
121 bool MCSectionELF::HasCommonSymbols() const {
123 if (StringRef(SectionName).startswith(".gnu.linkonce."))
124 return true;
126 return false;
129 unsigned MCSectionELF::DetermineEntrySize(SectionKind Kind) {
130 if (Kind.isMergeable1ByteCString()) return 1;
131 if (Kind.isMergeable2ByteCString()) return 2;
132 if (Kind.isMergeable4ByteCString()) return 4;
133 if (Kind.isMergeableConst4()) return 4;
134 if (Kind.isMergeableConst8()) return 8;
135 if (Kind.isMergeableConst16()) return 16;
136 return 0;