blob: 48a1d8f1330cd876ecf7dd660a05c7b808cba646 [file] [log] [blame]
Chris Lattner7b26fce2009-08-22 20:48:53 +00001//===-- X86MCAsmInfo.cpp - X86 asm properties -----------------------------===//
Jim Laskey0e835412006-09-07 22:05:02 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jim Laskey0e835412006-09-07 22:05:02 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner7b26fce2009-08-22 20:48:53 +000010// This file contains the declarations of the X86MCAsmInfo properties.
Jim Laskey0e835412006-09-07 22:05:02 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner7b26fce2009-08-22 20:48:53 +000014#include "X86MCAsmInfo.h"
Daniel Sanders50f17232015-09-15 16:17:27 +000015#include "llvm/ADT/Triple.h"
Chris Lattner5418dd52010-04-08 21:26:26 +000016#include "llvm/MC/MCContext.h"
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000017#include "llvm/MC/MCExpr.h"
Chris Lattner76bdea32010-01-23 07:21:06 +000018#include "llvm/MC/MCSectionELF.h"
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000019#include "llvm/MC/MCStreamer.h"
Chris Lattner1e9097e2009-08-11 23:01:09 +000020#include "llvm/Support/CommandLine.h"
Rafael Espindolaaea49582011-01-23 04:28:49 +000021#include "llvm/Support/ELF.h"
Jim Laskey0e835412006-09-07 22:05:02 +000022using namespace llvm;
Chris Lattner1e9097e2009-08-11 23:01:09 +000023
24enum 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
Chris Lattner1e9097e2009-08-11 23:01:09 +000030static cl::opt<AsmWriterFlavorTy>
31AsmWriterFlavor("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"),
Mehdi Amini732afdd2016-10-08 19:41:06 +000034 clEnumValN(Intel, "intel", "Emit Intel-style assembly")));
Chris Lattner1e9097e2009-08-11 23:01:09 +000035
Jim Grosbach361ca342012-09-24 23:06:27 +000036static cl::opt<bool>
Tim Northoverd2ecbcc2016-05-03 21:03:41 +000037MarkedJTDataRegions("mark-data-regions", cl::init(true),
Jim Grosbach361ca342012-09-24 23:06:27 +000038 cl::desc("Mark code section jump table data regions."),
39 cl::Hidden);
Chris Lattner1e9097e2009-08-11 23:01:09 +000040
David Blaikiea379b1812011-12-20 02:50:00 +000041void X86MCAsmInfoDarwin::anchor() { }
42
Daniel Sanders50f17232015-09-15 16:17:27 +000043X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) {
44 bool is64Bit = T.getArch() == Triple::x86_64;
Evan Chenga83b37a2011-07-15 02:09:41 +000045 if (is64Bit)
Eli Bendersky0893e102013-01-22 18:02:49 +000046 PointerSize = CalleeSaveStackSlotSize = 8;
Evan Chenga83b37a2011-07-15 02:09:41 +000047
Chris Lattner1e9097e2009-08-11 23:01:09 +000048 AssemblerDialect = AsmWriterFlavor;
Eric Christopher719c2972011-07-07 22:54:12 +000049
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000050 TextAlignFillValue = 0x90;
Daniel Dunbar123686852009-07-24 08:24:36 +000051
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000052 if (!is64Bit)
Craig Topper062a2ba2014-04-25 05:30:21 +000053 Data64bitsDirective = nullptr; // we can't emit a 64-bit unit
Bill Wendling0a860df2009-07-13 18:48:39 +000054
Chris Lattnerd8716672010-02-17 01:38:01 +000055 // Use ## as a comment string so that .s files generated by llvm can go
Chris Lattnerb67807e2010-02-17 01:55:54 +000056 // through the GCC preprocessor without causing an error. This is needed
57 // because "clang foo.s" runs the C preprocessor, which is usually reserved
58 // for .S files on other systems. Perhaps this is because the file system
59 // wasn't always case preserving or something.
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000060 CommentString = "##";
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000061
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000062 SupportsDebugInformation = true;
Jim Grosbach361ca342012-09-24 23:06:27 +000063 UseDataRegionDirectives = MarkedJTDataRegions;
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000064
65 // Exceptions handling
Rafael Espindolafc822362011-05-01 15:44:13 +000066 ExceptionsType = ExceptionHandling::DwarfCFI;
David Fang1b018492013-12-10 21:37:41 +000067
68 // old assembler lacks some directives
69 // FIXME: this should really be a check on the assembler characteristics
70 // rather than OS version
Daniel Sanders50f17232015-09-15 16:17:27 +000071 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6))
David Fang1b018492013-12-10 21:37:41 +000072 HasWeakDefCanBeHiddenDirective = false;
Iain Sandoe618def62014-01-08 10:22:54 +000073
Tim Northover0942e392014-07-22 15:47:09 +000074 // Assume ld64 is new enough that the abs-ified FDE relocs may be used
75 // (actually, must, since otherwise the non-extern relocations we produce
76 // overwhelm ld64's tiny little mind and it fails).
77 DwarfFDESymbolsUseAbsDiff = true;
Daniel Sanders753e1762014-02-13 14:44:26 +000078
79 UseIntegratedAssembler = true;
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000080}
81
Daniel Sanders50f17232015-09-15 16:17:27 +000082X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple)
83 : X86MCAsmInfoDarwin(Triple) {
84}
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000085
David Blaikiea379b1812011-12-20 02:50:00 +000086void X86ELFMCAsmInfo::anchor() { }
87
Daniel Sanders50f17232015-09-15 16:17:27 +000088X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
89 bool is64Bit = T.getArch() == Triple::x86_64;
90 bool isX32 = T.getEnvironment() == Triple::GNUX32;
Eli Bendersky0893e102013-01-22 18:02:49 +000091
92 // For ELF, x86-64 pointer size depends on the ABI.
93 // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64
94 // with the x32 ABI, pointer size remains the default 4.
95 PointerSize = (is64Bit && !isX32) ? 8 : 4;
96
97 // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI.
98 CalleeSaveStackSlotSize = is64Bit ? 8 : 4;
Evan Chenga83b37a2011-07-15 02:09:41 +000099
Chris Lattner1e9097e2009-08-11 23:01:09 +0000100 AssemblerDialect = AsmWriterFlavor;
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000101
Daniel Dunbar68e22cb2010-02-25 18:07:10 +0000102 TextAlignFillValue = 0x90;
103
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000104 // Debug Information
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000105 SupportsDebugInformation = true;
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000106
107 // Exceptions handling
Rafael Espindolaa01cdb02011-04-15 15:11:06 +0000108 ExceptionsType = ExceptionHandling::DwarfCFI;
109
Daniel Sanders753e1762014-02-13 14:44:26 +0000110 // Always enable the integrated assembler by default.
111 // Clang also enabled it when the OS is Solaris but that is redundant here.
112 UseIntegratedAssembler = true;
Chris Lattner76bdea32010-01-23 07:21:06 +0000113}
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000114
Evan Chenga83b37a2011-07-15 02:09:41 +0000115const MCExpr *
116X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym,
117 unsigned Encoding,
118 MCStreamer &Streamer) const {
119 MCContext &Context = Streamer.getContext();
120 const MCExpr *Res =
Jim Grosbach13760bd2015-05-30 01:25:56 +0000121 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context);
122 const MCExpr *Four = MCConstantExpr::create(4, Context);
123 return MCBinaryExpr::createAdd(Res, Four, Context);
Evan Chenga83b37a2011-07-15 02:09:41 +0000124}
125
David Blaikiea379b1812011-12-20 02:50:00 +0000126void X86MCAsmInfoMicrosoft::anchor() { }
127
Daniel Sanders50f17232015-09-15 16:17:27 +0000128X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
129 if (Triple.getArch() == Triple::x86_64) {
Michael J. Spencerde3a2112011-11-29 18:00:06 +0000130 PrivateGlobalPrefix = ".L";
Matt Arsenault4e273432014-12-04 00:06:57 +0000131 PrivateLabelPrefix = ".L";
NAKAMURA Takumi1db59952014-06-25 12:41:52 +0000132 PointerSize = 8;
Saleem Abdulrasoold1a4ed62014-09-01 23:48:39 +0000133 WinEHEncodingType = WinEH::EncodingType::Itanium;
Reid Kleckner1d3d4ad2015-05-29 17:00:57 +0000134 } else {
135 // 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just
136 // a place holder that the Windows EHStreamer looks for to suppress CFI
137 // output. In particular, usesWindowsCFI() returns false.
138 WinEHEncodingType = WinEH::EncodingType::X86;
NAKAMURA Takumi1db59952014-06-25 12:41:52 +0000139 }
Michael J. Spencerde3a2112011-11-29 18:00:06 +0000140
Reid Kleckner0738a9c2015-05-05 17:44:16 +0000141 ExceptionsType = ExceptionHandling::WinEH;
142
Michael J. Spencerde3a2112011-11-29 18:00:06 +0000143 AssemblerDialect = AsmWriterFlavor;
144
145 TextAlignFillValue = 0x90;
Hans Wennborgce69d772013-10-18 20:46:28 +0000146
147 AllowAtInName = true;
Daniel Sanders753e1762014-02-13 14:44:26 +0000148
149 UseIntegratedAssembler = true;
Michael J. Spencerde3a2112011-11-29 18:00:06 +0000150}
151
David Blaikiea379b1812011-12-20 02:50:00 +0000152void X86MCAsmInfoGNUCOFF::anchor() { }
153
Daniel Sanders50f17232015-09-15 16:17:27 +0000154X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
155 assert(Triple.isOSWindows() && "Windows is the only supported COFF target");
156 if (Triple.getArch() == Triple::x86_64) {
NAKAMURA Takumi547cc6f2010-12-07 02:43:45 +0000157 PrivateGlobalPrefix = ".L";
Matt Arsenault4e273432014-12-04 00:06:57 +0000158 PrivateLabelPrefix = ".L";
NAKAMURA Takumi35289342014-04-08 15:28:50 +0000159 PointerSize = 8;
Saleem Abdulrasoold1a4ed62014-09-01 23:48:39 +0000160 WinEHEncodingType = WinEH::EncodingType::Itanium;
Reid Kleckner5cc15692015-01-23 18:49:01 +0000161 ExceptionsType = ExceptionHandling::WinEH;
NAKAMURA Takumi1db59952014-06-25 12:41:52 +0000162 } else {
163 ExceptionsType = ExceptionHandling::DwarfCFI;
NAKAMURA Takumi35289342014-04-08 15:28:50 +0000164 }
Michael J. Spencer377aa202010-08-21 05:58:13 +0000165
Chris Lattner1e9097e2009-08-11 23:01:09 +0000166 AssemblerDialect = AsmWriterFlavor;
Daniel Dunbar68e22cb2010-02-25 18:07:10 +0000167
168 TextAlignFillValue = 0x90;
NAKAMURA Takumib95f6412012-04-07 02:24:20 +0000169
Daniel Sanders753e1762014-02-13 14:44:26 +0000170 UseIntegratedAssembler = true;
Benjamin Kramerd7d8afa2010-02-16 10:25:04 +0000171}