1 //===-- X86MCAsmInfo.cpp - X86 asm properties -----------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file contains the declarations of the X86MCAsmInfo properties. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "X86MCAsmInfo.h" 14 #include "llvm/MC/MCExpr.h" 15 #include "llvm/MC/MCStreamer.h" 16 #include "llvm/Support/CommandLine.h" 17 #include "llvm/TargetParser/Triple.h" 18 using namespace llvm; 19 20 enum AsmWriterFlavorTy { 21 // Note: This numbering has to match the GCC assembler dialects for inline 22 // asm alternatives to work right. 23 ATT = 0, Intel = 1 24 }; 25 26 static cl::opt<AsmWriterFlavorTy> AsmWriterFlavor( 27 "x86-asm-syntax", cl::init(ATT), cl::Hidden, 28 cl::desc("Choose style of code to emit from X86 backend:"), 29 cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"), 30 clEnumValN(Intel, "intel", "Emit Intel-style assembly"))); 31 32 static cl::opt<bool> 33 MarkedJTDataRegions("mark-data-regions", cl::init(true), 34 cl::desc("Mark code section jump table data regions."), 35 cl::Hidden); 36 37 void X86MCAsmInfoDarwin::anchor() { } 38 39 X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) { 40 bool is64Bit = T.getArch() == Triple::x86_64; 41 if (is64Bit) 42 CodePointerSize = CalleeSaveStackSlotSize = 8; 43 44 AssemblerDialect = AsmWriterFlavor; 45 46 TextAlignFillValue = 0x90; 47 48 if (!is64Bit) 49 Data64bitsDirective = nullptr; // we can't emit a 64-bit unit 50 51 // Use ## as a comment string so that .s files generated by llvm can go 52 // through the GCC preprocessor without causing an error. This is needed 53 // because "clang foo.s" runs the C preprocessor, which is usually reserved 54 // for .S files on other systems. Perhaps this is because the file system 55 // wasn't always case preserving or something. 56 CommentString = "##"; 57 58 SupportsDebugInformation = true; 59 UseDataRegionDirectives = MarkedJTDataRegions; 60 61 // Exceptions handling 62 ExceptionsType = ExceptionHandling::DwarfCFI; 63 64 // old assembler lacks some directives 65 // FIXME: this should really be a check on the assembler characteristics 66 // rather than OS version 67 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6)) 68 HasWeakDefCanBeHiddenDirective = false; 69 70 // Assume ld64 is new enough that the abs-ified FDE relocs may be used 71 // (actually, must, since otherwise the non-extern relocations we produce 72 // overwhelm ld64's tiny little mind and it fails). 73 DwarfFDESymbolsUseAbsDiff = true; 74 } 75 76 X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple) 77 : X86MCAsmInfoDarwin(Triple) { 78 } 79 80 void X86ELFMCAsmInfo::anchor() { } 81 82 X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) { 83 bool is64Bit = T.getArch() == Triple::x86_64; 84 bool isX32 = T.isX32(); 85 86 // For ELF, x86-64 pointer size depends on the ABI. 87 // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64 88 // with the x32 ABI, pointer size remains the default 4. 89 CodePointerSize = (is64Bit && !isX32) ? 8 : 4; 90 91 // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI. 92 CalleeSaveStackSlotSize = is64Bit ? 8 : 4; 93 94 AssemblerDialect = AsmWriterFlavor; 95 96 TextAlignFillValue = 0x90; 97 98 // Debug Information 99 SupportsDebugInformation = true; 100 101 // Exceptions handling 102 ExceptionsType = ExceptionHandling::DwarfCFI; 103 } 104 105 const MCExpr * 106 X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym, 107 unsigned Encoding, 108 MCStreamer &Streamer) const { 109 MCContext &Context = Streamer.getContext(); 110 const MCExpr *Res = 111 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context); 112 const MCExpr *Four = MCConstantExpr::create(4, Context); 113 return MCBinaryExpr::createAdd(Res, Four, Context); 114 } 115 116 void X86MCAsmInfoMicrosoft::anchor() { } 117 118 X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) { 119 if (Triple.getArch() == Triple::x86_64) { 120 PrivateGlobalPrefix = ".L"; 121 PrivateLabelPrefix = ".L"; 122 CodePointerSize = 8; 123 WinEHEncodingType = WinEH::EncodingType::Itanium; 124 } else { 125 // 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just 126 // a place holder that the Windows EHStreamer looks for to suppress CFI 127 // output. In particular, usesWindowsCFI() returns false. 128 WinEHEncodingType = WinEH::EncodingType::X86; 129 } 130 131 ExceptionsType = ExceptionHandling::WinEH; 132 133 AssemblerDialect = AsmWriterFlavor; 134 135 TextAlignFillValue = 0x90; 136 137 AllowAtInName = true; 138 } 139 140 void X86MCAsmInfoMicrosoftMASM::anchor() { } 141 142 X86MCAsmInfoMicrosoftMASM::X86MCAsmInfoMicrosoftMASM(const Triple &Triple) 143 : X86MCAsmInfoMicrosoft(Triple) { 144 DollarIsPC = true; 145 SeparatorString = "\n"; 146 CommentString = ";"; 147 AllowAdditionalComments = false; 148 AllowQuestionAtStartOfIdentifier = true; 149 AllowDollarAtStartOfIdentifier = true; 150 AllowAtAtStartOfIdentifier = true; 151 } 152 153 void X86MCAsmInfoGNUCOFF::anchor() { } 154 155 X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) { 156 assert((Triple.isOSWindows() || Triple.isUEFI()) && 157 "Windows and UEFI are the only supported COFF targets"); 158 if (Triple.getArch() == Triple::x86_64) { 159 PrivateGlobalPrefix = ".L"; 160 PrivateLabelPrefix = ".L"; 161 CodePointerSize = 8; 162 WinEHEncodingType = WinEH::EncodingType::Itanium; 163 ExceptionsType = ExceptionHandling::WinEH; 164 } else { 165 ExceptionsType = ExceptionHandling::DwarfCFI; 166 } 167 168 AssemblerDialect = AsmWriterFlavor; 169 170 TextAlignFillValue = 0x90; 171 172 AllowAtInName = true; 173 } 174