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