LLVM  4.0.0
MCAsmInfo.cpp
Go to the documentation of this file.
1 //===-- MCAsmInfo.cpp - Asm Info -------------------------------------------==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines target asm properties related what form asm statements
11 // should take.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCStreamer.h"
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/Support/Dwarf.h"
21 #include <cctype>
22 #include <cstring>
23 using namespace llvm;
24 
26  PointerSize = 4;
28 
29  IsLittleEndian = true;
30  StackGrowsUp = false;
33  HasMachoTBSSDirective = false;
34  MaxInstLength = 4;
35  MinInstAlignment = 1;
36  DollarIsPC = false;
37  SeparatorString = ";";
38  CommentString = "#";
39  LabelSuffix = ":";
41  NeedsLocalForSize = false;
42  PrivateGlobalPrefix = "L";
45  InlineAsmStart = "APP";
46  InlineAsmEnd = "NO_APP";
47  Code16Directive = ".code16";
48  Code32Directive = ".code32";
49  Code64Directive = ".code64";
50  AssemblerDialect = 0;
51  AllowAtInName = false;
52  SupportsQuotedNames = true;
54  ZeroDirective = "\t.zero\t";
55  AsciiDirective = "\t.ascii\t";
56  AscizDirective = "\t.asciz\t";
57  Data8bitsDirective = "\t.byte\t";
58  Data16bitsDirective = "\t.short\t";
59  Data32bitsDirective = "\t.long\t";
60  Data64bitsDirective = "\t.quad\t";
63  AlignmentIsInBytes = true;
65  GPRel64Directive = nullptr;
66  GPRel32Directive = nullptr;
67  GlobalDirective = "\t.globl\t";
72  HasFunctionAlignment = true;
75  HasIdentDirective = false;
76  HasNoDeadStrip = false;
77  HasAltEntry = false;
78  WeakDirective = "\t.weak\t";
79  WeakRefDirective = nullptr;
80  HasWeakDefDirective = false;
82  HasLinkOnceDirective = false;
91  DwarfRegNumForCFI = false;
94  UseLogicalShr = true;
95 
96  // FIXME: Clang's logic should be synced with the logic used to initialize
97  // this member and the two implementations should be merged.
98  // For reference:
99  // - Solaris always enables the integrated assembler by default
100  // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
101  // - Windows always enables the integrated assembler by default
102  // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
103  // - MachO targets always enables the integrated assembler by default
104  // - MCAsmInfoDarwin is handling this case
105  // - Generic_GCC toolchains enable the integrated assembler on a per
106  // architecture basis.
107  // - The target subclasses for AArch64, ARM, and X86 handle these cases
108  UseIntegratedAssembler = false;
109  PreserveAsmComments = true;
110 
112 }
113 
115 }
116 
118  return false;
119 }
120 
121 const MCExpr *
123  unsigned Encoding,
124  MCStreamer &Streamer) const {
125  return getExprForFDESymbol(Sym, Encoding, Streamer);
126 }
127 
128 const MCExpr *
130  unsigned Encoding,
131  MCStreamer &Streamer) const {
132  if (!(Encoding & dwarf::DW_EH_PE_pcrel))
133  return MCSymbolRefExpr::create(Sym, Streamer.getContext());
134 
135  MCContext &Context = Streamer.getContext();
136  const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
137  MCSymbol *PCSym = Context.createTempSymbol();
138  Streamer.EmitLabel(PCSym);
139  const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
140  return MCBinaryExpr::createSub(Res, PC, Context);
141 }
142 
143 static bool isAcceptableChar(char C) {
144  return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
145  (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
146 }
147 
149  if (Name.empty())
150  return false;
151 
152  // If any of the characters in the string is an unacceptable character, force
153  // quotes.
154  for (char C : Name) {
155  if (!isAcceptableChar(C))
156  return false;
157  }
158 
159  return true;
160 }
161 
163  // FIXME: Does .section .bss/.data/.text work everywhere??
164  return SectionName == ".text" || SectionName == ".data" ||
165  (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
166 }
bool HasSingleParameterDotFile
True if the target has a single parameter .file directive, this is true for ELF targets.
Definition: MCAsmInfo.h:274
const char * Code16Directive
These are assembly directives that tells the assembler to interpret the following instructions differ...
Definition: MCAsmInfo.h:140
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
Definition: MCAsmInfo.cpp:148
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:40
LCOMM::LCOMMType LCOMMDirectiveAlignmentType
Describes if the .lcomm directive for the target supports an alignment argument and how it is interpr...
Definition: MCAsmInfo.h:262
unsigned TextAlignFillValue
If non-zero, this is used to fill the executable space created as the result of a alignment directive...
Definition: MCAsmInfo.h:226
LLVMContext & Context
bool HasSubsectionsViaSymbols
True if this target has the MachO .subsections_via_symbols directive.
Definition: MCAsmInfo.h:78
bool UseIntegratedAssembler
Should we use the integrated assembler? The integrated assembler should be enabled by default (by the...
Definition: MCAsmInfo.h:358
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition: MCAsmInfo.h:124
const char * WeakDirective
Used to declare a global as being a weak symbol. Defaults to ".weak".
Definition: MCAsmInfo.h:289
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:298
bool DwarfRegNumForCFI
True if dwarf register numbers are printed instead of symbolic register names in .cfi_* directives.
Definition: MCAsmInfo.h:341
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
bool DwarfUsesRelocationsAcrossSections
True if Dwarf2 output generally uses relocations for references to other .debug_* sections...
Definition: MCAsmInfo.h:333
const char * Data64bitsDirective
Definition: MCAsmInfo.h:184
const char * ZeroDirective
This should be set to the directive used to get some number of zero bytes emitted to the current sect...
Definition: MCAsmInfo.h:166
bool SupportsQuotedNames
If this is true, symbol names with invalid characters will be printed in quotes.
Definition: MCAsmInfo.h:153
bool IsLittleEndian
True if target is little endian. Default is true.
Definition: MCAsmInfo.h:71
const char * GlobalDirective
This is the directive used to declare a global entity.
Definition: MCAsmInfo.h:232
unsigned CalleeSaveStackSlotSize
Size of the stack slot reserved for callee-saved registers, in bytes.
Definition: MCAsmInfo.h:68
unsigned AssemblerDialect
Which dialect of an assembler variant to use. Defaults to 0.
Definition: MCAsmInfo.h:145
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:301
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const
True if the section is atomized using the symbols in it.
Definition: MCAsmInfo.cpp:117
bool HasDotTypeDotSizeDirective
True if the target has .type and .size directives, this is true for most ELF targets.
Definition: MCAsmInfo.h:270
const char * AsciiDirective
This directive allows emission of an ascii string with the standard C escape characters embedded into...
Definition: MCAsmInfo.h:170
bool AlignmentIsInBytes
If this is true (the default) then the asmprinter emits ".align N" directives, where N is the number ...
Definition: MCAsmInfo.h:222
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line...
Definition: MCAsmInfo.h:102
bool HasNoDeadStrip
True if this target supports the MachO .no_dead_strip directive.
Definition: MCAsmInfo.h:282
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:122
bool UseLogicalShr
True if the integrated assembler should interpret 'a >> b' constant expressions as logical rather t...
Definition: MCAsmInfo.h:368
StringRef CommentString
This indicates the comment character used by the assembler.
Definition: MCAsmInfo.h:106
bool UsesELFSectionDirectiveForBSS
This is true if this target uses ELF '.section' directive before the '.bss' one.
Definition: MCAsmInfo.h:212
const char * Data8bitsDirective
These directives are used to output some unit of integer data to the current section.
Definition: MCAsmInfo.h:181
bool HasAggressiveSymbolFolding
False if the assembler requires that we use.
Definition: MCAsmInfo.h:254
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
bool StackGrowsUp
True if target stack grow up. Default is false.
Definition: MCAsmInfo.h:74
MCContext & getContext() const
Definition: MCStreamer.h:221
Context object for machine code objects.
Definition: MCContext.h:51
bool SunStyleELFSectionSwitchSyntax
This is true if this target uses "Sun Style" syntax for section switching ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in .section directives.
Definition: MCAsmInfo.h:207
bool HasFunctionAlignment
Definition: MCAsmInfo.h:266
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:497
MCSymbolAttr HiddenVisibilityAttr
This attribute, if not MCSA_Invalid, is used to declare a symbol as having hidden visibility...
Definition: MCAsmInfo.h:309
const char * Code32Directive
Definition: MCAsmInfo.h:141
bool HasLinkOnceDirective
True if we have a .linkonce directive.
Definition: MCAsmInfo.h:305
.protected (ELF)
Definition: MCDirectives.h:40
const char * AscizDirective
If not null, this allows for special handling of zero terminated strings on this target.
Definition: MCAsmInfo.h:175
virtual bool shouldOmitSectionDirective(StringRef SectionName) const
Return true if the .section directive should be omitted when emitting SectionName.
Definition: MCAsmInfo.cpp:162
bool DollarIsPC
The '$' token, when not referencing an identifier or constant, refers to the current PC...
Definition: MCAsmInfo.h:98
const char * InlineAsmStart
If these are nonempty, they contain a directive to emit before and after an inline assembly statement...
Definition: MCAsmInfo.h:134
.hidden (ELF)
Definition: MCDirectives.h:31
bool HasIdentDirective
True if the target has a .ident directive, this is true for ELF targets.
Definition: MCAsmInfo.h:278
Streaming machine code generation interface.
Definition: MCStreamer.h:161
const char * GPRel64Directive
If non-null, a directive that is used to emit a word which should be relocated as a 64-bit GP-relativ...
Definition: MCAsmInfo.h:189
bool COMMDirectiveAlignmentIsInBytes
True is .comm's and .lcomms optional alignment is to be specified in bytes instead of log2(n)...
Definition: MCAsmInfo.h:258
unsigned PointerSize
Pointer size in bytes. Default is 4.
Definition: MCAsmInfo.h:64
bool AllowAtInName
This is true if the assembler allows @ characters in symbol names.
Definition: MCAsmInfo.h:149
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition: MCAsmInfo.h:323
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition: MCAsmInfo.h:329
const char * WeakRefDirective
This directive, if non-null, is used to declare a global as being a weak undefined symbol...
Definition: MCAsmInfo.h:293
DebugCompressionType CompressDebugSections
Compress DWARF debug sections. Defaults to no compression.
Definition: MCAsmInfo.h:364
const char * Data16bitsDirective
Definition: MCAsmInfo.h:182
bool UseAssignmentForEHBegin
Definition: MCAsmInfo.h:112
bool HasWeakDefDirective
True if we have a directive to declare a global as being a weak defined symbol.
Definition: MCAsmInfo.h:297
bool usesELFSectionDirectiveForBSS() const
Definition: MCAsmInfo.h:450
bool NeedsLocalForSize
Definition: MCAsmInfo.h:115
bool HasAltEntry
True if this target supports the MachO .alt_entry directive.
Definition: MCAsmInfo.h:286
virtual void EmitLabel(MCSymbol *Symbol)
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:293
const char * LabelSuffix
This is appended to emitted labels. Defaults to ":".
Definition: MCAsmInfo.h:109
bool HasMachoZeroFillDirective
True if this is a MachO target that supports the macho-specific .zerofill directive for emitting BSS ...
Definition: MCAsmInfo.h:82
virtual ~MCAsmInfo()
Definition: MCAsmInfo.cpp:114
const char * InlineAsmEnd
Definition: MCAsmInfo.h:135
bool DwarfFDESymbolsUseAbsDiff
True if DWARF FDE symbol reference relocations should be replaced by an absolute difference.
Definition: MCAsmInfo.h:337
bool HasMachoTBSSDirective
True if this is a MachO target that supports the macho-specific .tbss directive for emitting thread l...
Definition: MCAsmInfo.h:86
unsigned MinInstAlignment
Every possible instruction length is a multiple of this value.
Definition: MCAsmInfo.h:94
const char * Data32bitsDirective
Definition: MCAsmInfo.h:183
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
const char * GPRel32Directive
If non-null, a directive that is used to emit a word which should be relocated as a 32-bit GP-relativ...
Definition: MCAsmInfo.h:194
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:130
bool PreserveAsmComments
Preserve Comments in assembly.
Definition: MCAsmInfo.h:361
MCSymbolAttr ProtectedVisibilityAttr
This attribute, if not MCSA_Invalid, is used to declare a symbol as having protected visibility...
Definition: MCAsmInfo.h:317
bool SetDirectiveSuppressesReloc
True if the expression .long f - g uses a relocation but it can be suppressed by writing a = f - g ...
Definition: MCAsmInfo.h:239
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition: MCAsmInfo.h:326
StringRef LinkerPrivateGlobalPrefix
This prefix is used for symbols that should be passed through the assembler but be removed by the lin...
Definition: MCAsmInfo.h:130
bool UseDataRegionDirectives
This is true if data region markers should be printed as ".data_region/.end_data_region" directives...
Definition: MCAsmInfo.h:158
const char SectionName[]
Definition: AMDGPUPTNote.h:24
static bool isAcceptableChar(char C)
Definition: MCAsmInfo.cpp:143
bool NeedsDwarfSectionOffsetDirective
Definition: MCAsmInfo.h:214
MCSymbolAttr HiddenDeclarationVisibilityAttr
This attribute, if not MCSA_Invalid, is used to declare an undefined symbol as having hidden visibili...
Definition: MCAsmInfo.h:313
virtual const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:129
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
StringRef PrivateGlobalPrefix
This prefix is used for globals like constant pool entries that are completely private to the ...
Definition: MCAsmInfo.h:120
const char * Code64Directive
Definition: MCAsmInfo.h:142
unsigned MaxInstLength
This is the maximum possible length of an instruction, which is needed to compute the size of an inli...
Definition: MCAsmInfo.h:90
bool UseParensForSymbolVariant
True if target uses parens to indicate the symbol variant instead of
Definition: MCAsmInfo.h:345
char * PC