X86MCAsmInfo.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. #include "X86MCAsmInfo.h"
  13. #include "llvm/ADT/Triple.h"
  14. #include "llvm/MC/MCExpr.h"
  15. #include "llvm/MC/MCStreamer.h"
  16. #include "llvm/Support/CommandLine.h"
  17. using namespace llvm;
  18. enum AsmWriterFlavorTy {
  19. // Note: This numbering has to match the GCC assembler dialects for inline
  20. // asm alternatives to work right.
  21. ATT = 0, Intel = 1
  22. };
  23. static cl::opt<AsmWriterFlavorTy> AsmWriterFlavor(
  24. "x86-asm-syntax", cl::init(ATT), cl::Hidden,
  25. cl::desc("Choose style of code to emit from X86 backend:"),
  26. cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"),
  27. clEnumValN(Intel, "intel", "Emit Intel-style assembly")));
  28. static cl::opt<bool>
  29. MarkedJTDataRegions("mark-data-regions", cl::init(true),
  30. cl::desc("Mark code section jump table data regions."),
  31. cl::Hidden);
  32. void X86MCAsmInfoDarwin::anchor() { }
  33. X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) {
  34. bool is64Bit = T.getArch() == Triple::x86_64;
  35. if (is64Bit)
  36. CodePointerSize = CalleeSaveStackSlotSize = 8;
  37. AssemblerDialect = AsmWriterFlavor;
  38. TextAlignFillValue = 0x90;
  39. if (!is64Bit)
  40. Data64bitsDirective = nullptr; // we can't emit a 64-bit unit
  41. // Use ## as a comment string so that .s files generated by llvm can go
  42. // through the GCC preprocessor without causing an error. This is needed
  43. // because "clang foo.s" runs the C preprocessor, which is usually reserved
  44. // for .S files on other systems. Perhaps this is because the file system
  45. // wasn't always case preserving or something.
  46. CommentString = "##";
  47. SupportsDebugInformation = true;
  48. UseDataRegionDirectives = MarkedJTDataRegions;
  49. // Exceptions handling
  50. ExceptionsType = ExceptionHandling::DwarfCFI;
  51. // old assembler lacks some directives
  52. // FIXME: this should really be a check on the assembler characteristics
  53. // rather than OS version
  54. if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6))
  55. HasWeakDefCanBeHiddenDirective = false;
  56. // Assume ld64 is new enough that the abs-ified FDE relocs may be used
  57. // (actually, must, since otherwise the non-extern relocations we produce
  58. // overwhelm ld64's tiny little mind and it fails).
  59. DwarfFDESymbolsUseAbsDiff = true;
  60. }
  61. X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple)
  62. : X86MCAsmInfoDarwin(Triple) {
  63. }
  64. void X86ELFMCAsmInfo::anchor() { }
  65. X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
  66. bool is64Bit = T.getArch() == Triple::x86_64;
  67. bool isX32 = T.isX32();
  68. // For ELF, x86-64 pointer size depends on the ABI.
  69. // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64
  70. // with the x32 ABI, pointer size remains the default 4.
  71. CodePointerSize = (is64Bit && !isX32) ? 8 : 4;
  72. // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI.
  73. CalleeSaveStackSlotSize = is64Bit ? 8 : 4;
  74. AssemblerDialect = AsmWriterFlavor;
  75. TextAlignFillValue = 0x90;
  76. // Debug Information
  77. SupportsDebugInformation = true;
  78. // Exceptions handling
  79. ExceptionsType = ExceptionHandling::DwarfCFI;
  80. }
  81. const MCExpr *
  82. X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym,
  83. unsigned Encoding,
  84. MCStreamer &Streamer) const {
  85. MCContext &Context = Streamer.getContext();
  86. const MCExpr *Res =
  87. MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context);
  88. const MCExpr *Four = MCConstantExpr::create(4, Context);
  89. return MCBinaryExpr::createAdd(Res, Four, Context);
  90. }
  91. void X86MCAsmInfoMicrosoft::anchor() { }
  92. X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
  93. if (Triple.getArch() == Triple::x86_64) {
  94. PrivateGlobalPrefix = ".L";
  95. PrivateLabelPrefix = ".L";
  96. CodePointerSize = 8;
  97. WinEHEncodingType = WinEH::EncodingType::Itanium;
  98. } else {
  99. // 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just
  100. // a place holder that the Windows EHStreamer looks for to suppress CFI
  101. // output. In particular, usesWindowsCFI() returns false.
  102. WinEHEncodingType = WinEH::EncodingType::X86;
  103. }
  104. ExceptionsType = ExceptionHandling::WinEH;
  105. AssemblerDialect = AsmWriterFlavor;
  106. TextAlignFillValue = 0x90;
  107. AllowAtInName = true;
  108. }
  109. void X86MCAsmInfoMicrosoftMASM::anchor() { }
  110. X86MCAsmInfoMicrosoftMASM::X86MCAsmInfoMicrosoftMASM(const Triple &Triple)
  111. : X86MCAsmInfoMicrosoft(Triple) {
  112. DollarIsPC = true;
  113. SeparatorString = "\n";
  114. CommentString = ";";
  115. AllowAdditionalComments = false;
  116. AllowQuestionAtStartOfIdentifier = true;
  117. AllowDollarAtStartOfIdentifier = true;
  118. AllowAtAtStartOfIdentifier = true;
  119. }
  120. void X86MCAsmInfoGNUCOFF::anchor() { }
  121. X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
  122. assert(Triple.isOSWindows() && "Windows is the only supported COFF target");
  123. if (Triple.getArch() == Triple::x86_64) {
  124. PrivateGlobalPrefix = ".L";
  125. PrivateLabelPrefix = ".L";
  126. CodePointerSize = 8;
  127. WinEHEncodingType = WinEH::EncodingType::Itanium;
  128. ExceptionsType = ExceptionHandling::WinEH;
  129. } else {
  130. ExceptionsType = ExceptionHandling::DwarfCFI;
  131. }
  132. AssemblerDialect = AsmWriterFlavor;
  133. TextAlignFillValue = 0x90;
  134. AllowAtInName = true;
  135. }