LLVM API Documentation

X86MCAsmInfo.cpp
Go to the documentation of this file.
00001 //===-- X86MCAsmInfo.cpp - X86 asm properties -----------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains the declarations of the X86MCAsmInfo properties.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "X86MCAsmInfo.h"
00015 #include "llvm/ADT/Triple.h"
00016 #include "llvm/MC/MCContext.h"
00017 #include "llvm/MC/MCExpr.h"
00018 #include "llvm/MC/MCSectionELF.h"
00019 #include "llvm/MC/MCStreamer.h"
00020 #include "llvm/Support/CommandLine.h"
00021 #include "llvm/Support/ELF.h"
00022 using namespace llvm;
00023 
00024 enum AsmWriterFlavorTy {
00025   // Note: This numbering has to match the GCC assembler dialects for inline
00026   // asm alternatives to work right.
00027   ATT = 0, Intel = 1
00028 };
00029 
00030 static cl::opt<AsmWriterFlavorTy>
00031 AsmWriterFlavor("x86-asm-syntax", cl::init(ATT),
00032   cl::desc("Choose style of code to emit from X86 backend:"),
00033   cl::values(clEnumValN(ATT,   "att",   "Emit AT&T-style assembly"),
00034              clEnumValN(Intel, "intel", "Emit Intel-style assembly"),
00035              clEnumValEnd));
00036 
00037 static cl::opt<bool>
00038 MarkedJTDataRegions("mark-data-regions", cl::init(false),
00039   cl::desc("Mark code section jump table data regions."),
00040   cl::Hidden);
00041 
00042 void X86MCAsmInfoDarwin::anchor() { }
00043 
00044 X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) {
00045   bool is64Bit = T.getArch() == Triple::x86_64;
00046   if (is64Bit)
00047     PointerSize = CalleeSaveStackSlotSize = 8;
00048 
00049   AssemblerDialect = AsmWriterFlavor;
00050 
00051   TextAlignFillValue = 0x90;
00052 
00053   if (!is64Bit)
00054     Data64bitsDirective = nullptr;       // we can't emit a 64-bit unit
00055 
00056   // Use ## as a comment string so that .s files generated by llvm can go
00057   // through the GCC preprocessor without causing an error.  This is needed
00058   // because "clang foo.s" runs the C preprocessor, which is usually reserved
00059   // for .S files on other systems.  Perhaps this is because the file system
00060   // wasn't always case preserving or something.
00061   CommentString = "##";
00062 
00063   SupportsDebugInformation = true;
00064   UseDataRegionDirectives = MarkedJTDataRegions;
00065 
00066   // Exceptions handling
00067   ExceptionsType = ExceptionHandling::DwarfCFI;
00068 
00069   // old assembler lacks some directives
00070   // FIXME: this should really be a check on the assembler characteristics
00071   // rather than OS version
00072   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6))
00073     HasWeakDefCanBeHiddenDirective = false;
00074 
00075   // Assume ld64 is new enough that the abs-ified FDE relocs may be used
00076   // (actually, must, since otherwise the non-extern relocations we produce
00077   // overwhelm ld64's tiny little mind and it fails).
00078   DwarfFDESymbolsUseAbsDiff = true;
00079 
00080   UseIntegratedAssembler = true;
00081 }
00082 
00083 X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple)
00084   : X86MCAsmInfoDarwin(Triple) {
00085 }
00086 
00087 void X86ELFMCAsmInfo::anchor() { }
00088 
00089 X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
00090   bool is64Bit = T.getArch() == Triple::x86_64;
00091   bool isX32 = T.getEnvironment() == Triple::GNUX32;
00092 
00093   // For ELF, x86-64 pointer size depends on the ABI.
00094   // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64
00095   // with the x32 ABI, pointer size remains the default 4.
00096   PointerSize = (is64Bit && !isX32) ? 8 : 4;
00097 
00098   // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI.
00099   CalleeSaveStackSlotSize = is64Bit ? 8 : 4;
00100 
00101   AssemblerDialect = AsmWriterFlavor;
00102 
00103   TextAlignFillValue = 0x90;
00104 
00105   // Debug Information
00106   SupportsDebugInformation = true;
00107 
00108   // Exceptions handling
00109   ExceptionsType = ExceptionHandling::DwarfCFI;
00110 
00111   // OpenBSD and Bitrig have buggy support for .quad in 32-bit mode, just split
00112   // into two .words.
00113   if ((T.getOS() == Triple::OpenBSD || T.getOS() == Triple::Bitrig) &&
00114        T.getArch() == Triple::x86)
00115     Data64bitsDirective = nullptr;
00116 
00117   // Always enable the integrated assembler by default.
00118   // Clang also enabled it when the OS is Solaris but that is redundant here.
00119   UseIntegratedAssembler = true;
00120 }
00121 
00122 const MCExpr *
00123 X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym,
00124                                                    unsigned Encoding,
00125                                                    MCStreamer &Streamer) const {
00126   MCContext &Context = Streamer.getContext();
00127   const MCExpr *Res =
00128     MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context);
00129   const MCExpr *Four = MCConstantExpr::Create(4, Context);
00130   return MCBinaryExpr::CreateAdd(Res, Four, Context);
00131 }
00132 
00133 const MCSection *X86ELFMCAsmInfo::
00134 getNonexecutableStackSection(MCContext &Ctx) const {
00135   return Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS,
00136                            0, SectionKind::getMetadata());
00137 }
00138 
00139 void X86MCAsmInfoMicrosoft::anchor() { }
00140 
00141 X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
00142   if (Triple.getArch() == Triple::x86_64) {
00143     PrivateGlobalPrefix = ".L";
00144     PointerSize = 8;
00145     WinEHEncodingType = WinEH::EncodingType::Itanium;
00146     ExceptionsType = ExceptionHandling::WinEH;
00147   }
00148 
00149   AssemblerDialect = AsmWriterFlavor;
00150 
00151   TextAlignFillValue = 0x90;
00152 
00153   AllowAtInName = true;
00154 
00155   UseIntegratedAssembler = true;
00156 }
00157 
00158 void X86MCAsmInfoGNUCOFF::anchor() { }
00159 
00160 X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
00161   assert(Triple.isOSWindows() && "Windows is the only supported COFF target");
00162   if (Triple.getArch() == Triple::x86_64) {
00163     PrivateGlobalPrefix = ".L";
00164     PointerSize = 8;
00165     WinEHEncodingType = WinEH::EncodingType::Itanium;
00166     ExceptionsType = ExceptionHandling::WinEH;
00167   } else {
00168     ExceptionsType = ExceptionHandling::DwarfCFI;
00169   }
00170 
00171   AssemblerDialect = AsmWriterFlavor;
00172 
00173   TextAlignFillValue = 0x90;
00174 
00175   UseIntegratedAssembler = true;
00176 }