1 //===-- X86TargetAsmInfo.cpp - X86 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 contains the declarations of the X86TargetAsmInfo properties.
12 //===----------------------------------------------------------------------===//
14 #include "X86TargetAsmInfo.h"
15 #include "X86TargetMachine.h"
16 #include "X86Subtarget.h"
17 #include "llvm/DerivedTypes.h"
18 #include "llvm/InlineAsm.h"
19 #include "llvm/Instructions.h"
20 #include "llvm/Intrinsics.h"
21 #include "llvm/Module.h"
22 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/Support/Dwarf.h"
24 #include "llvm/Support/ErrorHandling.h"
27 using namespace llvm::dwarf;
29 const char *const llvm::x86_asm_table[] = {
41 X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM):
42 X86TargetAsmInfo<DarwinTargetAsmInfo>(TM) {
43 const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
44 bool is64Bit = Subtarget->is64Bit();
46 AlignmentIsInBytes = false;
47 TextAlignFillValue = 0x90;
51 Data64bitsDirective = 0; // we can't emit a 64-bit unit
52 ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
53 ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
54 if (TM.getRelocationModel() != Reloc::Static)
55 ConstantPoolSection = "\t.const_data";
57 ConstantPoolSection = "\t.const\n";
58 // FIXME: Why don't we always use this section?
60 SixteenByteConstantSection = getUnnamedSection("\t.literal16\n",
61 SectionFlags::Mergeable);
62 LCOMMDirective = "\t.lcomm\t";
64 // Leopard and above support aligned common symbols.
65 COMMDirectiveTakesAlignment = (Subtarget->getDarwinVers() >= 9);
66 HasDotTypeDotSizeDirective = false;
69 PersonalityPrefix = "";
70 PersonalitySuffix = "+4@GOTPCREL";
72 PersonalityPrefix = "L";
73 PersonalitySuffix = "$non_lazy_ptr";
76 InlineAsmStart = "## InlineAsm Start";
77 InlineAsmEnd = "## InlineAsm End";
79 SetDirective = "\t.set";
81 UsedDirective = "\t.no_dead_strip\t";
82 ProtectedDirective = "\t.globl\t";
84 SupportsDebugInformation = true;
85 DwarfDebugInlineSection = ".section __DWARF,__debug_inlined,regular,debug";
86 DwarfUsesInlineInfoSection = true;
88 // Exceptions handling
89 SupportsExceptionHandling = true;
90 GlobalEHDirective = "\t.globl\t";
91 SupportsWeakOmittedEHFrame = false;
92 AbsoluteEHSectionOffsets = false;
94 ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
95 DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
99 X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
101 if (Reason == DwarfEncoding::Functions && Global)
102 return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
103 else if (Reason == DwarfEncoding::CodeLabels || !Global)
104 return DW_EH_PE_pcrel;
106 return DW_EH_PE_absptr;
110 X86DarwinTargetAsmInfo::getEHGlobalPrefix() const
112 const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
113 if (Subtarget->getDarwinVers() > 9)
114 return PrivateGlobalPrefix;
119 X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
120 X86TargetAsmInfo<ELFTargetAsmInfo>(TM) {
122 CStringSection = ".rodata.str";
123 PrivateGlobalPrefix = ".L";
124 WeakRefDirective = "\t.weak\t";
125 SetDirective = "\t.set\t";
128 // Set up DWARF directives
129 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
131 BSSSection_ = getUnnamedSection("\t.bss",
132 SectionFlags::Writable | SectionFlags::BSS);
135 AbsoluteDebugSectionOffsets = true;
136 SupportsDebugInformation = true;
137 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
138 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
139 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
140 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
141 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
142 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
143 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
144 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
145 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
146 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
147 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
149 // Exceptions handling
150 SupportsExceptionHandling = true;
151 AbsoluteEHSectionOffsets = false;
152 DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
153 DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
155 // On Linux we must declare when we can use a non-executable stack.
156 if (TM.getSubtarget<X86Subtarget>().isLinux())
157 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
161 X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
163 CodeModel::Model CM = TM.getCodeModel();
164 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
166 if (TM.getRelocationModel() == Reloc::PIC_) {
170 // 32 bit targets always encode pointers as 4 bytes
171 Format = DW_EH_PE_sdata4;
173 // 64 bit targets encode pointers in 4 bytes iff:
174 // - code model is small OR
175 // - code model is medium and we're emitting externally visible symbols
176 // or any code symbols
177 if (CM == CodeModel::Small ||
178 (CM == CodeModel::Medium && (Global ||
179 Reason != DwarfEncoding::Data)))
180 Format = DW_EH_PE_sdata4;
182 Format = DW_EH_PE_sdata8;
186 Format |= DW_EH_PE_indirect;
188 return (Format | DW_EH_PE_pcrel);
191 (CM == CodeModel::Small ||
192 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
193 return DW_EH_PE_udata4;
195 return DW_EH_PE_absptr;
199 X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
200 X86GenericTargetAsmInfo(TM) {
203 LCOMMDirective = "\t.lcomm\t";
204 COMMDirectiveTakesAlignment = false;
205 HasDotTypeDotSizeDirective = false;
206 HasSingleParameterDotFile = false;
207 StaticCtorsSection = "\t.section .ctors,\"aw\"";
208 StaticDtorsSection = "\t.section .dtors,\"aw\"";
209 HiddenDirective = NULL;
210 PrivateGlobalPrefix = "L"; // Prefix for private global symbols
211 WeakRefDirective = "\t.weak\t";
212 SetDirective = "\t.set\t";
214 // Set up DWARF directives
215 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
216 AbsoluteDebugSectionOffsets = true;
217 AbsoluteEHSectionOffsets = false;
218 SupportsDebugInformation = true;
219 DwarfSectionOffsetDirective = "\t.secrel32\t";
220 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\"";
221 DwarfInfoSection = "\t.section\t.debug_info,\"dr\"";
222 DwarfLineSection = "\t.section\t.debug_line,\"dr\"";
223 DwarfFrameSection = "\t.section\t.debug_frame,\"dr\"";
224 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
225 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
226 DwarfStrSection = "\t.section\t.debug_str,\"dr\"";
227 DwarfLocSection = "\t.section\t.debug_loc,\"dr\"";
228 DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
229 DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\"";
230 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
234 X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
236 CodeModel::Model CM = TM.getCodeModel();
237 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
239 if (TM.getRelocationModel() == Reloc::PIC_) {
243 // 32 bit targets always encode pointers as 4 bytes
244 Format = DW_EH_PE_sdata4;
246 // 64 bit targets encode pointers in 4 bytes iff:
247 // - code model is small OR
248 // - code model is medium and we're emitting externally visible symbols
249 // or any code symbols
250 if (CM == CodeModel::Small ||
251 (CM == CodeModel::Medium && (Global ||
252 Reason != DwarfEncoding::Data)))
253 Format = DW_EH_PE_sdata4;
255 Format = DW_EH_PE_sdata8;
259 Format |= DW_EH_PE_indirect;
261 return (Format | DW_EH_PE_pcrel);
265 (CM == CodeModel::Small ||
266 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
267 return DW_EH_PE_udata4;
268 return DW_EH_PE_absptr;
271 const char *X86COFFTargetAsmInfo::
272 getSectionPrefixForUniqueGlobal(SectionKind Kind) const {
274 return ".text$linkonce";
275 if (Kind.isWriteable())
276 return ".data$linkonce";
277 return ".rdata$linkonce";
281 void X86COFFTargetAsmInfo::getSectionFlags(unsigned Flags,
282 SmallVectorImpl<char> &Str) const {
283 // FIXME: Inefficient.
284 std::string Res = ",\"";
285 if (Flags & SectionFlags::Code)
287 if (Flags & SectionFlags::Writable)
291 Str.append(Res.begin(), Res.end());
294 X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
295 X86GenericTargetAsmInfo(TM) {
299 InlineAsmStart = "; InlineAsm Start";
300 InlineAsmEnd = "; InlineAsm End";
302 PrivateGlobalPrefix = "$";
303 AlignDirective = "\tALIGN\t";
304 ZeroDirective = "\tdb\t";
305 ZeroDirectiveSuffix = " dup(0)";
306 AsciiDirective = "\tdb\t";
308 Data8bitsDirective = "\tdb\t";
309 Data16bitsDirective = "\tdw\t";
310 Data32bitsDirective = "\tdd\t";
311 Data64bitsDirective = "\tdq\t";
312 HasDotTypeDotSizeDirective = false;
313 HasSingleParameterDotFile = false;
315 AlignmentIsInBytes = true;
317 TextSection = getUnnamedSection("_text", SectionFlags::Code);
318 DataSection = getUnnamedSection("_data", SectionFlags::Writable);
320 JumpTableDataSection = NULL;
321 SwitchToSectionDirective = "";
322 TextSectionStartSuffix = "\tSEGMENT PARA 'CODE'";
323 DataSectionStartSuffix = "\tSEGMENT PARA 'DATA'";
324 SectionEndDirectiveSuffix = "\tends\n";
327 // Instantiate default implementation.
328 TEMPLATE_INSTANTIATION(class X86TargetAsmInfo<TargetAsmInfo>);