1 //===-- COFFTargetAsmInfo.cpp - COFF asm properties -------------*- C++ -*-===//
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 // This file defines target asm properties related what form asm statements
11 // should take in general on COFF-based targets
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Target/COFFTargetAsmInfo.h"
16 #include "llvm/ADT/SmallVector.h"
19 COFFTargetAsmInfo::COFFTargetAsmInfo(const TargetMachine &TM)
22 TextSection = getOrCreateSection("_text", true, SectionKind::Text);
23 DataSection = getOrCreateSection("_data", true, SectionKind::DataRel);
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";
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\"";
56 void COFFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
57 SmallVectorImpl<char> &Str) const {
58 // FIXME: Inefficient.
59 std::string Res = ",\"";
62 if (Kind.isWriteable())
66 Str.append(Res.begin(), Res.end());
69 //===----------------------------------------------------------------------===//
70 // Move to AsmPrinter (mangler access).
71 //===----------------------------------------------------------------------===//
73 #include "llvm/GlobalVariable.h"
75 static const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) {
77 return ".text$linkonce";
78 if (Kind.isWriteable())
79 return ".data$linkonce";
80 return ".rdata$linkonce";
84 COFFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
85 SectionKind Kind) const {
86 assert(!Kind.isThreadLocal() && "Doesn't support TLS");
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.
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());
98 return getTextSection();
101 if (const Section *S = getBSSSection_())
104 if (Kind.isReadOnly())
105 if (const Section *S = getReadOnlySection())
108 return getDataSection();