X86MCAsmInfo.cpp revision 116bc795da4b10773235a89cc251d31651b3851d
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"
22using namespace llvm;
23
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
30static 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
38static const char *const x86_asm_table[] = {
39  "{si}", "S",
40  "{di}", "D",
41  "{ax}", "a",
42  "{cx}", "c",
43  "{memory}", "memory",
44  "{flags}", "",
45  "{dirflag}", "",
46  "{fpsr}", "",
47  "{fpcr}", "",
48  "{cc}", "cc",
49  0,0};
50
51X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) {
52  bool is64Bit = T.getArch() == Triple::x86_64;
53  if (is64Bit)
54    PointerSize = 8;
55
56  AsmTransCBE = x86_asm_table;
57  AssemblerDialect = AsmWriterFlavor;
58
59  TextAlignFillValue = 0x90;
60
61  if (!is64Bit)
62    Data64bitsDirective = 0;       // we can't emit a 64-bit unit
63
64  // Use ## as a comment string so that .s files generated by llvm can go
65  // 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.
69  CommentString = "##";
70  PCSymbol = ".";
71
72  SupportsDebugInformation = true;
73  DwarfUsesInlineInfoSection = true;
74
75  // Exceptions handling
76  ExceptionsType = ExceptionHandling::DwarfCFI;
77}
78
79X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple)
80  : X86MCAsmInfoDarwin(Triple) {
81}
82
83X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
84  if (T.getArch() == Triple::x86_64)
85    PointerSize = 8;
86
87  AsmTransCBE = x86_asm_table;
88  AssemblerDialect = AsmWriterFlavor;
89
90  TextAlignFillValue = 0x90;
91
92  PrivateGlobalPrefix = ".L";
93  WeakRefDirective = "\t.weak\t";
94  PCSymbol = ".";
95
96  // Set up DWARF directives
97  HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
98
99  // Debug Information
100  SupportsDebugInformation = true;
101
102  // Exceptions handling
103  ExceptionsType = ExceptionHandling::DwarfCFI;
104
105  // 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;
109}
110
111const 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
122const MCSection *X86ELFMCAsmInfo::
123getNonexecutableStackSection(MCContext &Ctx) const {
124  return Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS,
125                           0, SectionKind::getMetadata());
126}
127
128X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
129  if (Triple.getArch() == Triple::x86_64) {
130    GlobalPrefix = "";
131    PrivateGlobalPrefix = ".L";
132  }
133
134  AsmTransCBE = x86_asm_table;
135  AssemblerDialect = AsmWriterFlavor;
136
137  TextAlignFillValue = 0x90;
138}
139
140X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
141  if (Triple.getArch() == Triple::x86_64) {
142    GlobalPrefix = "";
143    PrivateGlobalPrefix = ".L";
144  }
145
146  AsmTransCBE = x86_asm_table;
147  AssemblerDialect = AsmWriterFlavor;
148
149  TextAlignFillValue = 0x90;
150}
151