LLVM  8.0.1
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/ADT/Twine.h"
13 #include "llvm/MC/MCSymbol.h"
14 
15 namespace llvm {
16 class MCSymbolMachO : public MCSymbol {
17  /// We store the value for the 'desc' symbol field in the
18  /// lowest 16 bits of the implementation defined flags.
19  enum MachOSymbolFlags : uint16_t { // See <mach-o/nlist.h>.
20  SF_DescFlagsMask = 0xFFFF,
21 
22  // Reference type flags.
23  SF_ReferenceTypeMask = 0x0007,
24  SF_ReferenceTypeUndefinedNonLazy = 0x0000,
25  SF_ReferenceTypeUndefinedLazy = 0x0001,
26  SF_ReferenceTypeDefined = 0x0002,
27  SF_ReferenceTypePrivateDefined = 0x0003,
28  SF_ReferenceTypePrivateUndefinedNonLazy = 0x0004,
29  SF_ReferenceTypePrivateUndefinedLazy = 0x0005,
30 
31  // Other 'desc' flags.
32  SF_ThumbFunc = 0x0008,
33  SF_NoDeadStrip = 0x0020,
34  SF_WeakReference = 0x0040,
35  SF_WeakDefinition = 0x0080,
36  SF_SymbolResolver = 0x0100,
37  SF_AltEntry = 0x0200,
38 
39  // Common alignment
40  SF_CommonAlignmentMask = 0xF0FF,
41  SF_CommonAlignmentShift = 8
42  };
43 
44 public:
46  : MCSymbol(SymbolKindMachO, Name, isTemporary) {}
47 
48  // Reference type methods.
49 
50  void clearReferenceType() const {
51  modifyFlags(0, SF_ReferenceTypeMask);
52  }
53 
55  modifyFlags(Value ? SF_ReferenceTypeUndefinedLazy : 0,
56  SF_ReferenceTypeUndefinedLazy);
57  }
58 
59  // Other 'desc' methods.
60 
61  void setThumbFunc() const {
62  modifyFlags(SF_ThumbFunc, SF_ThumbFunc);
63  }
64 
65  bool isNoDeadStrip() const {
66  return getFlags() & SF_NoDeadStrip;
67  }
68  void setNoDeadStrip() const {
69  modifyFlags(SF_NoDeadStrip, SF_NoDeadStrip);
70  }
71 
72  bool isWeakReference() const {
73  return getFlags() & SF_WeakReference;
74  }
75  void setWeakReference() const {
76  modifyFlags(SF_WeakReference, SF_WeakReference);
77  }
78 
79  bool isWeakDefinition() const {
80  return getFlags() & SF_WeakDefinition;
81  }
82  void setWeakDefinition() const {
83  modifyFlags(SF_WeakDefinition, SF_WeakDefinition);
84  }
85 
86  bool isSymbolResolver() const {
87  return getFlags() & SF_SymbolResolver;
88  }
89  void setSymbolResolver() const {
90  modifyFlags(SF_SymbolResolver, SF_SymbolResolver);
91  }
92 
93  void setAltEntry() const {
94  modifyFlags(SF_AltEntry, SF_AltEntry);
95  }
96 
97  bool isAltEntry() const {
98  return getFlags() & SF_AltEntry;
99  }
100 
101  void setDesc(unsigned Value) const {
102  assert(Value == (Value & SF_DescFlagsMask) &&
103  "Invalid .desc value!");
104  setFlags(Value & SF_DescFlagsMask);
105  }
106 
107  /// Get the encoded value of the flags as they will be emitted in to
108  /// the MachO binary
109  uint16_t getEncodedFlags(bool EncodeAsAltEntry) const {
110  uint16_t Flags = getFlags();
111 
112  // Common alignment is packed into the 'desc' bits.
113  if (isCommon()) {
114  if (unsigned Align = getCommonAlignment()) {
115  unsigned Log2Size = Log2_32(Align);
116  assert((1U << Log2Size) == Align && "Invalid 'common' alignment!");
117  if (Log2Size > 15)
118  report_fatal_error("invalid 'common' alignment '" +
119  Twine(Align) + "' for '" + getName() + "'",
120  false);
121  Flags = (Flags & SF_CommonAlignmentMask) |
122  (Log2Size << SF_CommonAlignmentShift);
123  }
124  }
125 
126  if (EncodeAsAltEntry)
127  Flags |= SF_AltEntry;
128 
129  return Flags;
130  }
131 
132  static bool classof(const MCSymbol *S) { return S->isMachO(); }
133 };
134 }
135 
136 #endif
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
void setReferenceTypeUndefinedLazy(bool Value) const
Definition: MCSymbolMachO.h:54
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:24
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:126
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
static bool classof(const MCSymbol *S)
unsigned getCommonAlignment() const
Return the alignment of a &#39;common&#39; symbol.
Definition: MCSymbol.h:359
bool isCommon() const
Is this a &#39;common&#39; symbol.
Definition: MCSymbol.h:380
void setDesc(unsigned Value) const
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
uint16_t getEncodedFlags(bool EncodeAsAltEntry) const
Get the encoded value of the flags as they will be emitted in to the MachO binary.
void setSymbolResolver() const
Definition: MCSymbolMachO.h:89
bool isWeakReference() const
Definition: MCSymbolMachO.h:72
void setWeakDefinition() const
Definition: MCSymbolMachO.h:82
void setThumbFunc() const
Definition: MCSymbolMachO.h:61
bool isWeakDefinition() const
Definition: MCSymbolMachO.h:79
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition: MCSymbol.h:220
void setFlags(uint32_t Value) const
Set the (implementation defined) symbol flags.
Definition: MCSymbol.h:410
void setAltEntry() const
Definition: MCSymbolMachO.h:93
void clearReferenceType() const
Definition: MCSymbolMachO.h:50
uint32_t Flags
Definition: MCSymbol.h:124
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:539
bool isMachO() const
Definition: MCSymbol.h:285
bool isAltEntry() const
Definition: MCSymbolMachO.h:97
void setNoDeadStrip() const
Definition: MCSymbolMachO.h:68
MCSymbolMachO(const StringMapEntry< bool > *Name, bool isTemporary)
Definition: MCSymbolMachO.h:45
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:203
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isSymbolResolver() const
Definition: MCSymbolMachO.h:86
LLVM Value Representation.
Definition: Value.h:73
void setWeakReference() const
Definition: MCSymbolMachO.h:75
void modifyFlags(uint32_t Value, uint32_t Mask) const
Modify the flags via a mask.
Definition: MCSymbol.h:416
uint32_t getFlags() const
Get the (implementation defined) symbol flags.
Definition: MCSymbol.h:407
bool isNoDeadStrip() const
Definition: MCSymbolMachO.h:65