blob: 27031005bd0987ef29faab77ef8068e6eaa914f1 [file] [log] [blame]
Chris Lattneraf76e592009-08-22 20:48:53 +00001//===-- X86MCAsmInfo.cpp - X86 asm properties -----------------------------===//
Jim Laskey8e8de8f2006-09-07 22:05:02 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Laskey8e8de8f2006-09-07 22:05:02 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattneraf76e592009-08-22 20:48:53 +000010// This file contains the declarations of the X86MCAsmInfo properties.
Jim Laskey8e8de8f2006-09-07 22:05:02 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattneraf76e592009-08-22 20:48:53 +000014#include "X86MCAsmInfo.h"
Chris Lattnera7ac47c2009-08-12 07:22:17 +000015#include "llvm/ADT/Triple.h"
Chris Lattner74aae472010-04-08 21:26:26 +000016#include "llvm/MC/MCContext.h"
Rafael Espindolabfa27cc2011-04-28 16:09:09 +000017#include "llvm/MC/MCExpr.h"
Chris Lattnerf9f93e42010-01-23 07:21:06 +000018#include "llvm/MC/MCSectionELF.h"
Rafael Espindolabfa27cc2011-04-28 16:09:09 +000019#include "llvm/MC/MCStreamer.h"
Chris Lattnerce914b82009-08-11 23:01:09 +000020#include "llvm/Support/CommandLine.h"
Rafael Espindolac85dca62011-01-23 04:28:49 +000021#include "llvm/Support/ELF.h"
Jim Laskey8e8de8f2006-09-07 22:05:02 +000022using namespace llvm;
Chris Lattnerce914b82009-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 Lattnerce914b82009-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
37
Chris Lattnera1a1f022009-08-11 21:57:08 +000038static const char *const x86_asm_table[] = {
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000039 "{si}", "S",
40 "{di}", "D",
41 "{ax}", "a",
42 "{cx}", "c",
43 "{memory}", "memory",
44 "{flags}", "",
45 "{dirflag}", "",
46 "{fpsr}", "",
Eric Christopherd8cca662011-07-07 22:54:12 +000047 "{fpcr}", "",
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000048 "{cc}", "cc",
49 0,0};
Andrew Lenharth6c0695f2006-11-28 19:52:49 +000050
Evan Cheng1be0e272011-07-15 02:09:41 +000051X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) {
52 bool is64Bit = T.getArch() == Triple::x86_64;
53 if (is64Bit)
54 PointerSize = 8;
55
Chris Lattnera1a1f022009-08-11 21:57:08 +000056 AsmTransCBE = x86_asm_table;
Chris Lattnerce914b82009-08-11 23:01:09 +000057 AssemblerDialect = AsmWriterFlavor;
Eric Christopherd8cca662011-07-07 22:54:12 +000058
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000059 TextAlignFillValue = 0x90;
Daniel Dunbarf6ccee52009-07-24 08:24:36 +000060
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000061 if (!is64Bit)
62 Data64bitsDirective = 0; // we can't emit a 64-bit unit
Bill Wendlingb6be1392009-07-13 18:48:39 +000063
Chris Lattnerfeeb93e2010-02-17 01:38:01 +000064 // Use ## as a comment string so that .s files generated by llvm can go
Chris Lattner52be68d2010-02-17 01:55:54 +000065 // through the GCC preprocessor without causing an error. This is needed
66 // because "clang foo.s" runs the C preprocessor, which is usually reserved
67 // for .S files on other systems. Perhaps this is because the file system
68 // wasn't always case preserving or something.
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000069 CommentString = "##";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000070 PCSymbol = ".";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000071
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000072 SupportsDebugInformation = true;
Devang Patel0f7fef32009-04-13 17:02:03 +000073 DwarfUsesInlineInfoSection = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000074
75 // Exceptions handling
Rafael Espindola450a5a12011-05-01 15:44:13 +000076 ExceptionsType = ExceptionHandling::DwarfCFI;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000077}
78
Rafael Espindolabfa27cc2011-04-28 16:09:09 +000079X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple)
80 : X86MCAsmInfoDarwin(Triple) {
81}
82
Chris Lattnerbcc5cb42010-03-11 00:06:19 +000083X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
Evan Cheng1be0e272011-07-15 02:09:41 +000084 if (T.getArch() == Triple::x86_64)
85 PointerSize = 8;
86
Chris Lattnera1a1f022009-08-11 21:57:08 +000087 AsmTransCBE = x86_asm_table;
Chris Lattnerce914b82009-08-11 23:01:09 +000088 AssemblerDialect = AsmWriterFlavor;
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000089
Daniel Dunbar010b1b22010-02-25 18:07:10 +000090 TextAlignFillValue = 0x90;
91
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000092 PrivateGlobalPrefix = ".L";
93 WeakRefDirective = "\t.weak\t";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000094 PCSymbol = ".";
95
96 // Set up DWARF directives
97 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
98
99 // Debug Information
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000100 SupportsDebugInformation = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000101
102 // Exceptions handling
Rafael Espindolaf0adba92011-04-15 15:11:06 +0000103 ExceptionsType = ExceptionHandling::DwarfCFI;
104
Chris Lattnerbcc5cb42010-03-11 00:06:19 +0000105 // OpenBSD has buggy support for .quad in 32-bit mode, just split into two
106 // .words.
107 if (T.getOS() == Triple::OpenBSD && T.getArch() == Triple::x86)
108 Data64bitsDirective = 0;
Chris Lattnerf9f93e42010-01-23 07:21:06 +0000109}
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000110
Evan Cheng1be0e272011-07-15 02:09:41 +0000111const MCExpr *
112X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym,
113 unsigned Encoding,
114 MCStreamer &Streamer) const {
115 MCContext &Context = Streamer.getContext();
116 const MCExpr *Res =
117 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context);
118 const MCExpr *Four = MCConstantExpr::Create(4, Context);
119 return MCBinaryExpr::CreateAdd(Res, Four, Context);
120}
121
Chris Lattner74aae472010-04-08 21:26:26 +0000122const MCSection *X86ELFMCAsmInfo::
123getNonexecutableStackSection(MCContext &Ctx) const {
Rafael Espindolac85dca62011-01-23 04:28:49 +0000124 return Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS,
Rafael Espindola3f2d13c2010-11-11 03:40:25 +0000125 0, SectionKind::getMetadata());
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000126}
127
Chris Lattner8eeba352010-01-20 06:34:14 +0000128X86MCAsmInfoCOFF::X86MCAsmInfoCOFF(const Triple &Triple) {
NAKAMURA Takumi63fbb522010-12-07 02:43:45 +0000129 if (Triple.getArch() == Triple::x86_64) {
Michael J. Spencerda0bfcd2010-08-21 05:58:13 +0000130 GlobalPrefix = "";
NAKAMURA Takumi63fbb522010-12-07 02:43:45 +0000131 PrivateGlobalPrefix = ".L";
132 }
Michael J. Spencerda0bfcd2010-08-21 05:58:13 +0000133
Chris Lattnera1a1f022009-08-11 21:57:08 +0000134 AsmTransCBE = x86_asm_table;
Chris Lattnerce914b82009-08-11 23:01:09 +0000135 AssemblerDialect = AsmWriterFlavor;
Daniel Dunbar010b1b22010-02-25 18:07:10 +0000136
137 TextAlignFillValue = 0x90;
Benjamin Kramer30fb00a2010-02-16 10:25:04 +0000138}