1//===-- X86MCAsmInfo.cpp - X86 asm properties -----------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the declarations of the X86MCAsmInfo properties.
10//
11//===----------------------------------------------------------------------===//
12
13#include "X86MCAsmInfo.h"
14#include "llvm/MC/MCExpr.h"
15#include "llvm/MC/MCStreamer.h"
16#include "llvm/Support/CommandLine.h"
17#include "llvm/TargetParser/Triple.h"
18using namespace llvm;
19
20enum AsmWriterFlavorTy {
21 // Note: This numbering has to match the GCC assembler dialects for inline
22 // asm alternatives to work right.
23 ATT = 0, Intel = 1
24};
25
26static cl::opt<AsmWriterFlavorTy> X86AsmSyntax(
27 "x86-asm-syntax", cl::init(Val: ATT), cl::Hidden,
28 cl::desc("Select the assembly style for input"),
29 cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"),
30 clEnumValN(Intel, "intel", "Emit Intel-style assembly")));
31
32static cl::opt<bool>
33MarkedJTDataRegions("mark-data-regions", cl::init(Val: true),
34 cl::desc("Mark code section jump table data regions."),
35 cl::Hidden);
36
37const MCAsmInfo::AtSpecifier atSpecifiers[] = {
38 {.Kind: X86::S_ABS8, .Name: "ABS8"},
39 {.Kind: X86::S_DTPOFF, .Name: "DTPOFF"},
40 {.Kind: X86::S_DTPREL, .Name: "DTPREL"},
41 {.Kind: X86::S_GOT, .Name: "GOT"},
42 {.Kind: X86::S_GOTENT, .Name: "GOTENT"},
43 {.Kind: X86::S_GOTNTPOFF, .Name: "GOTNTPOFF"},
44 {.Kind: X86::S_GOTOFF, .Name: "GOTOFF"},
45 {.Kind: X86::S_GOTPCREL, .Name: "GOTPCREL"},
46 {.Kind: X86::S_GOTPCREL_NORELAX, .Name: "GOTPCREL_NORELAX"},
47 {.Kind: X86::S_GOTREL, .Name: "GOTREL"},
48 {.Kind: X86::S_GOTTPOFF, .Name: "GOTTPOFF"},
49 {.Kind: X86::S_INDNTPOFF, .Name: "INDNTPOFF"},
50 {.Kind: MCSymbolRefExpr::VK_COFF_IMGREL32, .Name: "IMGREL"},
51 {.Kind: X86::S_NTPOFF, .Name: "NTPOFF"},
52 {.Kind: X86::S_PCREL, .Name: "PCREL"},
53 {.Kind: X86::S_PLT, .Name: "PLT"},
54 {.Kind: X86::S_PLTOFF, .Name: "PLTOFF"},
55 {.Kind: X86::S_COFF_SECREL, .Name: "SECREL32"},
56 {.Kind: X86::S_SIZE, .Name: "SIZE"},
57 {.Kind: X86::S_TLSCALL, .Name: "tlscall"},
58 {.Kind: X86::S_TLSDESC, .Name: "tlsdesc"},
59 {.Kind: X86::S_TLSGD, .Name: "TLSGD"},
60 {.Kind: X86::S_TLSLD, .Name: "TLSLD"},
61 {.Kind: X86::S_TLSLDM, .Name: "TLSLDM"},
62 {.Kind: X86::S_TLVP, .Name: "TLVP"},
63 {.Kind: X86::S_TLVPPAGE, .Name: "TLVPPAGE"},
64 {.Kind: X86::S_TLVPPAGEOFF, .Name: "TLVPPAGEOFF"},
65 {.Kind: X86::S_TPOFF, .Name: "TPOFF"},
66};
67
68void X86MCAsmInfoDarwin::anchor() { }
69
70X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) {
71 bool is64Bit = T.isX86_64();
72 if (is64Bit)
73 CodePointerSize = CalleeSaveStackSlotSize = 8;
74
75 AssemblerDialect = X86AsmSyntax;
76
77 if (!is64Bit)
78 Data64bitsDirective = nullptr; // we can't emit a 64-bit unit
79
80 // Use ## as a comment string so that .s files generated by llvm can go
81 // through the GCC preprocessor without causing an error. This is needed
82 // because "clang foo.s" runs the C preprocessor, which is usually reserved
83 // for .S files on other systems. Perhaps this is because the file system
84 // wasn't always case preserving or something.
85 CommentString = "##";
86
87 SupportsDebugInformation = true;
88 UseDataRegionDirectives = MarkedJTDataRegions;
89
90 // Exceptions handling
91 ExceptionsType = ExceptionHandling::DwarfCFI;
92
93 // old assembler lacks some directives
94 // FIXME: this should really be a check on the assembler characteristics
95 // rather than OS version
96 if (T.isMacOSX() && T.isMacOSXVersionLT(Major: 10, Minor: 6))
97 HasWeakDefCanBeHiddenDirective = false;
98
99 // Assume ld64 is new enough that the abs-ified FDE relocs may be used
100 // (actually, must, since otherwise the non-extern relocations we produce
101 // overwhelm ld64's tiny little mind and it fails).
102 DwarfFDESymbolsUseAbsDiff = true;
103
104 initializeAtSpecifiers(atSpecifiers);
105}
106
107X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple)
108 : X86MCAsmInfoDarwin(Triple) {
109}
110
111void X86ELFMCAsmInfo::anchor() { }
112
113X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
114 bool is64Bit = T.isX86_64();
115 bool isX32 = T.isX32();
116
117 // For ELF, x86-64 pointer size depends on the ABI.
118 // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64
119 // with the x32 ABI, pointer size remains the default 4.
120 CodePointerSize = (is64Bit && !isX32) ? 8 : 4;
121
122 // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI.
123 CalleeSaveStackSlotSize = is64Bit ? 8 : 4;
124
125 AssemblerDialect = X86AsmSyntax;
126
127 // Debug Information
128 SupportsDebugInformation = true;
129
130 // Exceptions handling
131 ExceptionsType = ExceptionHandling::DwarfCFI;
132
133 initializeAtSpecifiers(atSpecifiers);
134}
135
136const MCExpr *
137X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym,
138 unsigned Encoding,
139 MCStreamer &Streamer) const {
140 MCContext &Context = Streamer.getContext();
141 const MCExpr *Res = MCSymbolRefExpr::create(Symbol: Sym, specifier: X86::S_GOTPCREL, Ctx&: Context);
142 const MCExpr *Four = MCConstantExpr::create(Value: 4, Ctx&: Context);
143 return MCBinaryExpr::createAdd(LHS: Res, RHS: Four, Ctx&: Context);
144}
145
146void X86MCAsmInfoMicrosoft::anchor() { }
147
148X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
149 if (Triple.isX86_64()) {
150 InternalSymbolPrefix = ".L";
151 PrivateLabelPrefix = ".L";
152 CodePointerSize = 8;
153 WinEHEncodingType = WinEH::EncodingType::Itanium;
154 } else {
155 // 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just
156 // a place holder that the Windows EHStreamer looks for to suppress CFI
157 // output. In particular, usesWindowsCFI() returns false.
158 WinEHEncodingType = WinEH::EncodingType::X86;
159 }
160
161 ExceptionsType = ExceptionHandling::WinEH;
162
163 AssemblerDialect = X86AsmSyntax;
164
165 AllowAtInName = true;
166
167 initializeAtSpecifiers(atSpecifiers);
168}
169
170void X86MCAsmInfoMicrosoftMASM::anchor() { }
171
172X86MCAsmInfoMicrosoftMASM::X86MCAsmInfoMicrosoftMASM(const Triple &Triple)
173 : X86MCAsmInfoMicrosoft(Triple) {
174 DollarIsPC = true;
175 SeparatorString = "\n";
176 CommentString = ";";
177 AllowAdditionalComments = false;
178 AllowQuestionAtStartOfIdentifier = true;
179 AllowDollarAtStartOfIdentifier = true;
180 AllowAtAtStartOfIdentifier = true;
181}
182
183void X86MCAsmInfoGNUCOFF::anchor() { }
184
185X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
186 assert((Triple.isOSWindows() || Triple.isUEFI()) &&
187 "Windows and UEFI are the only supported COFF targets");
188 if (Triple.isX86_64()) {
189 InternalSymbolPrefix = ".L";
190 PrivateLabelPrefix = ".L";
191 CodePointerSize = 8;
192 WinEHEncodingType = WinEH::EncodingType::Itanium;
193 ExceptionsType = ExceptionHandling::WinEH;
194 } else {
195 ExceptionsType = ExceptionHandling::DwarfCFI;
196 }
197
198 AssemblerDialect = X86AsmSyntax;
199
200 AllowAtInName = true;
201
202 initializeAtSpecifiers(atSpecifiers);
203}
204