1 //===- lib/MC/MCSectionELF.cpp - ELF Code Section Representation ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCSectionELF.h"
11 #include "llvm/MC/MCContext.h"
12 #include "llvm/Support/raw_ostream.h"
13 #include "llvm/Target/TargetAsmInfo.h"
17 MCSectionELF *MCSectionELF::
18 Create(const StringRef &Section, unsigned Type, unsigned Flags,
19 SectionKind K, bool hasCrazyBSS, bool isExplicit, MCContext &Ctx) {
21 (Ctx) MCSectionELF(Section, Type, Flags, K, hasCrazyBSS, isExplicit);
24 // ShouldOmitSectionDirective - Decides whether a '.section' directive
25 // should be printed before the section name
26 bool MCSectionELF::ShouldOmitSectionDirective(const char *Name) const {
28 // PPC/Linux doesn't support the .bss directive, it needs .section .bss.
29 // FIXME: Does .section .bss/.data/.text work everywhere??
30 if ((!HasCrazyBSS && strncmp(Name, ".bss", 4) == 0) ||
31 strncmp(Name, ".text", 5) == 0 ||
32 strncmp(Name, ".data", 5) == 0)
38 // ShouldPrintSectionType - Only prints the section type if supported
39 bool MCSectionELF::ShouldPrintSectionType(unsigned Ty) const {
41 if (IsExplicit && !(Ty == SHT_NOBITS || Ty == SHT_PROGBITS))
47 void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
48 raw_ostream &OS) const {
50 if (ShouldOmitSectionDirective(SectionName.c_str())) {
51 OS << '\t' << getSectionName() << '\n';
55 OS << "\t.section\t" << getSectionName();
57 // Handle the weird solaris syntax if desired.
58 if (TAI.usesSunStyleELFSectionSwitchSyntax() &&
59 !(Flags & MCSectionELF::SHF_MERGE)) {
60 if (Flags & MCSectionELF::SHF_ALLOC)
62 if (Flags & MCSectionELF::SHF_EXECINSTR)
64 if (Flags & MCSectionELF::SHF_WRITE)
66 if (Flags & MCSectionELF::SHF_TLS)
71 if (Flags & MCSectionELF::SHF_ALLOC)
73 if (Flags & MCSectionELF::SHF_EXECINSTR)
75 if (Flags & MCSectionELF::SHF_WRITE)
77 if (Flags & MCSectionELF::SHF_MERGE)
79 if (Flags & MCSectionELF::SHF_STRINGS)
81 if (Flags & MCSectionELF::SHF_TLS)
86 if (ShouldPrintSectionType(Type)) {
89 // If comment string is '@', e.g. as on ARM - use '%' instead
90 if (TAI.getCommentString()[0] == '@')
95 if (Type == MCSectionELF::SHT_INIT_ARRAY)
97 else if (Type == MCSectionELF::SHT_FINI_ARRAY)
99 else if (Type == MCSectionELF::SHT_PREINIT_ARRAY)
100 OS << "preinit_array";
101 else if (Type == MCSectionELF::SHT_NOBITS)
103 else if (Type == MCSectionELF::SHT_PROGBITS)
106 if (getKind().isMergeable1ByteCString()) {
108 } else if (getKind().isMergeable2ByteCString()) {
110 } else if (getKind().isMergeable4ByteCString() ||
111 getKind().isMergeableConst4()) {
113 } else if (getKind().isMergeableConst8()) {
115 } else if (getKind().isMergeableConst16()) {