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