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