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> X86AsmSyntax( 27 "x86-asm-syntax", cl::init(ATT), cl::Hidden, 28 cl::desc("Select the assembly style for input"), 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 = X86AsmSyntax; 45 46 if (!is64Bit) 47 Data64bitsDirective = nullptr; // we can't emit a 64-bit unit 48 49 // Use ## as a comment string so that .s files generated by llvm can go 50 // through the GCC preprocessor without causing an error. This is needed 51 // because "clang foo.s" runs the C preprocessor, which is usually reserved 52 // for .S files on other systems. Perhaps this is because the file system 53 // wasn't always case preserving or something. 54 CommentString = "##"; 55 56 SupportsDebugInformation = true; 57 UseDataRegionDirectives = MarkedJTDataRegions; 58 59 // Exceptions handling 60 ExceptionsType = ExceptionHandling::DwarfCFI; 61 62 // old assembler lacks some directives 63 // FIXME: this should really be a check on the assembler characteristics 64 // rather than OS version 65 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6)) 66 HasWeakDefCanBeHiddenDirective = false; 67 68 // Assume ld64 is new enough that the abs-ified FDE relocs may be used 69 // (actually, must, since otherwise the non-extern relocations we produce 70 // overwhelm ld64's tiny little mind and it fails). 71 DwarfFDESymbolsUseAbsDiff = true; 72 } 73 74 X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple) 75 : X86MCAsmInfoDarwin(Triple) { 76 } 77 78 void X86ELFMCAsmInfo::anchor() { } 79 80 X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) { 81 bool is64Bit = T.getArch() == Triple::x86_64; 82 bool isX32 = T.isX32(); 83 84 // For ELF, x86-64 pointer size depends on the ABI. 85 // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64 86 // with the x32 ABI, pointer size remains the default 4. 87 CodePointerSize = (is64Bit && !isX32) ? 8 : 4; 88 89 // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI. 90 CalleeSaveStackSlotSize = is64Bit ? 8 : 4; 91 92 AssemblerDialect = X86AsmSyntax; 93 94 // Debug Information 95 SupportsDebugInformation = true; 96 97 // Exceptions handling 98 ExceptionsType = ExceptionHandling::DwarfCFI; 99 } 100 101 const MCExpr * 102 X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym, 103 unsigned Encoding, 104 MCStreamer &Streamer) const { 105 MCContext &Context = Streamer.getContext(); 106 const MCExpr *Res = 107 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context); 108 const MCExpr *Four = MCConstantExpr::create(4, Context); 109 return MCBinaryExpr::createAdd(Res, Four, Context); 110 } 111 112 void X86MCAsmInfoMicrosoft::anchor() { } 113 114 X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) { 115 if (Triple.getArch() == Triple::x86_64) { 116 PrivateGlobalPrefix = ".L"; 117 PrivateLabelPrefix = ".L"; 118 CodePointerSize = 8; 119 WinEHEncodingType = WinEH::EncodingType::Itanium; 120 } else { 121 // 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just 122 // a place holder that the Windows EHStreamer looks for to suppress CFI 123 // output. In particular, usesWindowsCFI() returns false. 124 WinEHEncodingType = WinEH::EncodingType::X86; 125 } 126 127 ExceptionsType = ExceptionHandling::WinEH; 128 129 AssemblerDialect = X86AsmSyntax; 130 131 AllowAtInName = true; 132 } 133 134 void X86MCAsmInfoMicrosoftMASM::anchor() { } 135 136 X86MCAsmInfoMicrosoftMASM::X86MCAsmInfoMicrosoftMASM(const Triple &Triple) 137 : X86MCAsmInfoMicrosoft(Triple) { 138 DollarIsPC = true; 139 SeparatorString = "\n"; 140 CommentString = ";"; 141 AllowAdditionalComments = false; 142 AllowQuestionAtStartOfIdentifier = true; 143 AllowDollarAtStartOfIdentifier = true; 144 AllowAtAtStartOfIdentifier = true; 145 } 146 147 void X86MCAsmInfoGNUCOFF::anchor() { } 148 149 X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) { 150 assert(Triple.isOSWindowsOrUEFI() && 151 "Windows and UEFI are the only supported COFF targets"); 152 if (Triple.getArch() == Triple::x86_64) { 153 PrivateGlobalPrefix = ".L"; 154 PrivateLabelPrefix = ".L"; 155 CodePointerSize = 8; 156 WinEHEncodingType = WinEH::EncodingType::Itanium; 157 ExceptionsType = ExceptionHandling::WinEH; 158 } else { 159 ExceptionsType = ExceptionHandling::DwarfCFI; 160 } 161 162 AssemblerDialect = X86AsmSyntax; 163 164 AllowAtInName = true; 165 } 166