10b57cec5SDimitry Andric //===-- X86MCAsmInfo.cpp - X86 asm properties -----------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file contains the declarations of the X86MCAsmInfo properties.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric #include "X86MCAsmInfo.h"
140b57cec5SDimitry Andric #include "llvm/MC/MCExpr.h"
150b57cec5SDimitry Andric #include "llvm/MC/MCStreamer.h"
160b57cec5SDimitry Andric #include "llvm/Support/CommandLine.h"
17*06c3fb27SDimitry Andric #include "llvm/TargetParser/Triple.h"
180b57cec5SDimitry Andric using namespace llvm;
190b57cec5SDimitry Andric
200b57cec5SDimitry Andric enum AsmWriterFlavorTy {
210b57cec5SDimitry Andric // Note: This numbering has to match the GCC assembler dialects for inline
220b57cec5SDimitry Andric // asm alternatives to work right.
230b57cec5SDimitry Andric ATT = 0, Intel = 1
240b57cec5SDimitry Andric };
250b57cec5SDimitry Andric
260b57cec5SDimitry Andric static cl::opt<AsmWriterFlavorTy> AsmWriterFlavor(
270b57cec5SDimitry Andric "x86-asm-syntax", cl::init(ATT), cl::Hidden,
280b57cec5SDimitry Andric cl::desc("Choose style of code to emit from X86 backend:"),
290b57cec5SDimitry Andric cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"),
300b57cec5SDimitry Andric clEnumValN(Intel, "intel", "Emit Intel-style assembly")));
310b57cec5SDimitry Andric
320b57cec5SDimitry Andric static cl::opt<bool>
330b57cec5SDimitry Andric MarkedJTDataRegions("mark-data-regions", cl::init(true),
340b57cec5SDimitry Andric cl::desc("Mark code section jump table data regions."),
350b57cec5SDimitry Andric cl::Hidden);
360b57cec5SDimitry Andric
anchor()370b57cec5SDimitry Andric void X86MCAsmInfoDarwin::anchor() { }
380b57cec5SDimitry Andric
X86MCAsmInfoDarwin(const Triple & T)390b57cec5SDimitry Andric X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) {
400b57cec5SDimitry Andric bool is64Bit = T.getArch() == Triple::x86_64;
410b57cec5SDimitry Andric if (is64Bit)
420b57cec5SDimitry Andric CodePointerSize = CalleeSaveStackSlotSize = 8;
430b57cec5SDimitry Andric
440b57cec5SDimitry Andric AssemblerDialect = AsmWriterFlavor;
450b57cec5SDimitry Andric
460b57cec5SDimitry Andric TextAlignFillValue = 0x90;
470b57cec5SDimitry Andric
480b57cec5SDimitry Andric if (!is64Bit)
490b57cec5SDimitry Andric Data64bitsDirective = nullptr; // we can't emit a 64-bit unit
500b57cec5SDimitry Andric
510b57cec5SDimitry Andric // Use ## as a comment string so that .s files generated by llvm can go
520b57cec5SDimitry Andric // through the GCC preprocessor without causing an error. This is needed
530b57cec5SDimitry Andric // because "clang foo.s" runs the C preprocessor, which is usually reserved
540b57cec5SDimitry Andric // for .S files on other systems. Perhaps this is because the file system
550b57cec5SDimitry Andric // wasn't always case preserving or something.
560b57cec5SDimitry Andric CommentString = "##";
570b57cec5SDimitry Andric
580b57cec5SDimitry Andric SupportsDebugInformation = true;
590b57cec5SDimitry Andric UseDataRegionDirectives = MarkedJTDataRegions;
600b57cec5SDimitry Andric
610b57cec5SDimitry Andric // Exceptions handling
620b57cec5SDimitry Andric ExceptionsType = ExceptionHandling::DwarfCFI;
630b57cec5SDimitry Andric
640b57cec5SDimitry Andric // old assembler lacks some directives
650b57cec5SDimitry Andric // FIXME: this should really be a check on the assembler characteristics
660b57cec5SDimitry Andric // rather than OS version
670b57cec5SDimitry Andric if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6))
680b57cec5SDimitry Andric HasWeakDefCanBeHiddenDirective = false;
690b57cec5SDimitry Andric
700b57cec5SDimitry Andric // Assume ld64 is new enough that the abs-ified FDE relocs may be used
710b57cec5SDimitry Andric // (actually, must, since otherwise the non-extern relocations we produce
720b57cec5SDimitry Andric // overwhelm ld64's tiny little mind and it fails).
730b57cec5SDimitry Andric DwarfFDESymbolsUseAbsDiff = true;
740b57cec5SDimitry Andric }
750b57cec5SDimitry Andric
X86_64MCAsmInfoDarwin(const Triple & Triple)760b57cec5SDimitry Andric X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple)
770b57cec5SDimitry Andric : X86MCAsmInfoDarwin(Triple) {
780b57cec5SDimitry Andric }
790b57cec5SDimitry Andric
anchor()800b57cec5SDimitry Andric void X86ELFMCAsmInfo::anchor() { }
810b57cec5SDimitry Andric
X86ELFMCAsmInfo(const Triple & T)820b57cec5SDimitry Andric X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
830b57cec5SDimitry Andric bool is64Bit = T.getArch() == Triple::x86_64;
84fe6060f1SDimitry Andric bool isX32 = T.isX32();
850b57cec5SDimitry Andric
860b57cec5SDimitry Andric // For ELF, x86-64 pointer size depends on the ABI.
870b57cec5SDimitry Andric // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64
880b57cec5SDimitry Andric // with the x32 ABI, pointer size remains the default 4.
890b57cec5SDimitry Andric CodePointerSize = (is64Bit && !isX32) ? 8 : 4;
900b57cec5SDimitry Andric
910b57cec5SDimitry Andric // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI.
920b57cec5SDimitry Andric CalleeSaveStackSlotSize = is64Bit ? 8 : 4;
930b57cec5SDimitry Andric
940b57cec5SDimitry Andric AssemblerDialect = AsmWriterFlavor;
950b57cec5SDimitry Andric
960b57cec5SDimitry Andric TextAlignFillValue = 0x90;
970b57cec5SDimitry Andric
980b57cec5SDimitry Andric // Debug Information
990b57cec5SDimitry Andric SupportsDebugInformation = true;
1000b57cec5SDimitry Andric
1010b57cec5SDimitry Andric // Exceptions handling
1020b57cec5SDimitry Andric ExceptionsType = ExceptionHandling::DwarfCFI;
1030b57cec5SDimitry Andric }
1040b57cec5SDimitry Andric
1050b57cec5SDimitry Andric const MCExpr *
getExprForPersonalitySymbol(const MCSymbol * Sym,unsigned Encoding,MCStreamer & Streamer) const1060b57cec5SDimitry Andric X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym,
1070b57cec5SDimitry Andric unsigned Encoding,
1080b57cec5SDimitry Andric MCStreamer &Streamer) const {
1090b57cec5SDimitry Andric MCContext &Context = Streamer.getContext();
1100b57cec5SDimitry Andric const MCExpr *Res =
1110b57cec5SDimitry Andric MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context);
1120b57cec5SDimitry Andric const MCExpr *Four = MCConstantExpr::create(4, Context);
1130b57cec5SDimitry Andric return MCBinaryExpr::createAdd(Res, Four, Context);
1140b57cec5SDimitry Andric }
1150b57cec5SDimitry Andric
anchor()1160b57cec5SDimitry Andric void X86MCAsmInfoMicrosoft::anchor() { }
1170b57cec5SDimitry Andric
X86MCAsmInfoMicrosoft(const Triple & Triple)1180b57cec5SDimitry Andric X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
1190b57cec5SDimitry Andric if (Triple.getArch() == Triple::x86_64) {
1200b57cec5SDimitry Andric PrivateGlobalPrefix = ".L";
1210b57cec5SDimitry Andric PrivateLabelPrefix = ".L";
1220b57cec5SDimitry Andric CodePointerSize = 8;
1230b57cec5SDimitry Andric WinEHEncodingType = WinEH::EncodingType::Itanium;
1240b57cec5SDimitry Andric } else {
1250b57cec5SDimitry Andric // 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just
1260b57cec5SDimitry Andric // a place holder that the Windows EHStreamer looks for to suppress CFI
1270b57cec5SDimitry Andric // output. In particular, usesWindowsCFI() returns false.
1280b57cec5SDimitry Andric WinEHEncodingType = WinEH::EncodingType::X86;
1290b57cec5SDimitry Andric }
1300b57cec5SDimitry Andric
1310b57cec5SDimitry Andric ExceptionsType = ExceptionHandling::WinEH;
1320b57cec5SDimitry Andric
1330b57cec5SDimitry Andric AssemblerDialect = AsmWriterFlavor;
1340b57cec5SDimitry Andric
1350b57cec5SDimitry Andric TextAlignFillValue = 0x90;
1360b57cec5SDimitry Andric
1370b57cec5SDimitry Andric AllowAtInName = true;
1385ffd83dbSDimitry Andric }
1390b57cec5SDimitry Andric
anchor()1405ffd83dbSDimitry Andric void X86MCAsmInfoMicrosoftMASM::anchor() { }
1415ffd83dbSDimitry Andric
X86MCAsmInfoMicrosoftMASM(const Triple & Triple)1425ffd83dbSDimitry Andric X86MCAsmInfoMicrosoftMASM::X86MCAsmInfoMicrosoftMASM(const Triple &Triple)
1435ffd83dbSDimitry Andric : X86MCAsmInfoMicrosoft(Triple) {
1445ffd83dbSDimitry Andric DollarIsPC = true;
1455ffd83dbSDimitry Andric SeparatorString = "\n";
1465ffd83dbSDimitry Andric CommentString = ";";
147fe6060f1SDimitry Andric AllowAdditionalComments = false;
148fe6060f1SDimitry Andric AllowQuestionAtStartOfIdentifier = true;
149fe6060f1SDimitry Andric AllowDollarAtStartOfIdentifier = true;
150fe6060f1SDimitry Andric AllowAtAtStartOfIdentifier = true;
1510b57cec5SDimitry Andric }
1520b57cec5SDimitry Andric
anchor()1530b57cec5SDimitry Andric void X86MCAsmInfoGNUCOFF::anchor() { }
1540b57cec5SDimitry Andric
X86MCAsmInfoGNUCOFF(const Triple & Triple)1550b57cec5SDimitry Andric X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
156*06c3fb27SDimitry Andric assert((Triple.isOSWindows() || Triple.isUEFI()) &&
157*06c3fb27SDimitry Andric "Windows and UEFI are the only supported COFF targets");
1580b57cec5SDimitry Andric if (Triple.getArch() == Triple::x86_64) {
1590b57cec5SDimitry Andric PrivateGlobalPrefix = ".L";
1600b57cec5SDimitry Andric PrivateLabelPrefix = ".L";
1610b57cec5SDimitry Andric CodePointerSize = 8;
1620b57cec5SDimitry Andric WinEHEncodingType = WinEH::EncodingType::Itanium;
1630b57cec5SDimitry Andric ExceptionsType = ExceptionHandling::WinEH;
1640b57cec5SDimitry Andric } else {
1650b57cec5SDimitry Andric ExceptionsType = ExceptionHandling::DwarfCFI;
1660b57cec5SDimitry Andric }
1670b57cec5SDimitry Andric
1680b57cec5SDimitry Andric AssemblerDialect = AsmWriterFlavor;
1690b57cec5SDimitry Andric
1700b57cec5SDimitry Andric TextAlignFillValue = 0x90;
1710b57cec5SDimitry Andric
1728bcb0991SDimitry Andric AllowAtInName = true;
1730b57cec5SDimitry Andric }
174