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