LLVM  3.7.0
MCSymbolMachO.h
Go to the documentation of this file.
1 //===- MCSymbolMachO.h - ---------------------------------------*- 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 #ifndef LLVM_MC_MCSYMBOLMACHO_H
10 #define LLVM_MC_MCSYMBOLMACHO_H
11 
12 #include "llvm/MC/MCSymbol.h"
13 
14 namespace llvm {
15 class MCSymbolMachO : public MCSymbol {
16  /// \brief We store the value for the 'desc' symbol field in the
17  /// lowest 16 bits of the implementation defined flags.
18  enum MachOSymbolFlags : uint16_t { // See <mach-o/nlist.h>.
19  SF_DescFlagsMask = 0xFFFF,
20 
21  // Reference type flags.
22  SF_ReferenceTypeMask = 0x0007,
23  SF_ReferenceTypeUndefinedNonLazy = 0x0000,
24  SF_ReferenceTypeUndefinedLazy = 0x0001,
25  SF_ReferenceTypeDefined = 0x0002,
26  SF_ReferenceTypePrivateDefined = 0x0003,
27  SF_ReferenceTypePrivateUndefinedNonLazy = 0x0004,
28  SF_ReferenceTypePrivateUndefinedLazy = 0x0005,
29 
30  // Other 'desc' flags.
31  SF_ThumbFunc = 0x0008,
32  SF_NoDeadStrip = 0x0020,
33  SF_WeakReference = 0x0040,
34  SF_WeakDefinition = 0x0080,
35  SF_SymbolResolver = 0x0100,
36 
37  // Common alignment
38  SF_CommonAlignmentMask = 0xF0FF,
39  SF_CommonAlignmentShift = 8
40  };
41 
42 public:
44  : MCSymbol(SymbolKindMachO, Name, isTemporary) {}
45 
46  // Reference type methods.
47 
48  void clearReferenceType() const {
49  modifyFlags(0, SF_ReferenceTypeMask);
50  }
51 
53  modifyFlags(Value ? SF_ReferenceTypeUndefinedLazy : 0,
54  SF_ReferenceTypeUndefinedLazy);
55  }
56 
57  // Other 'desc' methods.
58 
59  void setThumbFunc() const {
60  modifyFlags(SF_ThumbFunc, SF_ThumbFunc);
61  }
62 
63  bool isNoDeadStrip() const {
64  return getFlags() & SF_NoDeadStrip;
65  }
66  void setNoDeadStrip() const {
67  modifyFlags(SF_NoDeadStrip, SF_NoDeadStrip);
68  }
69 
70  bool isWeakReference() const {
71  return getFlags() & SF_WeakReference;
72  }
73  void setWeakReference() const {
74  modifyFlags(SF_WeakReference, SF_WeakReference);
75  }
76 
77  bool isWeakDefinition() const {
78  return getFlags() & SF_WeakDefinition;
79  }
80  void setWeakDefinition() const {
81  modifyFlags(SF_WeakDefinition, SF_WeakDefinition);
82  }
83 
84  bool isSymbolResolver() const {
85  return getFlags() & SF_SymbolResolver;
86  }
87  void setSymbolResolver() const {
88  modifyFlags(SF_SymbolResolver, SF_SymbolResolver);
89  }
90 
91  void setDesc(unsigned Value) const {
92  assert(Value == (Value & SF_DescFlagsMask) &&
93  "Invalid .desc value!");
94  setFlags(Value & SF_DescFlagsMask);
95  }
96 
97  /// \brief Get the encoded value of the flags as they will be emitted in to
98  /// the MachO binary
99  uint16_t getEncodedFlags() const {
100  uint16_t Flags = getFlags();
101 
102  // Common alignment is packed into the 'desc' bits.
103  if (isCommon()) {
104  if (unsigned Align = getCommonAlignment()) {
105  unsigned Log2Size = Log2_32(Align);
106  assert((1U << Log2Size) == Align && "Invalid 'common' alignment!");
107  if (Log2Size > 15)
108  report_fatal_error("invalid 'common' alignment '" +
109  Twine(Align) + "' for '" + getName() + "'",
110  false);
111  Flags = (Flags & SF_CommonAlignmentMask) |
112  (Log2Size << SF_CommonAlignmentShift);
113  }
114  }
115 
116  return Flags;
117  }
118 
119  static bool classof(const MCSymbol *S) { return S->isMachO(); }
120 };
121 }
122 
123 #endif
bool isSymbolResolver() const
Definition: MCSymbolMachO.h:84
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
static bool classof(const MCSymbol *S)
void clearReferenceType() const
Definition: MCSymbolMachO.h:48
bool isNoDeadStrip() const
Definition: MCSymbolMachO.h:63
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
void setFlags(uint32_t Value) const
Set the (implementation defined) symbol flags.
Definition: MCSymbol.h:406
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
bool isMachO() const
Definition: MCSymbol.h:287
void setWeakReference() const
Definition: MCSymbolMachO.h:73
void setWeakDefinition() const
Definition: MCSymbolMachO.h:80
bool isWeakReference() const
Definition: MCSymbolMachO.h:70
uint32_t getFlags() const
Get the (implementation defined) symbol flags.
Definition: MCSymbol.h:403
bool isWeakDefinition() const
Definition: MCSymbolMachO.h:77
void modifyFlags(uint32_t Value, uint32_t Mask) const
Modify the flags via a mask.
Definition: MCSymbol.h:412
void setDesc(unsigned Value) const
Definition: MCSymbolMachO.h:91
unsigned getCommonAlignment() const
Return the alignment of a 'common' symbol.
Definition: MCSymbol.h:357
void setThumbFunc() const
Definition: MCSymbolMachO.h:59
void setReferenceTypeUndefinedLazy(bool Value) const
Definition: MCSymbolMachO.h:52
void setSymbolResolver() const
Definition: MCSymbolMachO.h:87
uint32_t Flags
Definition: MCSymbol.h:123
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
uint16_t getEncodedFlags() const
Get the encoded value of the flags as they will be emitted in to the MachO binary.
Definition: MCSymbolMachO.h:99
unsigned Log2_32(uint32_t Value)
Log2_32 - This function returns the floor log base 2 of the specified value, -1 if the value is zero...
Definition: MathExtras.h:468
void setNoDeadStrip() const
Definition: MCSymbolMachO.h:66
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition: MCSymbol.h:222
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:205
bool isCommon() const
Is this a 'common' symbol.
Definition: MCSymbol.h:378
MCSymbolMachO(const StringMapEntry< bool > *Name, bool isTemporary)
Definition: MCSymbolMachO.h:43
LLVM Value Representation.
Definition: Value.h:69