LLVM 24.0.0git
X86MCAsmInfo.cpp
Go to the documentation of this file.
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
13#include "X86MCAsmInfo.h"
14#include "llvm/ADT/Enum.h"
15#include "llvm/MC/MCExpr.h"
16#include "llvm/MC/MCStreamer.h"
19using namespace llvm;
20
22 // Note: This numbering has to match the GCC assembler dialects for inline
23 // asm alternatives to work right.
24 ATT = 0, Intel = 1
25};
26
28 "x86-asm-syntax", cl::init(ATT), cl::Hidden,
29 cl::desc("Select the assembly style for input"),
30 cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"),
31 clEnumValN(Intel, "intel", "Emit Intel-style assembly")));
32
33static cl::opt<bool>
34MarkedJTDataRegions("mark-data-regions", cl::init(true),
35 cl::desc("Mark code section jump table data regions."),
37
39 {{"ABS8"}, X86::S_ABS8},
40 {{"DTPOFF"}, X86::S_DTPOFF},
41 {{"DTPREL"}, X86::S_DTPREL},
42 {{"GOT"}, X86::S_GOT},
43 {{"GOTENT"}, X86::S_GOTENT},
44 {{"GOTNTPOFF"}, X86::S_GOTNTPOFF},
45 {{"GOTOFF"}, X86::S_GOTOFF},
46 {{"GOTPCREL"}, X86::S_GOTPCREL},
47 {{"GOTPCREL_NORELAX"}, X86::S_GOTPCREL_NORELAX},
48 {{"GOTREL"}, X86::S_GOTREL},
49 {{"GOTTPOFF"}, X86::S_GOTTPOFF},
50 {{"INDNTPOFF"}, X86::S_INDNTPOFF},
52 {{"NTPOFF"}, X86::S_NTPOFF},
53 {{"PCREL"}, X86::S_PCREL},
54 {{"PLT"}, X86::S_PLT},
55 {{"PLTOFF"}, X86::S_PLTOFF},
56 {{"SECREL32"}, X86::S_COFF_SECREL},
57 {{"SIZE"}, X86::S_SIZE},
58 {{"tlscall"}, X86::S_TLSCALL},
59 {{"tlsdesc"}, X86::S_TLSDESC},
60 {{"TLSGD"}, X86::S_TLSGD},
61 {{"TLSLD"}, X86::S_TLSLD},
62 {{"TLSLDM"}, X86::S_TLSLDM},
63 {{"TLVP"}, X86::S_TLVP},
64 {{"TLVPPAGE"}, X86::S_TLVPPAGE},
65 {{"TLVPPAGEOFF"}, X86::S_TLVPPAGEOFF},
66 {{"TPOFF"}, X86::S_TPOFF},
67};
69
70void X86MCAsmInfoDarwin::anchor() { }
71
75 bool is64Bit = T.isX86_64();
76 if (is64Bit)
78
80
81 if (!is64Bit)
82 Data64bitsDirective = nullptr; // we can't emit a 64-bit unit
83
84 // Use ## as a comment string so that .s files generated by llvm can go
85 // through the GCC preprocessor without causing an error. This is needed
86 // because "clang foo.s" runs the C preprocessor, which is usually reserved
87 // for .S files on other systems. Perhaps this is because the file system
88 // wasn't always case preserving or something.
89 CommentString = "##";
90
93
94 // Exceptions handling
96
97 // old assembler lacks some directives
98 // FIXME: this should really be a check on the assembler characteristics
99 // rather than OS version
100 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6))
102
103 // Assume ld64 is new enough that the abs-ified FDE relocs may be used
104 // (actually, must, since otherwise the non-extern relocations we produce
105 // overwhelm ld64's tiny little mind and it fails).
107
109}
110
114
115void X86ELFMCAsmInfo::anchor() { }
116
120 bool is64Bit = T.isX86_64();
121 bool isX32 = T.isX32();
122
123 // For ELF, x86-64 pointer size depends on the ABI.
124 // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64
125 // with the x32 ABI, pointer size remains the default 4.
126 CodePointerSize = (is64Bit && !isX32) ? 8 : 4;
127
128 // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI.
130
132
133 // Debug Information
135
136 // Exceptions handling
138
140}
141
142const MCExpr *
144 unsigned Encoding,
145 MCStreamer &Streamer) const {
146 MCContext &Context = Streamer.getContext();
147 const MCExpr *Res = MCSymbolRefExpr::create(Sym, X86::S_GOTPCREL, Context);
148 const MCExpr *Four = MCConstantExpr::create(4, Context);
149 return MCBinaryExpr::createAdd(Res, Four, Context);
150}
151
152void X86MCAsmInfoMicrosoft::anchor() { }
153
157 if (Triple.isX86_64()) {
158 InternalSymbolPrefix = ".L";
159 CodePointerSize = 8;
160 WinEHEncodingType = WinEH::EncodingType::Itanium;
161 } else {
162 // 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just
163 // a place holder that the Windows EHStreamer looks for to suppress CFI
164 // output. In particular, usesWindowsCFI() returns false.
165 WinEHEncodingType = WinEH::EncodingType::X86;
166 }
167
169
171
172 AllowAtInName = true;
173
175}
176
177void X86MCAsmInfoMicrosoftMASM::anchor() { }
178
190
191void X86MCAsmInfoGNUCOFF::anchor() { }
192
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
constexpr EnumStringDef< MCAsmInfo::AtSpecifierKind > AtSpecifierDefs[]
constexpr auto atSpecifiers
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
#define BUILD_ENUM_STRINGS(Tab)
Definition Enum.h:120
static LVOptions Options
Definition LVOptions.cpp:25
#define T
static bool is64Bit(const char *name)
static cl::opt< bool > MarkedJTDataRegions("mark-data-regions", cl::init(true), cl::desc("Mark code section jump table data regions."), cl::Hidden)
AsmWriterFlavorTy
@ Intel
@ ATT
static cl::opt< AsmWriterFlavorTy > X86AsmSyntax("x86-asm-syntax", cl::init(ATT), cl::Hidden, cl::desc("Select the assembly style for input"), cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"), clEnumValN(Intel, "intel", "Emit Intel-style assembly")))
MCAsmInfoDarwin(const MCTargetOptions &Options)
MCAsmInfoELF(const MCTargetOptions &Options)
MCAsmInfoGNUCOFF(const MCTargetOptions &Options)
MCAsmInfoMicrosoft(const MCTargetOptions &Options)
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:159
bool AllowAdditionalComments
This indicates whether to allow additional "comment strings" to be lexed as a comment.
Definition MCAsmInfo.h:142
bool AllowQuestionAtStartOfIdentifier
This is true if the assembler allows the "?" character at the start of of a string to be lexed as an ...
Definition MCAsmInfo.h:184
const char * Data64bitsDirective
Definition MCAsmInfo.h:245
bool DollarIsPC
The '$' token, when not referencing an identifier or constant, refers to the current PC.
Definition MCAsmInfo.h:126
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition MCAsmInfo.h:357
bool AllowDollarAtStartOfIdentifier
This is true if the assembler allows the "$" character at the start of of a string to be lexed as an ...
Definition MCAsmInfo.h:191
bool DwarfFDESymbolsUseAbsDiff
True if DWARF FDE symbol reference relocations should be replaced by an absolute difference.
Definition MCAsmInfo.h:372
bool AllowAtAtStartOfIdentifier
This is true if the assembler allows the "@" character at the start of a string to be lexed as an Asm...
Definition MCAsmInfo.h:198
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition MCAsmInfo.h:364
bool AllowAtInName
This is true if the assembler allows @ characters in symbol names.
Definition MCAsmInfo.h:177
bool HasWeakDefCanBeHiddenDirective
True if we have a directive to declare a global as being a weak defined symbol that can be hidden (un...
Definition MCAsmInfo.h:327
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition MCAsmInfo.h:354
unsigned AssemblerDialect
Which dialect of an assembler variant to use. Defaults to 0.
Definition MCAsmInfo.h:173
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line.
Definition MCAsmInfo.h:130
void initializeAtSpecifiers(EnumStrings< AtSpecifierKind, 1 >)
bool UseDataRegionDirectives
This is true if data region markers should be printed as ".data_region/.end_data_region" directives.
Definition MCAsmInfo.h:207
unsigned CodePointerSize
Code pointer size in bytes. Default is 4.
Definition MCAsmInfo.h:86
unsigned CalleeSaveStackSlotSize
Size of the stack slot reserved for callee-saved registers, in bytes.
Definition MCAsmInfo.h:90
StringRef CommentString
This indicates the comment string used by the assembler.
Definition MCAsmInfo.h:134
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:342
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Context object for machine code objects.
Definition MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Streaming machine code generation interface.
Definition MCStreamer.h:222
MCContext & getContext() const
Definition MCStreamer.h:326
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:213
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
bool isX86_64() const
Tests whether the target is x86 (64-bit).
Definition Triple.h:1203
bool isOSWindowsOrUEFI() const
Tests whether the OS is Windows or UEFI.
Definition Triple.h:781
X86ELFMCAsmInfo(const Triple &Triple, const MCTargetOptions &Options)
X86MCAsmInfoDarwin(const Triple &Triple, const MCTargetOptions &Options)
X86MCAsmInfoGNUCOFF(const Triple &Triple, const MCTargetOptions &Options)
X86MCAsmInfoMicrosoftMASM(const Triple &Triple, const MCTargetOptions &Options)
X86MCAsmInfoMicrosoft(const Triple &Triple, const MCTargetOptions &Options)
@ Itanium
Windows CE ARM, PowerPC, SH3, SH4.
Definition MCAsmInfo.h:52
@ S_GOTPCREL_NORELAX
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
@ DwarfCFI
DWARF-like instruction based exceptions.
Definition CodeGen.h:55
@ WinEH
Windows Exception Handling.
Definition CodeGen.h:58
Compile-time data representation of enum entries.
Definition Enum.h:47
const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const override
X86_64MCAsmInfoDarwin(const Triple &Triple, const MCTargetOptions &Options)