LLVM 19.0.0git
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"
14
15namespace llvm {
16class 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 SF_Cold = 0x0400,
39
40 // Common alignment
41 SF_CommonAlignmentMask = 0xF0FF,
42 SF_CommonAlignmentShift = 8
43 };
44
45public:
48
49 // Reference type methods.
50
51 void clearReferenceType() const {
52 modifyFlags(0, SF_ReferenceTypeMask);
53 }
54
56 modifyFlags(Value ? SF_ReferenceTypeUndefinedLazy : 0,
57 SF_ReferenceTypeUndefinedLazy);
58 }
59
60 // Other 'desc' methods.
61
62 void setThumbFunc() const {
63 modifyFlags(SF_ThumbFunc, SF_ThumbFunc);
64 }
65
66 bool isNoDeadStrip() const {
67 return getFlags() & SF_NoDeadStrip;
68 }
69 void setNoDeadStrip() const {
70 modifyFlags(SF_NoDeadStrip, SF_NoDeadStrip);
71 }
72
73 bool isWeakReference() const {
74 return getFlags() & SF_WeakReference;
75 }
76 void setWeakReference() const {
77 modifyFlags(SF_WeakReference, SF_WeakReference);
78 }
79
80 bool isWeakDefinition() const {
81 return getFlags() & SF_WeakDefinition;
82 }
83 void setWeakDefinition() const {
84 modifyFlags(SF_WeakDefinition, SF_WeakDefinition);
85 }
86
87 bool isSymbolResolver() const {
88 return getFlags() & SF_SymbolResolver;
89 }
90 void setSymbolResolver() const {
91 modifyFlags(SF_SymbolResolver, SF_SymbolResolver);
92 }
93
94 void setAltEntry() const {
95 modifyFlags(SF_AltEntry, SF_AltEntry);
96 }
97
98 bool isAltEntry() const {
99 return getFlags() & SF_AltEntry;
100 }
101
102 void setCold() const { modifyFlags(SF_Cold, SF_Cold); }
103
104 bool isCold() const { return getFlags() & SF_Cold; }
105
106 void setDesc(unsigned Value) const {
107 assert(Value == (Value & SF_DescFlagsMask) &&
108 "Invalid .desc value!");
109 setFlags(Value & SF_DescFlagsMask);
110 }
111
112 /// Get the encoded value of the flags as they will be emitted in to
113 /// the MachO binary
114 uint16_t getEncodedFlags(bool EncodeAsAltEntry) const {
116
117 // Common alignment is packed into the 'desc' bits.
118 if (isCommon()) {
119 if (MaybeAlign MaybeAlignment = getCommonAlignment()) {
120 Align Alignment = *MaybeAlignment;
121 unsigned Log2Size = Log2(Alignment);
122 if (Log2Size > 15)
123 report_fatal_error("invalid 'common' alignment '" +
124 Twine(Alignment.value()) + "' for '" +
125 getName() + "'",
126 false);
127 Flags = (Flags & SF_CommonAlignmentMask) |
128 (Log2Size << SF_CommonAlignmentShift);
129 }
130 }
131
132 if (EncodeAsAltEntry)
133 Flags |= SF_AltEntry;
134
135 return Flags;
136 }
137
138 static bool classof(const MCSymbol *S) { return S->isMachO(); }
139};
140}
141
142#endif
std::string Name
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void setWeakReference() const
Definition: MCSymbolMachO.h:76
bool isNoDeadStrip() const
Definition: MCSymbolMachO.h:66
uint16_t getEncodedFlags(bool EncodeAsAltEntry) const
Get the encoded value of the flags as they will be emitted in to the MachO binary.
void setWeakDefinition() const
Definition: MCSymbolMachO.h:83
void setSymbolResolver() const
Definition: MCSymbolMachO.h:90
void clearReferenceType() const
Definition: MCSymbolMachO.h:51
bool isCold() const
MCSymbolMachO(const MCSymbolTableEntry *Name, bool isTemporary)
Definition: MCSymbolMachO.h:46
bool isWeakReference() const
Definition: MCSymbolMachO.h:73
void setReferenceTypeUndefinedLazy(bool Value) const
Definition: MCSymbolMachO.h:55
void setAltEntry() const
Definition: MCSymbolMachO.h:94
void setCold() const
void setDesc(unsigned Value) const
bool isAltEntry() const
Definition: MCSymbolMachO.h:98
static bool classof(const MCSymbol *S)
bool isSymbolResolver() const
Definition: MCSymbolMachO.h:87
void setNoDeadStrip() const
Definition: MCSymbolMachO.h:69
bool isWeakDefinition() const
Definition: MCSymbolMachO.h:80
void setThumbFunc() const
Definition: MCSymbolMachO.h:62
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
bool isMachO() const
Definition: MCSymbol.h:289
bool isCommon() const
Is this a 'common' symbol.
Definition: MCSymbol.h:387
void modifyFlags(uint32_t Value, uint32_t Mask) const
Modify the flags via a mask.
Definition: MCSymbol.h:431
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:205
uint32_t Flags
Definition: MCSymbol.h:135
void setFlags(uint32_t Value) const
Set the (implementation defined) symbol flags.
Definition: MCSymbol.h:425
uint32_t getFlags() const
Get the (implementation defined) symbol flags.
Definition: MCSymbol.h:422
MaybeAlign getCommonAlignment() const
Return the alignment of a 'common' symbol.
Definition: MCSymbol.h:364
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition: MCSymbol.h:222
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:208
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117