LLVM  9.0.0svn
MCSymbolMachO.h
Go to the documentation of this file.
1 //===- MCSymbolMachO.h - ---------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_MC_MCSYMBOLMACHO_H
9 #define LLVM_MC_MCSYMBOLMACHO_H
10 
11 #include "llvm/ADT/Twine.h"
12 #include "llvm/MC/MCSymbol.h"
13 
14 namespace llvm {
15 class MCSymbolMachO : public MCSymbol {
16  /// 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  SF_AltEntry = 0x0200,
37 
38  // Common alignment
39  SF_CommonAlignmentMask = 0xF0FF,
40  SF_CommonAlignmentShift = 8
41  };
42 
43 public:
45  : MCSymbol(SymbolKindMachO, Name, isTemporary) {}
46 
47  // Reference type methods.
48 
49  void clearReferenceType() const {
50  modifyFlags(0, SF_ReferenceTypeMask);
51  }
52 
54  modifyFlags(Value ? SF_ReferenceTypeUndefinedLazy : 0,
55  SF_ReferenceTypeUndefinedLazy);
56  }
57 
58  // Other 'desc' methods.
59 
60  void setThumbFunc() const {
61  modifyFlags(SF_ThumbFunc, SF_ThumbFunc);
62  }
63 
64  bool isNoDeadStrip() const {
65  return getFlags() & SF_NoDeadStrip;
66  }
67  void setNoDeadStrip() const {
68  modifyFlags(SF_NoDeadStrip, SF_NoDeadStrip);
69  }
70 
71  bool isWeakReference() const {
72  return getFlags() & SF_WeakReference;
73  }
74  void setWeakReference() const {
75  modifyFlags(SF_WeakReference, SF_WeakReference);
76  }
77 
78  bool isWeakDefinition() const {
79  return getFlags() & SF_WeakDefinition;
80  }
81  void setWeakDefinition() const {
82  modifyFlags(SF_WeakDefinition, SF_WeakDefinition);
83  }
84 
85  bool isSymbolResolver() const {
86  return getFlags() & SF_SymbolResolver;
87  }
88  void setSymbolResolver() const {
89  modifyFlags(SF_SymbolResolver, SF_SymbolResolver);
90  }
91 
92  void setAltEntry() const {
93  modifyFlags(SF_AltEntry, SF_AltEntry);
94  }
95 
96  bool isAltEntry() const {
97  return getFlags() & SF_AltEntry;
98  }
99 
100  void setDesc(unsigned Value) const {
101  assert(Value == (Value & SF_DescFlagsMask) &&
102  "Invalid .desc value!");
103  setFlags(Value & SF_DescFlagsMask);
104  }
105 
106  /// Get the encoded value of the flags as they will be emitted in to
107  /// the MachO binary
108  uint16_t getEncodedFlags(bool EncodeAsAltEntry) const {
109  uint16_t Flags = getFlags();
110 
111  // Common alignment is packed into the 'desc' bits.
112  if (isCommon()) {
113  if (unsigned Align = getCommonAlignment()) {
114  unsigned Log2Size = Log2_32(Align);
115  assert((1U << Log2Size) == Align && "Invalid 'common' alignment!");
116  if (Log2Size > 15)
117  report_fatal_error("invalid 'common' alignment '" +
118  Twine(Align) + "' for '" + getName() + "'",
119  false);
120  Flags = (Flags & SF_CommonAlignmentMask) |
121  (Log2Size << SF_CommonAlignmentShift);
122  }
123  }
124 
125  if (EncodeAsAltEntry)
126  Flags |= SF_AltEntry;
127 
128  return Flags;
129  }
130 
131  static bool classof(const MCSymbol *S) { return S->isMachO(); }
132 };
133 }
134 
135 #endif
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
void setReferenceTypeUndefinedLazy(bool Value) const
Definition: MCSymbolMachO.h:53
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:139
This class represents lattice values for constants.
Definition: AllocatorList.h:23
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:125
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
static bool classof(const MCSymbol *S)
unsigned getCommonAlignment() const
Return the alignment of a &#39;common&#39; symbol.
Definition: MCSymbol.h:358
bool isCommon() const
Is this a &#39;common&#39; symbol.
Definition: MCSymbol.h:379
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:80
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:88
bool isWeakReference() const
Definition: MCSymbolMachO.h:71
void setWeakDefinition() const
Definition: MCSymbolMachO.h:81
void setThumbFunc() const
Definition: MCSymbolMachO.h:60
bool isWeakDefinition() const
Definition: MCSymbolMachO.h:78
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition: MCSymbol.h:219
void setFlags(uint32_t Value) const
Set the (implementation defined) symbol flags.
Definition: MCSymbol.h:409
void setAltEntry() const
Definition: MCSymbolMachO.h:92
void clearReferenceType() const
Definition: MCSymbolMachO.h:49
uint32_t Flags
Definition: MCSymbol.h:123
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:538
bool isMachO() const
Definition: MCSymbol.h:284
bool isAltEntry() const
Definition: MCSymbolMachO.h:96
void setNoDeadStrip() const
Definition: MCSymbolMachO.h:67
MCSymbolMachO(const StringMapEntry< bool > *Name, bool isTemporary)
Definition: MCSymbolMachO.h:44
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:202
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isSymbolResolver() const
Definition: MCSymbolMachO.h:85
LLVM Value Representation.
Definition: Value.h:72
void setWeakReference() const
Definition: MCSymbolMachO.h:74
void modifyFlags(uint32_t Value, uint32_t Mask) const
Modify the flags via a mask.
Definition: MCSymbol.h:415
uint32_t getFlags() const
Get the (implementation defined) symbol flags.
Definition: MCSymbol.h:406
bool isNoDeadStrip() const
Definition: MCSymbolMachO.h:64