1 //===-- X86MCAsmInfo.cpp - X86 asm properties -----------------------------===//
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 contains the declarations of the X86MCAsmInfo properties.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "X86MCAsmInfo.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCSectionELF.h"
19 #include "llvm/MC/MCStreamer.h"
20 #include "llvm/Support/ELF.h"
21 using namespace llvm;
22
23 //#include <iostream>
24 enum AsmWriterFlavorTy {
25 // Note: This numbering has to match the GCC assembler dialects for inline
26 // asm alternatives to work right.
27 ATT = 0, Intel = 1
28 };
29
30 static AsmWriterFlavorTy AsmWriterFlavor = Intel; // ATT
31
32 static bool MarkedJTDataRegions = false;
33
X86MCAsmInfoDarwin(const Triple & T)34 X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) {
35 bool is64Bit = T.getArch() == Triple::x86_64;
36 if (is64Bit)
37 PointerSize = CalleeSaveStackSlotSize = 8;
38
39 AssemblerDialect = AsmWriterFlavor;
40
41 TextAlignFillValue = 0x90;
42
43 if (!is64Bit)
44 Data64bitsDirective = nullptr; // we can't emit a 64-bit unit
45
46 // Use ## as a comment string so that .s files generated by llvm can go
47 // through the GCC preprocessor without causing an error. This is needed
48 // because "clang foo.s" runs the C preprocessor, which is usually reserved
49 // for .S files on other systems. Perhaps this is because the file system
50 // wasn't always case preserving or something.
51 CommentString = "##";
52
53 SupportsDebugInformation = true;
54 UseDataRegionDirectives = MarkedJTDataRegions;
55
56 // Exceptions handling
57 ExceptionsType = ExceptionHandling::DwarfCFI;
58
59 // old assembler lacks some directives
60 // FIXME: this should really be a check on the assembler characteristics
61 // rather than OS version
62 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6))
63 HasWeakDefCanBeHiddenDirective = false;
64
65 // Assume ld64 is new enough that the abs-ified FDE relocs may be used
66 // (actually, must, since otherwise the non-extern relocations we produce
67 // overwhelm ld64's tiny little mind and it fails).
68 DwarfFDESymbolsUseAbsDiff = true;
69
70 UseIntegratedAssembler = true;
71 }
72
X86_64MCAsmInfoDarwin(const Triple & Triple)73 X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple)
74 : X86MCAsmInfoDarwin(Triple) {
75 }
76
X86ELFMCAsmInfo(const Triple & T)77 X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
78 bool is64Bit = T.getArch() == Triple::x86_64;
79 bool isX32 = T.getEnvironment() == Triple::GNUX32;
80
81 // For ELF, x86-64 pointer size depends on the ABI.
82 // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64
83 // with the x32 ABI, pointer size remains the default 4.
84 PointerSize = (is64Bit && !isX32) ? 8 : 4;
85
86 // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI.
87 CalleeSaveStackSlotSize = is64Bit ? 8 : 4;
88
89 AssemblerDialect = AsmWriterFlavor;
90
91 TextAlignFillValue = 0x90;
92
93 // Debug Information
94 SupportsDebugInformation = true;
95
96 // Exceptions handling
97 ExceptionsType = ExceptionHandling::DwarfCFI;
98
99 // Always enable the integrated assembler by default.
100 // Clang also enabled it when the OS is Solaris but that is redundant here.
101 UseIntegratedAssembler = true;
102 }
103
104 const MCExpr *
getExprForPersonalitySymbol(const MCSymbol * Sym,unsigned Encoding,MCStreamer & Streamer) const105 X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym,
106 unsigned Encoding,
107 MCStreamer &Streamer) const {
108 MCContext &Context = Streamer.getContext();
109 const MCExpr *Res =
110 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context);
111 const MCExpr *Four = MCConstantExpr::create(4, Context);
112 return MCBinaryExpr::createAdd(Res, Four, Context);
113 }
114
X86MCAsmInfoMicrosoft(const Triple & Triple)115 X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
116 if (Triple.getArch() == Triple::x86_64) {
117 PrivateGlobalPrefix = ".L";
118 PrivateLabelPrefix = ".L";
119 PointerSize = 8;
120 WinEHEncodingType = WinEH::EncodingType::Itanium;
121 } else {
122 // 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just
123 // a place holder that the Windows EHStreamer looks for to suppress CFI
124 // output. In particular, usesWindowsCFI() returns false.
125 WinEHEncodingType = WinEH::EncodingType::X86;
126 }
127
128 ExceptionsType = ExceptionHandling::WinEH;
129
130 AssemblerDialect = AsmWriterFlavor;
131
132 TextAlignFillValue = 0x90;
133
134 AllowAtInName = true;
135
136 UseIntegratedAssembler = true;
137 }
138
X86MCAsmInfoGNUCOFF(const Triple & Triple)139 X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
140 assert(Triple.isOSWindows() && "Windows is the only supported COFF target");
141 if (Triple.getArch() == Triple::x86_64) {
142 PrivateGlobalPrefix = ".L";
143 PrivateLabelPrefix = ".L";
144 PointerSize = 8;
145 WinEHEncodingType = WinEH::EncodingType::Itanium;
146 ExceptionsType = ExceptionHandling::WinEH;
147 } else {
148 ExceptionsType = ExceptionHandling::DwarfCFI;
149 }
150
151 AssemblerDialect = AsmWriterFlavor;
152
153 TextAlignFillValue = 0x90;
154
155 UseIntegratedAssembler = true;
156 }
157