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