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