Chris Lattner | 7b26fce | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 1 | //===-- X86MCAsmInfo.cpp - X86 asm properties -----------------------------===// |
Jim Laskey | 0e83541 | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | 0e83541 | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | 7b26fce | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 10 | // This file contains the declarations of the X86MCAsmInfo properties. |
Jim Laskey | 0e83541 | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 7b26fce | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 14 | #include "X86MCAsmInfo.h" |
Chris Lattner | 9a6cf91 | 2009-08-12 07:22:17 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/Triple.h" |
Chris Lattner | 5418dd5 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCContext.h" |
Rafael Espindola | c5dac4d | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCExpr.h" |
Chris Lattner | 76bdea3 | 2010-01-23 07:21:06 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCSectionELF.h" |
Rafael Espindola | c5dac4d | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 1e9097e | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 20 | #include "llvm/Support/CommandLine.h" |
Rafael Espindola | aea4958 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 21 | #include "llvm/Support/ELF.h" |
Jim Laskey | 0e83541 | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 22 | using namespace llvm; |
Chris Lattner | 1e9097e | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 1e9097e | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 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 | |
Jim Grosbach | 361ca34 | 2012-09-24 23:06:27 +0000 | [diff] [blame] | 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); |
Chris Lattner | 1e9097e | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 41 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 42 | void X86MCAsmInfoDarwin::anchor() { } |
| 43 | |
Evan Cheng | a83b37a | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 44 | X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) { |
| 45 | bool is64Bit = T.getArch() == Triple::x86_64; |
| 46 | if (is64Bit) |
Eli Bendersky | 0893e10 | 2013-01-22 18:02:49 +0000 | [diff] [blame] | 47 | PointerSize = CalleeSaveStackSlotSize = 8; |
Evan Cheng | a83b37a | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 1e9097e | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 49 | AssemblerDialect = AsmWriterFlavor; |
Eric Christopher | 719c297 | 2011-07-07 22:54:12 +0000 | [diff] [blame] | 50 | |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 51 | TextAlignFillValue = 0x90; |
Daniel Dunbar | 12368685 | 2009-07-24 08:24:36 +0000 | [diff] [blame] | 52 | |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 53 | if (!is64Bit) |
| 54 | Data64bitsDirective = 0; // we can't emit a 64-bit unit |
Bill Wendling | 0a860df | 2009-07-13 18:48:39 +0000 | [diff] [blame] | 55 | |
Chris Lattner | d871667 | 2010-02-17 01:38:01 +0000 | [diff] [blame] | 56 | // Use ## as a comment string so that .s files generated by llvm can go |
Chris Lattner | b67807e | 2010-02-17 01:55:54 +0000 | [diff] [blame] | 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. |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 61 | CommentString = "##"; |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 62 | |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 63 | SupportsDebugInformation = true; |
Jim Grosbach | 361ca34 | 2012-09-24 23:06:27 +0000 | [diff] [blame] | 64 | UseDataRegionDirectives = MarkedJTDataRegions; |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 65 | |
| 66 | // Exceptions handling |
Rafael Espindola | fc82236 | 2011-05-01 15:44:13 +0000 | [diff] [blame] | 67 | ExceptionsType = ExceptionHandling::DwarfCFI; |
David Fang | 1b01849 | 2013-12-10 21:37:41 +0000 | [diff] [blame] | 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; |
Iain Sandoe | 618def6 | 2014-01-08 10:22:54 +0000 | [diff] [blame] | 74 | |
| 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); |
Daniel Sanders | 753e176 | 2014-02-13 14:44:26 +0000 | [diff] [blame] | 79 | |
| 80 | UseIntegratedAssembler = true; |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Rafael Espindola | c5dac4d | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 83 | X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple) |
| 84 | : X86MCAsmInfoDarwin(Triple) { |
| 85 | } |
| 86 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 87 | void X86ELFMCAsmInfo::anchor() { } |
| 88 | |
Chris Lattner | 963b233 | 2010-03-11 00:06:19 +0000 | [diff] [blame] | 89 | X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) { |
Eli Bendersky | 0893e10 | 2013-01-22 18:02:49 +0000 | [diff] [blame] | 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; |
Evan Cheng | a83b37a | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 100 | |
Chris Lattner | 1e9097e | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 101 | AssemblerDialect = AsmWriterFlavor; |
Anton Korobeynikov | daee281 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 102 | |
Daniel Dunbar | 68e22cb | 2010-02-25 18:07:10 +0000 | [diff] [blame] | 103 | TextAlignFillValue = 0x90; |
| 104 | |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 105 | // Set up DWARF directives |
| 106 | HasLEB128 = true; // Target asm supports leb128 directives (little-endian) |
| 107 | |
| 108 | // Debug Information |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 109 | SupportsDebugInformation = true; |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 110 | |
| 111 | // Exceptions handling |
Rafael Espindola | a01cdb0 | 2011-04-15 15:11:06 +0000 | [diff] [blame] | 112 | ExceptionsType = ExceptionHandling::DwarfCFI; |
| 113 | |
Eric Christopher | 22738d0 | 2012-08-06 20:52:18 +0000 | [diff] [blame] | 114 | // OpenBSD and Bitrig have buggy support for .quad in 32-bit mode, just split |
| 115 | // into two .words. |
| 116 | if ((T.getOS() == Triple::OpenBSD || T.getOS() == Triple::Bitrig) && |
| 117 | T.getArch() == Triple::x86) |
Chris Lattner | 963b233 | 2010-03-11 00:06:19 +0000 | [diff] [blame] | 118 | Data64bitsDirective = 0; |
Daniel Sanders | 753e176 | 2014-02-13 14:44:26 +0000 | [diff] [blame] | 119 | |
| 120 | // Always enable the integrated assembler by default. |
| 121 | // Clang also enabled it when the OS is Solaris but that is redundant here. |
| 122 | UseIntegratedAssembler = true; |
Chris Lattner | 76bdea3 | 2010-01-23 07:21:06 +0000 | [diff] [blame] | 123 | } |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 124 | |
Evan Cheng | a83b37a | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 125 | const MCExpr * |
| 126 | X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym, |
| 127 | unsigned Encoding, |
| 128 | MCStreamer &Streamer) const { |
| 129 | MCContext &Context = Streamer.getContext(); |
| 130 | const MCExpr *Res = |
| 131 | MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context); |
| 132 | const MCExpr *Four = MCConstantExpr::Create(4, Context); |
| 133 | return MCBinaryExpr::CreateAdd(Res, Four, Context); |
| 134 | } |
| 135 | |
Chris Lattner | 5418dd5 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 136 | const MCSection *X86ELFMCAsmInfo:: |
| 137 | getNonexecutableStackSection(MCContext &Ctx) const { |
Rafael Espindola | aea4958 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 138 | return Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS, |
Rafael Espindola | 19fa380 | 2010-11-11 03:40:25 +0000 | [diff] [blame] | 139 | 0, SectionKind::getMetadata()); |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 140 | } |
| 141 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 142 | void X86MCAsmInfoMicrosoft::anchor() { } |
| 143 | |
Michael J. Spencer | de3a211 | 2011-11-29 18:00:06 +0000 | [diff] [blame] | 144 | X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) { |
Rafael Espindola | 5887356 | 2014-01-03 19:21:54 +0000 | [diff] [blame] | 145 | if (Triple.getArch() == Triple::x86_64) |
Michael J. Spencer | de3a211 | 2011-11-29 18:00:06 +0000 | [diff] [blame] | 146 | PrivateGlobalPrefix = ".L"; |
Michael J. Spencer | de3a211 | 2011-11-29 18:00:06 +0000 | [diff] [blame] | 147 | |
Michael J. Spencer | de3a211 | 2011-11-29 18:00:06 +0000 | [diff] [blame] | 148 | AssemblerDialect = AsmWriterFlavor; |
| 149 | |
| 150 | TextAlignFillValue = 0x90; |
Hans Wennborg | ce69d77 | 2013-10-18 20:46:28 +0000 | [diff] [blame] | 151 | |
| 152 | AllowAtInName = true; |
Daniel Sanders | 753e176 | 2014-02-13 14:44:26 +0000 | [diff] [blame] | 153 | |
| 154 | UseIntegratedAssembler = true; |
Michael J. Spencer | de3a211 | 2011-11-29 18:00:06 +0000 | [diff] [blame] | 155 | } |
| 156 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 157 | void X86MCAsmInfoGNUCOFF::anchor() { } |
| 158 | |
Michael J. Spencer | de3a211 | 2011-11-29 18:00:06 +0000 | [diff] [blame] | 159 | X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) { |
NAKAMURA Takumi | 3528934 | 2014-04-08 15:28:50 +0000 | [diff] [blame^] | 160 | if (Triple.getArch() == Triple::x86_64) { |
NAKAMURA Takumi | 547cc6f | 2010-12-07 02:43:45 +0000 | [diff] [blame] | 161 | PrivateGlobalPrefix = ".L"; |
NAKAMURA Takumi | 3528934 | 2014-04-08 15:28:50 +0000 | [diff] [blame^] | 162 | PointerSize = 8; |
| 163 | } |
Michael J. Spencer | 377aa20 | 2010-08-21 05:58:13 +0000 | [diff] [blame] | 164 | |
Chris Lattner | 1e9097e | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 165 | AssemblerDialect = AsmWriterFlavor; |
Daniel Dunbar | 68e22cb | 2010-02-25 18:07:10 +0000 | [diff] [blame] | 166 | |
| 167 | TextAlignFillValue = 0x90; |
NAKAMURA Takumi | b95f641 | 2012-04-07 02:24:20 +0000 | [diff] [blame] | 168 | |
| 169 | // Exceptions handling |
| 170 | ExceptionsType = ExceptionHandling::DwarfCFI; |
Daniel Sanders | 753e176 | 2014-02-13 14:44:26 +0000 | [diff] [blame] | 171 | |
| 172 | UseIntegratedAssembler = true; |
Benjamin Kramer | d7d8afa | 2010-02-16 10:25:04 +0000 | [diff] [blame] | 173 | } |