Path: blob/main/contrib/llvm-project/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
35294 views
//===-- X86MCAsmInfo.cpp - X86 asm properties -----------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains the declarations of the X86MCAsmInfo properties.9//10//===----------------------------------------------------------------------===//1112#include "X86MCAsmInfo.h"13#include "llvm/MC/MCExpr.h"14#include "llvm/MC/MCStreamer.h"15#include "llvm/Support/CommandLine.h"16#include "llvm/TargetParser/Triple.h"17using namespace llvm;1819enum AsmWriterFlavorTy {20// Note: This numbering has to match the GCC assembler dialects for inline21// asm alternatives to work right.22ATT = 0, Intel = 123};2425static cl::opt<AsmWriterFlavorTy> AsmWriterFlavor(26"x86-asm-syntax", cl::init(ATT), cl::Hidden,27cl::desc("Choose style of code to emit from X86 backend:"),28cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"),29clEnumValN(Intel, "intel", "Emit Intel-style assembly")));3031static cl::opt<bool>32MarkedJTDataRegions("mark-data-regions", cl::init(true),33cl::desc("Mark code section jump table data regions."),34cl::Hidden);3536void X86MCAsmInfoDarwin::anchor() { }3738X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) {39bool is64Bit = T.getArch() == Triple::x86_64;40if (is64Bit)41CodePointerSize = CalleeSaveStackSlotSize = 8;4243AssemblerDialect = AsmWriterFlavor;4445TextAlignFillValue = 0x90;4647if (!is64Bit)48Data64bitsDirective = nullptr; // we can't emit a 64-bit unit4950// Use ## as a comment string so that .s files generated by llvm can go51// through the GCC preprocessor without causing an error. This is needed52// because "clang foo.s" runs the C preprocessor, which is usually reserved53// for .S files on other systems. Perhaps this is because the file system54// wasn't always case preserving or something.55CommentString = "##";5657SupportsDebugInformation = true;58UseDataRegionDirectives = MarkedJTDataRegions;5960// Exceptions handling61ExceptionsType = ExceptionHandling::DwarfCFI;6263// old assembler lacks some directives64// FIXME: this should really be a check on the assembler characteristics65// rather than OS version66if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6))67HasWeakDefCanBeHiddenDirective = false;6869// Assume ld64 is new enough that the abs-ified FDE relocs may be used70// (actually, must, since otherwise the non-extern relocations we produce71// overwhelm ld64's tiny little mind and it fails).72DwarfFDESymbolsUseAbsDiff = true;73}7475X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple)76: X86MCAsmInfoDarwin(Triple) {77}7879void X86ELFMCAsmInfo::anchor() { }8081X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {82bool is64Bit = T.getArch() == Triple::x86_64;83bool isX32 = T.isX32();8485// For ELF, x86-64 pointer size depends on the ABI.86// For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-6487// with the x32 ABI, pointer size remains the default 4.88CodePointerSize = (is64Bit && !isX32) ? 8 : 4;8990// OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI.91CalleeSaveStackSlotSize = is64Bit ? 8 : 4;9293AssemblerDialect = AsmWriterFlavor;9495TextAlignFillValue = 0x90;9697// Debug Information98SupportsDebugInformation = true;99100// Exceptions handling101ExceptionsType = ExceptionHandling::DwarfCFI;102}103104const MCExpr *105X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym,106unsigned Encoding,107MCStreamer &Streamer) const {108MCContext &Context = Streamer.getContext();109const MCExpr *Res =110MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context);111const MCExpr *Four = MCConstantExpr::create(4, Context);112return MCBinaryExpr::createAdd(Res, Four, Context);113}114115void X86MCAsmInfoMicrosoft::anchor() { }116117X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {118if (Triple.getArch() == Triple::x86_64) {119PrivateGlobalPrefix = ".L";120PrivateLabelPrefix = ".L";121CodePointerSize = 8;122WinEHEncodingType = WinEH::EncodingType::Itanium;123} else {124// 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just125// a place holder that the Windows EHStreamer looks for to suppress CFI126// output. In particular, usesWindowsCFI() returns false.127WinEHEncodingType = WinEH::EncodingType::X86;128}129130ExceptionsType = ExceptionHandling::WinEH;131132AssemblerDialect = AsmWriterFlavor;133134TextAlignFillValue = 0x90;135136AllowAtInName = true;137}138139void X86MCAsmInfoMicrosoftMASM::anchor() { }140141X86MCAsmInfoMicrosoftMASM::X86MCAsmInfoMicrosoftMASM(const Triple &Triple)142: X86MCAsmInfoMicrosoft(Triple) {143DollarIsPC = true;144SeparatorString = "\n";145CommentString = ";";146AllowAdditionalComments = false;147AllowQuestionAtStartOfIdentifier = true;148AllowDollarAtStartOfIdentifier = true;149AllowAtAtStartOfIdentifier = true;150}151152void X86MCAsmInfoGNUCOFF::anchor() { }153154X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {155assert((Triple.isOSWindows() || Triple.isUEFI()) &&156"Windows and UEFI are the only supported COFF targets");157if (Triple.getArch() == Triple::x86_64) {158PrivateGlobalPrefix = ".L";159PrivateLabelPrefix = ".L";160CodePointerSize = 8;161WinEHEncodingType = WinEH::EncodingType::Itanium;162ExceptionsType = ExceptionHandling::WinEH;163} else {164ExceptionsType = ExceptionHandling::DwarfCFI;165}166167AssemblerDialect = AsmWriterFlavor;168169TextAlignFillValue = 0x90;170171AllowAtInName = true;172}173174175