blob: cd7356d55116d9e7cc376821eb7ac6c318f787b9 [file] [log] [blame]
Chris Lattner9418a392009-07-27 16:45:59 +00001//===-- COFFTargetAsmInfo.cpp - COFF asm properties -------------*- C++ -*-===//
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// This file defines target asm properties related what form asm statements
11// should take in general on COFF-based targets
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/Target/COFFTargetAsmInfo.h"
16#include "llvm/ADT/SmallVector.h"
17using namespace llvm;
18
19COFFTargetAsmInfo::COFFTargetAsmInfo(const TargetMachine &TM)
20 : TargetAsmInfo(TM) {
21
22 TextSection = getOrCreateSection("_text", true, SectionKind::Text);
23 DataSection = getOrCreateSection("_data", true, SectionKind::DataRel);
24
25 GlobalPrefix = "_";
26 LCOMMDirective = "\t.lcomm\t";
27 COMMDirectiveTakesAlignment = false;
28 HasDotTypeDotSizeDirective = false;
29 HasSingleParameterDotFile = false;
30 StaticCtorsSection = "\t.section .ctors,\"aw\"";
31 StaticDtorsSection = "\t.section .dtors,\"aw\"";
32 HiddenDirective = NULL;
33 PrivateGlobalPrefix = "L"; // Prefix for private global symbols
34 WeakRefDirective = "\t.weak\t";
35 SetDirective = "\t.set\t";
36
37 // Set up DWARF directives
38 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
39 AbsoluteDebugSectionOffsets = true;
40 AbsoluteEHSectionOffsets = false;
41 SupportsDebugInformation = true;
42 DwarfSectionOffsetDirective = "\t.secrel32\t";
43 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\"";
44 DwarfInfoSection = "\t.section\t.debug_info,\"dr\"";
45 DwarfLineSection = "\t.section\t.debug_line,\"dr\"";
46 DwarfFrameSection = "\t.section\t.debug_frame,\"dr\"";
47 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
48 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
49 DwarfStrSection = "\t.section\t.debug_str,\"dr\"";
50 DwarfLocSection = "\t.section\t.debug_loc,\"dr\"";
51 DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
52 DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\"";
53 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
54}
55
Chris Lattner9418a392009-07-27 16:45:59 +000056void COFFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
57 SmallVectorImpl<char> &Str) const {
58 // FIXME: Inefficient.
59 std::string Res = ",\"";
60 if (Kind.isText())
61 Res += 'x';
62 if (Kind.isWriteable())
63 Res += 'w';
64 Res += "\"";
65
66 Str.append(Res.begin(), Res.end());
67}
Chris Lattner000f7232009-07-27 19:14:14 +000068
69//===----------------------------------------------------------------------===//
70// Move to AsmPrinter (mangler access).
71//===----------------------------------------------------------------------===//
72
73#include "llvm/GlobalVariable.h"
74
75static const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) {
76 if (Kind.isText())
77 return ".text$linkonce";
78 if (Kind.isWriteable())
79 return ".data$linkonce";
80 return ".rdata$linkonce";
81}
82
83const Section *
84COFFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
85 SectionKind Kind) const {
86 assert(!Kind.isThreadLocal() && "Doesn't support TLS");
87
88 // If this global is linkonce/weak and the target handles this by emitting it
89 // into a 'uniqued' section name, create and return the section now.
90 if (Kind.isWeak()) {
91 const char *Prefix = getSectionPrefixForUniqueGlobal(Kind);
92 // FIXME: Use mangler interface (PR4584).
93 std::string Name = Prefix+GV->getNameStr();
94 return getOrCreateSection(Name.c_str(), false, Kind.getKind());
95 }
96
97 if (Kind.isText())
98 return getTextSection();
99
100 if (Kind.isBSS())
101 if (const Section *S = getBSSSection_())
102 return S;
103
104 if (Kind.isReadOnly())
105 if (const Section *S = getReadOnlySection())
106 return S;
107
108 return getDataSection();
109}