[LPM] Clean up the use of TLS in pretty stack trace and disable it
[oota-llvm.git] / include / llvm / MC / MCAsmInfo.h
1 //===-- llvm/MC/MCAsmInfo.h - Asm info --------------------------*- C++ -*-===//
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 contains a class to be used as the basis for target specific
11 // asm writers.  This class primarily takes care of global printing constants,
12 // which are used in very similar ways across all targets.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_MC_MCASMINFO_H
17 #define LLVM_MC_MCASMINFO_H
18
19 #include "llvm/MC/MCDirectives.h"
20 #include "llvm/MC/MCDwarf.h"
21 #include "llvm/MC/MachineLocation.h"
22 #include <cassert>
23 #include <vector>
24
25 namespace llvm {
26 class MCExpr;
27 class MCSection;
28 class MCStreamer;
29 class MCSymbol;
30 class MCContext;
31
32 namespace WinEH {
33 enum class EncodingType {
34   Invalid, /// Invalid
35   Alpha,   /// Windows Alpha
36   Alpha64, /// Windows AXP64
37   ARM,     /// Windows NT (Windows on ARM)
38   CE,      /// Windows CE ARM, PowerPC, SH3, SH4
39   Itanium, /// Windows x64, Windows Itanium (IA-64)
40   MIPS = Alpha,
41 };
42 }
43
44 enum class ExceptionHandling {
45   None,     /// No exception support
46   DwarfCFI, /// DWARF-like instruction based exceptions
47   SjLj,     /// setjmp/longjmp based exceptions
48   ARM,      /// ARM EHABI
49   WinEH,    /// Windows Exception Handling
50 };
51
52 namespace LCOMM {
53 enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
54 }
55
56 /// This class is intended to be used as a base class for asm
57 /// properties and features specific to the target.
58 class MCAsmInfo {
59 protected:
60   //===------------------------------------------------------------------===//
61   // Properties to be set by the target writer, used to configure asm printer.
62   //
63
64   /// Pointer size in bytes.  Default is 4.
65   unsigned PointerSize;
66
67   /// Size of the stack slot reserved for callee-saved registers, in bytes.
68   /// Default is same as pointer size.
69   unsigned CalleeSaveStackSlotSize;
70
71   /// True if target is little endian.  Default is true.
72   bool IsLittleEndian;
73
74   /// True if target stack grow up.  Default is false.
75   bool StackGrowsUp;
76
77   /// True if this target has the MachO .subsections_via_symbols directive.
78   /// Default is false.
79   bool HasSubsectionsViaSymbols;
80
81   /// True if this is a MachO target that supports the macho-specific .zerofill
82   /// directive for emitting BSS Symbols.  Default is false.
83   bool HasMachoZeroFillDirective;
84
85   /// True if this is a MachO target that supports the macho-specific .tbss
86   /// directive for emitting thread local BSS Symbols.  Default is false.
87   bool HasMachoTBSSDirective;
88
89   /// True if the compiler should emit a ".reference .constructors_used" or
90   /// ".reference .destructors_used" directive after the static ctor/dtor
91   /// list.  This directive is only emitted in Static relocation model.  Default
92   /// is false.
93   bool HasStaticCtorDtorReferenceInStaticMode;
94
95   /// This is the maximum possible length of an instruction, which is needed to
96   /// compute the size of an inline asm.  Defaults to 4.
97   unsigned MaxInstLength;
98
99   /// Every possible instruction length is a multiple of this value.  Factored
100   /// out in .debug_frame and .debug_line.  Defaults to 1.
101   unsigned MinInstAlignment;
102
103   /// The '$' token, when not referencing an identifier or constant, refers to
104   /// the current PC.  Defaults to false.
105   bool DollarIsPC;
106
107   /// This string, if specified, is used to separate instructions from each
108   /// other when on the same line.  Defaults to ';'
109   const char *SeparatorString;
110
111   /// This indicates the comment character used by the assembler.  Defaults to
112   /// "#"
113   const char *CommentString;
114
115   /// This is appended to emitted labels.  Defaults to ":"
116   const char *LabelSuffix;
117
118   // Print the EH begin symbol with an assignment. Defaults to false.
119   bool UseAssignmentForEHBegin;
120
121   /// This prefix is used for globals like constant pool entries that are
122   /// completely private to the .s file and should not have names in the .o
123   /// file.  Defaults to "L"
124   const char *PrivateGlobalPrefix;
125
126   /// This prefix is used for labels for basic blocks. Defaults to the same as
127   /// PrivateGlobalPrefix.
128   const char *PrivateLabelPrefix;
129
130   /// This prefix is used for symbols that should be passed through the
131   /// assembler but be removed by the linker.  This is 'l' on Darwin, currently
132   /// used for some ObjC metadata.  The default of "" meast that for this system
133   /// a plain private symbol should be used.  Defaults to "".
134   const char *LinkerPrivateGlobalPrefix;
135
136   /// If these are nonempty, they contain a directive to emit before and after
137   /// an inline assembly statement.  Defaults to "#APP\n", "#NO_APP\n"
138   const char *InlineAsmStart;
139   const char *InlineAsmEnd;
140
141   /// These are assembly directives that tells the assembler to interpret the
142   /// following instructions differently.  Defaults to ".code16", ".code32",
143   /// ".code64".
144   const char *Code16Directive;
145   const char *Code32Directive;
146   const char *Code64Directive;
147
148   /// Which dialect of an assembler variant to use.  Defaults to 0
149   unsigned AssemblerDialect;
150
151   /// This is true if the assembler allows @ characters in symbol names.
152   /// Defaults to false.
153   bool AllowAtInName;
154
155   /// This is true if data region markers should be printed as
156   /// ".data_region/.end_data_region" directives. If false, use "$d/$a" labels
157   /// instead.
158   bool UseDataRegionDirectives;
159
160   //===--- Data Emission Directives -------------------------------------===//
161
162   /// This should be set to the directive used to get some number of zero bytes
163   /// emitted to the current section.  Common cases are "\t.zero\t" and
164   /// "\t.space\t".  If this is set to null, the Data*bitsDirective's will be
165   /// used to emit zero bytes.  Defaults to "\t.zero\t"
166   const char *ZeroDirective;
167
168   /// This directive allows emission of an ascii string with the standard C
169   /// escape characters embedded into it.  Defaults to "\t.ascii\t"
170   const char *AsciiDirective;
171
172   /// If not null, this allows for special handling of zero terminated strings
173   /// on this target.  This is commonly supported as ".asciz".  If a target
174   /// doesn't support this, it can be set to null.  Defaults to "\t.asciz\t"
175   const char *AscizDirective;
176
177   /// These directives are used to output some unit of integer data to the
178   /// current section.  If a data directive is set to null, smaller data
179   /// directives will be used to emit the large sizes.  Defaults to "\t.byte\t",
180   /// "\t.short\t", "\t.long\t", "\t.quad\t"
181   const char *Data8bitsDirective;
182   const char *Data16bitsDirective;
183   const char *Data32bitsDirective;
184   const char *Data64bitsDirective;
185
186   /// If non-null, a directive that is used to emit a word which should be
187   /// relocated as a 64-bit GP-relative offset, e.g. .gpdword on Mips.  Defaults
188   /// to NULL.
189   const char *GPRel64Directive;
190
191   /// If non-null, a directive that is used to emit a word which should be
192   /// relocated as a 32-bit GP-relative offset, e.g. .gpword on Mips or .gprel32
193   /// on Alpha.  Defaults to NULL.
194   const char *GPRel32Directive;
195
196   /// This is true if this target uses "Sun Style" syntax for section switching
197   /// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in
198   /// .section directives.  Defaults to false.
199   bool SunStyleELFSectionSwitchSyntax;
200
201   /// This is true if this target uses ELF '.section' directive before the
202   /// '.bss' one. It's used for PPC/Linux which doesn't support the '.bss'
203   /// directive only.  Defaults to false.
204   bool UsesELFSectionDirectiveForBSS;
205
206   bool NeedsDwarfSectionOffsetDirective;
207
208   //===--- Alignment Information ----------------------------------------===//
209
210   /// If this is true (the default) then the asmprinter emits ".align N"
211   /// directives, where N is the number of bytes to align to.  Otherwise, it
212   /// emits ".align log2(N)", e.g. 3 to align to an 8 byte boundary.  Defaults
213   /// to true.
214   bool AlignmentIsInBytes;
215
216   /// If non-zero, this is used to fill the executable space created as the
217   /// result of a alignment directive.  Defaults to 0
218   unsigned TextAlignFillValue;
219
220   //===--- Global Variable Emission Directives --------------------------===//
221
222   /// This is the directive used to declare a global entity. Defaults to
223   /// ".globl".
224   const char *GlobalDirective;
225
226   /// True if the expression
227   ///   .long f - g
228   /// uses an relocation but it can be supressed by writting
229   ///   a = f - g
230   ///   .long a
231   bool SetDirectiveSuppressesReloc;
232
233   /// False if the assembler requires that we use
234   /// \code
235   ///   Lc = a - b
236   ///   .long Lc
237   /// \endcode
238   //
239   /// instead of
240   //
241   /// \code
242   ///   .long a - b
243   /// \endcode
244   ///
245   ///  Defaults to true.
246   bool HasAggressiveSymbolFolding;
247
248   /// True is .comm's and .lcomms optional alignment is to be specified in bytes
249   /// instead of log2(n).  Defaults to true.
250   bool COMMDirectiveAlignmentIsInBytes;
251
252   /// Describes if the .lcomm directive for the target supports an alignment
253   /// argument and how it is interpreted.  Defaults to NoAlignment.
254   LCOMM::LCOMMType LCOMMDirectiveAlignmentType;
255
256   /// True if the target has .type and .size directives, this is true for most
257   /// ELF targets.  Defaults to true.
258   bool HasDotTypeDotSizeDirective;
259
260   /// True if the target has a single parameter .file directive, this is true
261   /// for ELF targets.  Defaults to true.
262   bool HasSingleParameterDotFile;
263
264   /// True if the target has a .ident directive, this is true for ELF targets.
265   /// Defaults to false.
266   bool HasIdentDirective;
267
268   /// True if this target supports the MachO .no_dead_strip directive.  Defaults
269   /// to false.
270   bool HasNoDeadStrip;
271
272   /// Used to declare a global as being a weak symbol. Defaults to ".weak".
273   const char *WeakDirective;
274
275   /// This directive, if non-null, is used to declare a global as being a weak
276   /// undefined symbol.  Defaults to NULL.
277   const char *WeakRefDirective;
278
279   /// True if we have a directive to declare a global as being a weak defined
280   /// symbol.  Defaults to false.
281   bool HasWeakDefDirective;
282
283   /// True if we have a directive to declare a global as being a weak defined
284   /// symbol that can be hidden (unexported).  Defaults to false.
285   bool HasWeakDefCanBeHiddenDirective;
286
287   /// True if we have a .linkonce directive.  This is used on cygwin/mingw.
288   /// Defaults to false.
289   bool HasLinkOnceDirective;
290
291   /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
292   /// hidden visibility.  Defaults to MCSA_Hidden.
293   MCSymbolAttr HiddenVisibilityAttr;
294
295   /// This attribute, if not MCSA_Invalid, is used to declare an undefined
296   /// symbol as having hidden visibility. Defaults to MCSA_Hidden.
297   MCSymbolAttr HiddenDeclarationVisibilityAttr;
298
299   /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
300   /// protected visibility.  Defaults to MCSA_Protected
301   MCSymbolAttr ProtectedVisibilityAttr;
302
303   //===--- Dwarf Emission Directives -----------------------------------===//
304
305   /// True if target supports emission of debugging information.  Defaults to
306   /// false.
307   bool SupportsDebugInformation;
308
309   /// Exception handling format for the target.  Defaults to None.
310   ExceptionHandling ExceptionsType;
311
312   /// Windows exception handling data (.pdata) encoding.  Defaults to Invalid.
313   WinEH::EncodingType WinEHEncodingType;
314
315   /// True if Dwarf2 output generally uses relocations for references to other
316   /// .debug_* sections.
317   bool DwarfUsesRelocationsAcrossSections;
318
319   /// True if DWARF FDE symbol reference relocations should be replaced by an
320   /// absolute difference.
321   bool DwarfFDESymbolsUseAbsDiff;
322
323   /// True if dwarf register numbers are printed instead of symbolic register
324   /// names in .cfi_* directives.  Defaults to false.
325   bool DwarfRegNumForCFI;
326
327   /// True if target uses parens to indicate the symbol variant instead of @.
328   /// For example, foo(plt) instead of foo@plt.  Defaults to false.
329   bool UseParensForSymbolVariant;
330
331   //===--- Prologue State ----------------------------------------------===//
332
333   std::vector<MCCFIInstruction> InitialFrameState;
334
335   //===--- Integrated Assembler State ----------------------------------===//
336
337   /// Should we use the integrated assembler?
338   /// The integrated assembler should be enabled by default (by the
339   /// constructors) when failing to parse a valid piece of assembly (inline
340   /// or otherwise) is considered a bug. It may then be overridden after
341   /// construction (see LLVMTargetMachine::initAsmInfo()).
342   bool UseIntegratedAssembler;
343
344   /// Compress DWARF debug sections. Defaults to false.
345   bool CompressDebugSections;
346
347 public:
348   explicit MCAsmInfo();
349   virtual ~MCAsmInfo();
350
351   /// Get the pointer size in bytes.
352   unsigned getPointerSize() const { return PointerSize; }
353
354   /// Get the callee-saved register stack slot
355   /// size in bytes.
356   unsigned getCalleeSaveStackSlotSize() const {
357     return CalleeSaveStackSlotSize;
358   }
359
360   /// True if the target is little endian.
361   bool isLittleEndian() const { return IsLittleEndian; }
362
363   /// True if target stack grow up.
364   bool isStackGrowthDirectionUp() const { return StackGrowsUp; }
365
366   bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
367
368   // Data directive accessors.
369
370   const char *getData8bitsDirective() const { return Data8bitsDirective; }
371   const char *getData16bitsDirective() const { return Data16bitsDirective; }
372   const char *getData32bitsDirective() const { return Data32bitsDirective; }
373   const char *getData64bitsDirective() const { return Data64bitsDirective; }
374   const char *getGPRel64Directive() const { return GPRel64Directive; }
375   const char *getGPRel32Directive() const { return GPRel32Directive; }
376
377   /// Targets can implement this method to specify a section to switch to if the
378   /// translation unit doesn't have any trampolines that require an executable
379   /// stack.
380   virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const {
381     return nullptr;
382   }
383
384   /// \brief True if the section is atomized using the symbols in it.
385   /// This is false if the section is not atomized at all (most ELF sections) or
386   /// if it is atomized based on its contents (MachO' __TEXT,__cstring for
387   /// example).
388   virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const;
389
390   virtual const MCExpr *getExprForPersonalitySymbol(const MCSymbol *Sym,
391                                                     unsigned Encoding,
392                                                     MCStreamer &Streamer) const;
393
394   virtual const MCExpr *getExprForFDESymbol(const MCSymbol *Sym,
395                                             unsigned Encoding,
396                                             MCStreamer &Streamer) const;
397
398   bool usesSunStyleELFSectionSwitchSyntax() const {
399     return SunStyleELFSectionSwitchSyntax;
400   }
401
402   bool usesELFSectionDirectiveForBSS() const {
403     return UsesELFSectionDirectiveForBSS;
404   }
405
406   bool needsDwarfSectionOffsetDirective() const {
407     return NeedsDwarfSectionOffsetDirective;
408   }
409
410   // Accessors.
411
412   bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
413   bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
414   bool hasStaticCtorDtorReferenceInStaticMode() const {
415     return HasStaticCtorDtorReferenceInStaticMode;
416   }
417   unsigned getMaxInstLength() const { return MaxInstLength; }
418   unsigned getMinInstAlignment() const { return MinInstAlignment; }
419   bool getDollarIsPC() const { return DollarIsPC; }
420   const char *getSeparatorString() const { return SeparatorString; }
421
422   /// This indicates the column (zero-based) at which asm comments should be
423   /// printed.
424   unsigned getCommentColumn() const { return 40; }
425
426   const char *getCommentString() const { return CommentString; }
427   const char *getLabelSuffix() const { return LabelSuffix; }
428
429   bool useAssignmentForEHBegin() const { return UseAssignmentForEHBegin; }
430   const char *getPrivateGlobalPrefix() const { return PrivateGlobalPrefix; }
431   const char *getPrivateLabelPrefix() const { return PrivateLabelPrefix; }
432   bool hasLinkerPrivateGlobalPrefix() const {
433     return LinkerPrivateGlobalPrefix[0] != '\0';
434   }
435   const char *getLinkerPrivateGlobalPrefix() const {
436     if (hasLinkerPrivateGlobalPrefix())
437       return LinkerPrivateGlobalPrefix;
438     return getPrivateGlobalPrefix();
439   }
440   const char *getInlineAsmStart() const { return InlineAsmStart; }
441   const char *getInlineAsmEnd() const { return InlineAsmEnd; }
442   const char *getCode16Directive() const { return Code16Directive; }
443   const char *getCode32Directive() const { return Code32Directive; }
444   const char *getCode64Directive() const { return Code64Directive; }
445   unsigned getAssemblerDialect() const { return AssemblerDialect; }
446   bool doesAllowAtInName() const { return AllowAtInName; }
447   bool doesSupportDataRegionDirectives() const {
448     return UseDataRegionDirectives;
449   }
450   const char *getZeroDirective() const { return ZeroDirective; }
451   const char *getAsciiDirective() const { return AsciiDirective; }
452   const char *getAscizDirective() const { return AscizDirective; }
453   bool getAlignmentIsInBytes() const { return AlignmentIsInBytes; }
454   unsigned getTextAlignFillValue() const { return TextAlignFillValue; }
455   const char *getGlobalDirective() const { return GlobalDirective; }
456   bool doesSetDirectiveSuppressesReloc() const {
457     return SetDirectiveSuppressesReloc;
458   }
459   bool hasAggressiveSymbolFolding() const { return HasAggressiveSymbolFolding; }
460   bool getCOMMDirectiveAlignmentIsInBytes() const {
461     return COMMDirectiveAlignmentIsInBytes;
462   }
463   LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
464     return LCOMMDirectiveAlignmentType;
465   }
466   bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
467   bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
468   bool hasIdentDirective() const { return HasIdentDirective; }
469   bool hasNoDeadStrip() const { return HasNoDeadStrip; }
470   const char *getWeakDirective() const { return WeakDirective; }
471   const char *getWeakRefDirective() const { return WeakRefDirective; }
472   bool hasWeakDefDirective() const { return HasWeakDefDirective; }
473   bool hasWeakDefCanBeHiddenDirective() const {
474     return HasWeakDefCanBeHiddenDirective;
475   }
476   bool hasLinkOnceDirective() const { return HasLinkOnceDirective; }
477
478   MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr; }
479   MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
480     return HiddenDeclarationVisibilityAttr;
481   }
482   MCSymbolAttr getProtectedVisibilityAttr() const {
483     return ProtectedVisibilityAttr;
484   }
485   bool doesSupportDebugInformation() const { return SupportsDebugInformation; }
486   bool doesSupportExceptionHandling() const {
487     return ExceptionsType != ExceptionHandling::None;
488   }
489   ExceptionHandling getExceptionHandlingType() const { return ExceptionsType; }
490   WinEH::EncodingType getWinEHEncodingType() const { return WinEHEncodingType; }
491
492   /// Returns true if the exception handling method for the platform uses call
493   /// frame information to unwind.
494   bool usesCFIForEH() const {
495     return (ExceptionsType == ExceptionHandling::DwarfCFI ||
496             ExceptionsType == ExceptionHandling::ARM ||
497             ExceptionsType == ExceptionHandling::WinEH);
498   }
499
500   bool usesWindowsCFI() const {
501     return ExceptionsType == ExceptionHandling::WinEH;
502   }
503
504   bool doesDwarfUseRelocationsAcrossSections() const {
505     return DwarfUsesRelocationsAcrossSections;
506   }
507   bool doDwarfFDESymbolsUseAbsDiff() const { return DwarfFDESymbolsUseAbsDiff; }
508   bool useDwarfRegNumForCFI() const { return DwarfRegNumForCFI; }
509   bool useParensForSymbolVariant() const { return UseParensForSymbolVariant; }
510
511   void addInitialFrameState(const MCCFIInstruction &Inst) {
512     InitialFrameState.push_back(Inst);
513   }
514
515   const std::vector<MCCFIInstruction> &getInitialFrameState() const {
516     return InitialFrameState;
517   }
518
519   /// Return true if assembly (inline or otherwise) should be parsed.
520   bool useIntegratedAssembler() const { return UseIntegratedAssembler; }
521
522   /// Set whether assembly (inline or otherwise) should be parsed.
523   virtual void setUseIntegratedAssembler(bool Value) {
524     UseIntegratedAssembler = Value;
525   }
526
527   bool compressDebugSections() const { return CompressDebugSections; }
528
529   void setCompressDebugSections(bool CompressDebugSections) {
530     this->CompressDebugSections = CompressDebugSections;
531   }
532 };
533 }
534
535 #endif