blob: 7d93555872185e9a4d4adc473e0c8d04d48023d8 [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"
Chris Lattner9a6cf912009-08-12 07:22:17 +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"),
34 clEnumValN(Intel, "intel", "Emit Intel-style assembly"),
35 clEnumValEnd));
36
Jim Grosbach361ca342012-09-24 23:06:27 +000037static cl::opt<bool>
38MarkedJTDataRegions("mark-data-regions", cl::init(false),
39 cl::desc("Mark code section jump table data regions."),
40 cl::Hidden);
Chris Lattner1e9097e2009-08-11 23:01:09 +000041
David Blaikiea379b1812011-12-20 02:50:00 +000042void X86MCAsmInfoDarwin::anchor() { }
43
Evan Chenga83b37a2011-07-15 02:09:41 +000044X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) {
45 bool is64Bit = T.getArch() == Triple::x86_64;
46 if (is64Bit)
Eli Bendersky0893e102013-01-22 18:02:49 +000047 PointerSize = CalleeSaveStackSlotSize = 8;
Evan Chenga83b37a2011-07-15 02:09:41 +000048
Chris Lattner1e9097e2009-08-11 23:01:09 +000049 AssemblerDialect = AsmWriterFlavor;
Eric Christopher719c2972011-07-07 22:54:12 +000050
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000051 TextAlignFillValue = 0x90;
Daniel Dunbar123686852009-07-24 08:24:36 +000052
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000053 if (!is64Bit)
54 Data64bitsDirective = 0; // we can't emit a 64-bit unit
Bill Wendling0a860df2009-07-13 18:48:39 +000055
Chris Lattnerd8716672010-02-17 01:38:01 +000056 // Use ## as a comment string so that .s files generated by llvm can go
Chris Lattnerb67807e2010-02-17 01:55:54 +000057 // 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.
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000061 CommentString = "##";
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000062
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000063 SupportsDebugInformation = true;
Jim Grosbach361ca342012-09-24 23:06:27 +000064 UseDataRegionDirectives = MarkedJTDataRegions;
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000065
66 // Exceptions handling
Rafael Espindolafc822362011-05-01 15:44:13 +000067 ExceptionsType = ExceptionHandling::DwarfCFI;
David Fang1b018492013-12-10 21:37:41 +000068
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;
Iain Sandoe618def62014-01-08 10:22:54 +000074
75 // FIXME: this should not depend on the target OS version, but on the ld64
76 // version in use. From at least >= ld64-97.17 (Xcode 3.2.6) the abs-ified
77 // FDE relocs may be used.
78 DwarfFDESymbolsUseAbsDiff = T.isMacOSX() && !T.isMacOSXVersionLT(10, 6);
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000079}
80
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000081X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple)
82 : X86MCAsmInfoDarwin(Triple) {
83}
84
David Blaikiea379b1812011-12-20 02:50:00 +000085void X86ELFMCAsmInfo::anchor() { }
86
Chris Lattner963b2332010-03-11 00:06:19 +000087X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
Eli Bendersky0893e102013-01-22 18:02:49 +000088 bool is64Bit = T.getArch() == Triple::x86_64;
89 bool isX32 = T.getEnvironment() == Triple::GNUX32;
90
91 // For ELF, x86-64 pointer size depends on the ABI.
92 // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64
93 // with the x32 ABI, pointer size remains the default 4.
94 PointerSize = (is64Bit && !isX32) ? 8 : 4;
95
96 // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI.
97 CalleeSaveStackSlotSize = is64Bit ? 8 : 4;
Evan Chenga83b37a2011-07-15 02:09:41 +000098
Chris Lattner1e9097e2009-08-11 23:01:09 +000099 AssemblerDialect = AsmWriterFlavor;
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000100
Daniel Dunbar68e22cb2010-02-25 18:07:10 +0000101 TextAlignFillValue = 0x90;
102
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000103 // Set up DWARF directives
104 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
105
106 // Debug Information
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000107 SupportsDebugInformation = true;
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000108
109 // Exceptions handling
Rafael Espindolaa01cdb02011-04-15 15:11:06 +0000110 ExceptionsType = ExceptionHandling::DwarfCFI;
111
Eric Christopher22738d02012-08-06 20:52:18 +0000112 // OpenBSD and Bitrig have buggy support for .quad in 32-bit mode, just split
113 // into two .words.
114 if ((T.getOS() == Triple::OpenBSD || T.getOS() == Triple::Bitrig) &&
115 T.getArch() == Triple::x86)
Chris Lattner963b2332010-03-11 00:06:19 +0000116 Data64bitsDirective = 0;
Chris Lattner76bdea32010-01-23 07:21:06 +0000117}
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000118
Evan Chenga83b37a2011-07-15 02:09:41 +0000119const MCExpr *
120X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym,
121 unsigned Encoding,
122 MCStreamer &Streamer) const {
123 MCContext &Context = Streamer.getContext();
124 const MCExpr *Res =
125 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context);
126 const MCExpr *Four = MCConstantExpr::Create(4, Context);
127 return MCBinaryExpr::CreateAdd(Res, Four, Context);
128}
129
Chris Lattner5418dd52010-04-08 21:26:26 +0000130const MCSection *X86ELFMCAsmInfo::
131getNonexecutableStackSection(MCContext &Ctx) const {
Rafael Espindolaaea49582011-01-23 04:28:49 +0000132 return Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS,
Rafael Espindola19fa3802010-11-11 03:40:25 +0000133 0, SectionKind::getMetadata());
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000134}
135
David Blaikiea379b1812011-12-20 02:50:00 +0000136void X86MCAsmInfoMicrosoft::anchor() { }
137
Michael J. Spencerde3a2112011-11-29 18:00:06 +0000138X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
Rafael Espindola58873562014-01-03 19:21:54 +0000139 if (Triple.getArch() == Triple::x86_64)
Michael J. Spencerde3a2112011-11-29 18:00:06 +0000140 PrivateGlobalPrefix = ".L";
Michael J. Spencerde3a2112011-11-29 18:00:06 +0000141
Michael J. Spencerde3a2112011-11-29 18:00:06 +0000142 AssemblerDialect = AsmWriterFlavor;
143
144 TextAlignFillValue = 0x90;
Hans Wennborgce69d772013-10-18 20:46:28 +0000145
146 AllowAtInName = true;
Michael J. Spencerde3a2112011-11-29 18:00:06 +0000147}
148
David Blaikiea379b1812011-12-20 02:50:00 +0000149void X86MCAsmInfoGNUCOFF::anchor() { }
150
Michael J. Spencerde3a2112011-11-29 18:00:06 +0000151X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
Rafael Espindola58873562014-01-03 19:21:54 +0000152 if (Triple.getArch() == Triple::x86_64)
NAKAMURA Takumi547cc6f2010-12-07 02:43:45 +0000153 PrivateGlobalPrefix = ".L";
Michael J. Spencer377aa202010-08-21 05:58:13 +0000154
Chris Lattner1e9097e2009-08-11 23:01:09 +0000155 AssemblerDialect = AsmWriterFlavor;
Daniel Dunbar68e22cb2010-02-25 18:07:10 +0000156
157 TextAlignFillValue = 0x90;
NAKAMURA Takumib95f6412012-04-07 02:24:20 +0000158
159 // Exceptions handling
160 ExceptionsType = ExceptionHandling::DwarfCFI;
Benjamin Kramerd7d8afa2010-02-16 10:25:04 +0000161}