| 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 "MCTargetDesc/X86MCExpr.h" |
| 15 | #include "llvm/MC/MCExpr.h" |
| 16 | #include "llvm/MC/MCStreamer.h" |
| 17 | #include "llvm/Support/CommandLine.h" |
| 18 | #include "llvm/TargetParser/Triple.h" |
| 19 | using namespace llvm; |
| 20 | |
| 21 | enum AsmWriterFlavorTy { |
| 22 | // Note: This numbering has to match the GCC assembler dialects for inline |
| 23 | // asm alternatives to work right. |
| 24 | ATT = 0, Intel = 1 |
| 25 | }; |
| 26 | |
| 27 | static cl::opt<AsmWriterFlavorTy> X86AsmSyntax( |
| 28 | "x86-asm-syntax" , cl::init(Val: ATT), cl::Hidden, |
| 29 | cl::desc("Select the assembly style for input" ), |
| 30 | cl::values(clEnumValN(ATT, "att" , "Emit AT&T-style assembly" ), |
| 31 | clEnumValN(Intel, "intel" , "Emit Intel-style assembly" ))); |
| 32 | |
| 33 | static cl::opt<bool> |
| 34 | MarkedJTDataRegions("mark-data-regions" , cl::init(Val: true), |
| 35 | cl::desc("Mark code section jump table data regions." ), |
| 36 | cl::Hidden); |
| 37 | |
| 38 | const MCAsmInfo::AtSpecifier atSpecifiers[] = { |
| 39 | {.Kind: X86::S_ABS8, .Name: "ABS8" }, |
| 40 | {.Kind: X86::S_DTPOFF, .Name: "DTPOFF" }, |
| 41 | {.Kind: X86::S_DTPREL, .Name: "DTPREL" }, |
| 42 | {.Kind: X86::S_GOT, .Name: "GOT" }, |
| 43 | {.Kind: X86::S_GOTENT, .Name: "GOTENT" }, |
| 44 | {.Kind: X86::S_GOTNTPOFF, .Name: "GOTNTPOFF" }, |
| 45 | {.Kind: X86::S_GOTOFF, .Name: "GOTOFF" }, |
| 46 | {.Kind: X86::S_GOTPCREL, .Name: "GOTPCREL" }, |
| 47 | {.Kind: X86::S_GOTPCREL_NORELAX, .Name: "GOTPCREL_NORELAX" }, |
| 48 | {.Kind: X86::S_GOTREL, .Name: "GOTREL" }, |
| 49 | {.Kind: X86::S_GOTTPOFF, .Name: "GOTTPOFF" }, |
| 50 | {.Kind: X86::S_INDNTPOFF, .Name: "INDNTPOFF" }, |
| 51 | {.Kind: MCSymbolRefExpr::VK_COFF_IMGREL32, .Name: "IMGREL" }, |
| 52 | {.Kind: X86::S_NTPOFF, .Name: "NTPOFF" }, |
| 53 | {.Kind: X86::S_PCREL, .Name: "PCREL" }, |
| 54 | {.Kind: X86::S_PLT, .Name: "PLT" }, |
| 55 | {.Kind: X86::S_PLTOFF, .Name: "PLTOFF" }, |
| 56 | {.Kind: X86::S_COFF_SECREL, .Name: "SECREL32" }, |
| 57 | {.Kind: X86::S_SIZE, .Name: "SIZE" }, |
| 58 | {.Kind: X86::S_TLSCALL, .Name: "tlscall" }, |
| 59 | {.Kind: X86::S_TLSDESC, .Name: "tlsdesc" }, |
| 60 | {.Kind: X86::S_TLSGD, .Name: "TLSGD" }, |
| 61 | {.Kind: X86::S_TLSLD, .Name: "TLSLD" }, |
| 62 | {.Kind: X86::S_TLSLDM, .Name: "TLSLDM" }, |
| 63 | {.Kind: X86::S_TLVP, .Name: "TLVP" }, |
| 64 | {.Kind: X86::S_TLVPPAGE, .Name: "TLVPPAGE" }, |
| 65 | {.Kind: X86::S_TLVPPAGEOFF, .Name: "TLVPPAGEOFF" }, |
| 66 | {.Kind: X86::S_TPOFF, .Name: "TPOFF" }, |
| 67 | }; |
| 68 | |
| 69 | void X86MCAsmInfoDarwin::anchor() { } |
| 70 | |
| 71 | X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) { |
| 72 | bool is64Bit = T.getArch() == Triple::x86_64; |
| 73 | if (is64Bit) |
| 74 | CodePointerSize = CalleeSaveStackSlotSize = 8; |
| 75 | |
| 76 | AssemblerDialect = X86AsmSyntax; |
| 77 | |
| 78 | if (!is64Bit) |
| 79 | Data64bitsDirective = nullptr; // we can't emit a 64-bit unit |
| 80 | |
| 81 | // Use ## as a comment string so that .s files generated by llvm can go |
| 82 | // through the GCC preprocessor without causing an error. This is needed |
| 83 | // because "clang foo.s" runs the C preprocessor, which is usually reserved |
| 84 | // for .S files on other systems. Perhaps this is because the file system |
| 85 | // wasn't always case preserving or something. |
| 86 | CommentString = "##" ; |
| 87 | |
| 88 | SupportsDebugInformation = true; |
| 89 | UseDataRegionDirectives = MarkedJTDataRegions; |
| 90 | |
| 91 | // Exceptions handling |
| 92 | ExceptionsType = ExceptionHandling::DwarfCFI; |
| 93 | |
| 94 | // old assembler lacks some directives |
| 95 | // FIXME: this should really be a check on the assembler characteristics |
| 96 | // rather than OS version |
| 97 | if (T.isMacOSX() && T.isMacOSXVersionLT(Major: 10, Minor: 6)) |
| 98 | HasWeakDefCanBeHiddenDirective = false; |
| 99 | |
| 100 | // Assume ld64 is new enough that the abs-ified FDE relocs may be used |
| 101 | // (actually, must, since otherwise the non-extern relocations we produce |
| 102 | // overwhelm ld64's tiny little mind and it fails). |
| 103 | DwarfFDESymbolsUseAbsDiff = true; |
| 104 | |
| 105 | initializeAtSpecifiers(atSpecifiers); |
| 106 | } |
| 107 | |
| 108 | X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple) |
| 109 | : X86MCAsmInfoDarwin(Triple) { |
| 110 | } |
| 111 | |
| 112 | void X86ELFMCAsmInfo::anchor() { } |
| 113 | |
| 114 | X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) { |
| 115 | bool is64Bit = T.getArch() == Triple::x86_64; |
| 116 | bool isX32 = T.isX32(); |
| 117 | |
| 118 | // For ELF, x86-64 pointer size depends on the ABI. |
| 119 | // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64 |
| 120 | // with the x32 ABI, pointer size remains the default 4. |
| 121 | CodePointerSize = (is64Bit && !isX32) ? 8 : 4; |
| 122 | |
| 123 | // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI. |
| 124 | CalleeSaveStackSlotSize = is64Bit ? 8 : 4; |
| 125 | |
| 126 | AssemblerDialect = X86AsmSyntax; |
| 127 | |
| 128 | // Debug Information |
| 129 | SupportsDebugInformation = true; |
| 130 | |
| 131 | // Exceptions handling |
| 132 | ExceptionsType = ExceptionHandling::DwarfCFI; |
| 133 | |
| 134 | initializeAtSpecifiers(atSpecifiers); |
| 135 | } |
| 136 | |
| 137 | const MCExpr * |
| 138 | X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym, |
| 139 | unsigned Encoding, |
| 140 | MCStreamer &Streamer) const { |
| 141 | MCContext &Context = Streamer.getContext(); |
| 142 | const MCExpr *Res = MCSymbolRefExpr::create(Symbol: Sym, specifier: X86::S_GOTPCREL, Ctx&: Context); |
| 143 | const MCExpr *Four = MCConstantExpr::create(Value: 4, Ctx&: Context); |
| 144 | return MCBinaryExpr::createAdd(LHS: Res, RHS: Four, Ctx&: Context); |
| 145 | } |
| 146 | |
| 147 | void X86MCAsmInfoMicrosoft::anchor() { } |
| 148 | |
| 149 | X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) { |
| 150 | if (Triple.getArch() == Triple::x86_64) { |
| 151 | PrivateGlobalPrefix = ".L" ; |
| 152 | PrivateLabelPrefix = ".L" ; |
| 153 | CodePointerSize = 8; |
| 154 | WinEHEncodingType = WinEH::EncodingType::Itanium; |
| 155 | } else { |
| 156 | // 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just |
| 157 | // a place holder that the Windows EHStreamer looks for to suppress CFI |
| 158 | // output. In particular, usesWindowsCFI() returns false. |
| 159 | WinEHEncodingType = WinEH::EncodingType::X86; |
| 160 | } |
| 161 | |
| 162 | ExceptionsType = ExceptionHandling::WinEH; |
| 163 | |
| 164 | AssemblerDialect = X86AsmSyntax; |
| 165 | |
| 166 | AllowAtInName = true; |
| 167 | |
| 168 | initializeAtSpecifiers(atSpecifiers); |
| 169 | } |
| 170 | |
| 171 | void X86MCAsmInfoMicrosoftMASM::anchor() { } |
| 172 | |
| 173 | X86MCAsmInfoMicrosoftMASM::X86MCAsmInfoMicrosoftMASM(const Triple &Triple) |
| 174 | : X86MCAsmInfoMicrosoft(Triple) { |
| 175 | DollarIsPC = true; |
| 176 | SeparatorString = "\n" ; |
| 177 | CommentString = ";" ; |
| 178 | AllowAdditionalComments = false; |
| 179 | AllowQuestionAtStartOfIdentifier = true; |
| 180 | AllowDollarAtStartOfIdentifier = true; |
| 181 | AllowAtAtStartOfIdentifier = true; |
| 182 | } |
| 183 | |
| 184 | void X86MCAsmInfoGNUCOFF::anchor() { } |
| 185 | |
| 186 | X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) { |
| 187 | assert((Triple.isOSWindows() || Triple.isUEFI()) && |
| 188 | "Windows and UEFI are the only supported COFF targets" ); |
| 189 | if (Triple.getArch() == Triple::x86_64) { |
| 190 | PrivateGlobalPrefix = ".L" ; |
| 191 | PrivateLabelPrefix = ".L" ; |
| 192 | CodePointerSize = 8; |
| 193 | WinEHEncodingType = WinEH::EncodingType::Itanium; |
| 194 | ExceptionsType = ExceptionHandling::WinEH; |
| 195 | } else { |
| 196 | ExceptionsType = ExceptionHandling::DwarfCFI; |
| 197 | } |
| 198 | |
| 199 | AssemblerDialect = X86AsmSyntax; |
| 200 | |
| 201 | AllowAtInName = true; |
| 202 | |
| 203 | initializeAtSpecifiers(atSpecifiers); |
| 204 | } |
| 205 | |