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" |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +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"), |
Mehdi Amini | 732afdd | 2016-10-08 19:41:06 +0000 | [diff] [blame] | 34 | clEnumValN(Intel, "intel", "Emit Intel-style assembly"))); |
Chris Lattner | 1e9097e | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 35 | |
Jim Grosbach | 361ca34 | 2012-09-24 23:06:27 +0000 | [diff] [blame] | 36 | static cl::opt<bool> |
Tim Northover | d2ecbcc | 2016-05-03 21:03:41 +0000 | [diff] [blame] | 37 | MarkedJTDataRegions("mark-data-regions", cl::init(true), |
Jim Grosbach | 361ca34 | 2012-09-24 23:06:27 +0000 | [diff] [blame] | 38 | cl::desc("Mark code section jump table data regions."), |
| 39 | cl::Hidden); |
Chris Lattner | 1e9097e | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 40 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 41 | void X86MCAsmInfoDarwin::anchor() { } |
| 42 | |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 43 | X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) { |
| 44 | bool is64Bit = T.getArch() == Triple::x86_64; |
Evan Cheng | a83b37a | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 45 | if (is64Bit) |
Eli Bendersky | 0893e10 | 2013-01-22 18:02:49 +0000 | [diff] [blame] | 46 | PointerSize = CalleeSaveStackSlotSize = 8; |
Evan Cheng | a83b37a | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 47 | |
Chris Lattner | 1e9097e | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 48 | AssemblerDialect = AsmWriterFlavor; |
Eric Christopher | 719c297 | 2011-07-07 22:54:12 +0000 | [diff] [blame] | 49 | |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 50 | TextAlignFillValue = 0x90; |
Daniel Dunbar | 12368685 | 2009-07-24 08:24:36 +0000 | [diff] [blame] | 51 | |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 52 | if (!is64Bit) |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 53 | Data64bitsDirective = nullptr; // we can't emit a 64-bit unit |
Bill Wendling | 0a860df | 2009-07-13 18:48:39 +0000 | [diff] [blame] | 54 | |
Chris Lattner | d871667 | 2010-02-17 01:38:01 +0000 | [diff] [blame] | 55 | // 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] | 56 | // 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 Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 60 | CommentString = "##"; |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 61 | |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 62 | SupportsDebugInformation = true; |
Jim Grosbach | 361ca34 | 2012-09-24 23:06:27 +0000 | [diff] [blame] | 63 | UseDataRegionDirectives = MarkedJTDataRegions; |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 64 | |
| 65 | // Exceptions handling |
Rafael Espindola | fc82236 | 2011-05-01 15:44:13 +0000 | [diff] [blame] | 66 | ExceptionsType = ExceptionHandling::DwarfCFI; |
David Fang | 1b01849 | 2013-12-10 21:37:41 +0000 | [diff] [blame] | 67 | |
| 68 | // old assembler lacks some directives |
| 69 | // FIXME: this should really be a check on the assembler characteristics |
| 70 | // rather than OS version |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 71 | if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6)) |
David Fang | 1b01849 | 2013-12-10 21:37:41 +0000 | [diff] [blame] | 72 | HasWeakDefCanBeHiddenDirective = false; |
Iain Sandoe | 618def6 | 2014-01-08 10:22:54 +0000 | [diff] [blame] | 73 | |
Tim Northover | 0942e39 | 2014-07-22 15:47:09 +0000 | [diff] [blame] | 74 | // 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 Sanders | 753e176 | 2014-02-13 14:44:26 +0000 | [diff] [blame] | 78 | |
| 79 | UseIntegratedAssembler = true; |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 82 | X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple) |
| 83 | : X86MCAsmInfoDarwin(Triple) { |
| 84 | } |
Rafael Espindola | c5dac4d | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 85 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 86 | void X86ELFMCAsmInfo::anchor() { } |
| 87 | |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 88 | X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) { |
| 89 | bool is64Bit = T.getArch() == Triple::x86_64; |
| 90 | bool isX32 = T.getEnvironment() == Triple::GNUX32; |
Eli Bendersky | 0893e10 | 2013-01-22 18:02:49 +0000 | [diff] [blame] | 91 | |
| 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 Cheng | a83b37a | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 99 | |
Chris Lattner | 1e9097e | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 100 | AssemblerDialect = AsmWriterFlavor; |
Anton Korobeynikov | daee281 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 101 | |
Daniel Dunbar | 68e22cb | 2010-02-25 18:07:10 +0000 | [diff] [blame] | 102 | TextAlignFillValue = 0x90; |
| 103 | |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 104 | // Debug Information |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 105 | SupportsDebugInformation = true; |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 106 | |
| 107 | // Exceptions handling |
Rafael Espindola | a01cdb0 | 2011-04-15 15:11:06 +0000 | [diff] [blame] | 108 | ExceptionsType = ExceptionHandling::DwarfCFI; |
| 109 | |
Daniel Sanders | 753e176 | 2014-02-13 14:44:26 +0000 | [diff] [blame] | 110 | // 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 Lattner | 76bdea3 | 2010-01-23 07:21:06 +0000 | [diff] [blame] | 113 | } |
Anton Korobeynikov | 9a6ed37 | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 114 | |
Evan Cheng | a83b37a | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 115 | const MCExpr * |
| 116 | X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym, |
| 117 | unsigned Encoding, |
| 118 | MCStreamer &Streamer) const { |
| 119 | MCContext &Context = Streamer.getContext(); |
| 120 | const MCExpr *Res = |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 121 | MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context); |
| 122 | const MCExpr *Four = MCConstantExpr::create(4, Context); |
| 123 | return MCBinaryExpr::createAdd(Res, Four, Context); |
Evan Cheng | a83b37a | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 124 | } |
| 125 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 126 | void X86MCAsmInfoMicrosoft::anchor() { } |
| 127 | |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 128 | X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) { |
| 129 | if (Triple.getArch() == Triple::x86_64) { |
Michael J. Spencer | de3a211 | 2011-11-29 18:00:06 +0000 | [diff] [blame] | 130 | PrivateGlobalPrefix = ".L"; |
Matt Arsenault | 4e27343 | 2014-12-04 00:06:57 +0000 | [diff] [blame] | 131 | PrivateLabelPrefix = ".L"; |
NAKAMURA Takumi | 1db5995 | 2014-06-25 12:41:52 +0000 | [diff] [blame] | 132 | PointerSize = 8; |
Saleem Abdulrasool | d1a4ed6 | 2014-09-01 23:48:39 +0000 | [diff] [blame] | 133 | WinEHEncodingType = WinEH::EncodingType::Itanium; |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 134 | } 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 Takumi | 1db5995 | 2014-06-25 12:41:52 +0000 | [diff] [blame] | 139 | } |
Michael J. Spencer | de3a211 | 2011-11-29 18:00:06 +0000 | [diff] [blame] | 140 | |
Reid Kleckner | 0738a9c | 2015-05-05 17:44:16 +0000 | [diff] [blame] | 141 | ExceptionsType = ExceptionHandling::WinEH; |
| 142 | |
Michael J. Spencer | de3a211 | 2011-11-29 18:00:06 +0000 | [diff] [blame] | 143 | AssemblerDialect = AsmWriterFlavor; |
| 144 | |
| 145 | TextAlignFillValue = 0x90; |
Hans Wennborg | ce69d77 | 2013-10-18 20:46:28 +0000 | [diff] [blame] | 146 | |
| 147 | AllowAtInName = true; |
Daniel Sanders | 753e176 | 2014-02-13 14:44:26 +0000 | [diff] [blame] | 148 | |
| 149 | UseIntegratedAssembler = true; |
Michael J. Spencer | de3a211 | 2011-11-29 18:00:06 +0000 | [diff] [blame] | 150 | } |
| 151 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 152 | void X86MCAsmInfoGNUCOFF::anchor() { } |
| 153 | |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 154 | X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) { |
| 155 | assert(Triple.isOSWindows() && "Windows is the only supported COFF target"); |
| 156 | if (Triple.getArch() == Triple::x86_64) { |
NAKAMURA Takumi | 547cc6f | 2010-12-07 02:43:45 +0000 | [diff] [blame] | 157 | PrivateGlobalPrefix = ".L"; |
Matt Arsenault | 4e27343 | 2014-12-04 00:06:57 +0000 | [diff] [blame] | 158 | PrivateLabelPrefix = ".L"; |
NAKAMURA Takumi | 3528934 | 2014-04-08 15:28:50 +0000 | [diff] [blame] | 159 | PointerSize = 8; |
Saleem Abdulrasool | d1a4ed6 | 2014-09-01 23:48:39 +0000 | [diff] [blame] | 160 | WinEHEncodingType = WinEH::EncodingType::Itanium; |
Reid Kleckner | 5cc1569 | 2015-01-23 18:49:01 +0000 | [diff] [blame] | 161 | ExceptionsType = ExceptionHandling::WinEH; |
NAKAMURA Takumi | 1db5995 | 2014-06-25 12:41:52 +0000 | [diff] [blame] | 162 | } else { |
| 163 | ExceptionsType = ExceptionHandling::DwarfCFI; |
NAKAMURA Takumi | 3528934 | 2014-04-08 15:28:50 +0000 | [diff] [blame] | 164 | } |
Michael J. Spencer | 377aa20 | 2010-08-21 05:58:13 +0000 | [diff] [blame] | 165 | |
Chris Lattner | 1e9097e | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 166 | AssemblerDialect = AsmWriterFlavor; |
Daniel Dunbar | 68e22cb | 2010-02-25 18:07:10 +0000 | [diff] [blame] | 167 | |
| 168 | TextAlignFillValue = 0x90; |
NAKAMURA Takumi | b95f641 | 2012-04-07 02:24:20 +0000 | [diff] [blame] | 169 | |
Daniel Sanders | 753e176 | 2014-02-13 14:44:26 +0000 | [diff] [blame] | 170 | UseIntegratedAssembler = true; |
Benjamin Kramer | d7d8afa | 2010-02-16 10:25:04 +0000 | [diff] [blame] | 171 | } |