LLVM 22.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 bool isExternal() const { return IsExternal; }
50 void setExternal(bool Value) const { IsExternal = Value; }
51 bool isPrivateExtern() const { return IsPrivateExtern; }
53
54 // Reference type methods.
55
56 void clearReferenceType() const {
57 modifyFlags(0, SF_ReferenceTypeMask);
58 }
59
61 modifyFlags(Value ? SF_ReferenceTypeUndefinedLazy : 0,
62 SF_ReferenceTypeUndefinedLazy);
63 }
64
65 // Other 'desc' methods.
66
67 void setThumbFunc() const {
68 modifyFlags(SF_ThumbFunc, SF_ThumbFunc);
69 }
70
71 bool isNoDeadStrip() const {
72 return getFlags() & SF_NoDeadStrip;
73 }
74 void setNoDeadStrip() const {
75 modifyFlags(SF_NoDeadStrip, SF_NoDeadStrip);
76 }
77
78 bool isWeakReference() const {
79 return getFlags() & SF_WeakReference;
80 }
81 void setWeakReference() const {
82 modifyFlags(SF_WeakReference, SF_WeakReference);
83 }
84
85 bool isWeakDefinition() const {
86 return getFlags() & SF_WeakDefinition;
87 }
88 void setWeakDefinition() const {
89 modifyFlags(SF_WeakDefinition, SF_WeakDefinition);
90 }
91
92 bool isSymbolResolver() const {
93 return getFlags() & SF_SymbolResolver;
94 }
95 void setSymbolResolver() const {
96 modifyFlags(SF_SymbolResolver, SF_SymbolResolver);
97 }
98
99 void setAltEntry() const {
100 modifyFlags(SF_AltEntry, SF_AltEntry);
101 }
102
103 bool isAltEntry() const {
104 return getFlags() & SF_AltEntry;
105 }
106
107 void setCold() const { modifyFlags(SF_Cold, SF_Cold); }
108
109 bool isCold() const { return getFlags() & SF_Cold; }
110
111 void setDesc(unsigned Value) const {
112 assert(Value == (Value & SF_DescFlagsMask) &&
113 "Invalid .desc value!");
114 setFlags(Value & SF_DescFlagsMask);
115 }
116
117 // Check whether a particular symbol is visible to the linker and is required
118 // in the symbol table, or whether it can be discarded by the assembler. This
119 // also effects whether the assembler treats the label as potentially defining
120 // a separate atom.
122 // Non-temporary labels should always be visible to the linker.
123 if (!isTemporary())
124 return true;
125
126 return isUsedInReloc();
127 }
128
129 /// Get the encoded value of the flags as they will be emitted in to
130 /// the MachO binary
131 uint16_t getEncodedFlags(bool EncodeAsAltEntry) const {
133
134 // Common alignment is packed into the 'desc' bits.
135 if (isCommon()) {
136 if (MaybeAlign MaybeAlignment = getCommonAlignment()) {
137 Align Alignment = *MaybeAlignment;
138 unsigned Log2Size = Log2(Alignment);
139 if (Log2Size > 15)
140 report_fatal_error("invalid 'common' alignment '" +
141 Twine(Alignment.value()) + "' for '" +
142 getName() + "'",
143 false);
144 Flags = (Flags & SF_CommonAlignmentMask) |
145 (Log2Size << SF_CommonAlignmentShift);
146 }
147 }
148
149 if (EncodeAsAltEntry)
150 Flags |= SF_AltEntry;
151
152 return Flags;
153 }
154};
155}
156
157#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
bool isPrivateExtern() const
void setWeakReference() const
bool isNoDeadStrip() const
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
void setSymbolResolver() const
bool isExternal() const
void clearReferenceType() const
MCSymbolMachO(const MCSymbolTableEntry *Name, bool isTemporary)
bool isWeakReference() const
void setReferenceTypeUndefinedLazy(bool Value) const
void setAltEntry() const
void setPrivateExtern(bool Value)
bool isSymbolLinkerVisible() const
void setExternal(bool Value) const
void setDesc(unsigned Value) const
bool isAltEntry() const
bool isSymbolResolver() const
void setNoDeadStrip() const
bool isWeakDefinition() const
void setThumbFunc() const
MCSymbol(const MCSymbolTableEntry *Name, bool isTemporary)
Definition MCSymbol.h:146
bool isCommon() const
Is this a 'common' symbol.
Definition MCSymbol.h:344
void modifyFlags(uint32_t Value, uint32_t Mask) const
Modify the flags via a mask.
Definition MCSymbol.h:375
unsigned IsPrivateExtern
Mach-O specific: This symbol is private extern.
Definition MCSymbol.h:90
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
uint32_t Flags
Definition MCSymbol.h:117
void setFlags(uint32_t Value) const
Set the (implementation defined) symbol flags.
Definition MCSymbol.h:369
uint32_t getFlags() const
Get the (implementation defined) symbol flags.
Definition MCSymbol.h:366
unsigned IsExternal
True if this symbol is visible outside this translation unit.
Definition MCSymbol.h:87
MaybeAlign getCommonAlignment() const
Return the alignment of a 'common' symbol.
Definition MCSymbol.h:323
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition MCSymbol.h:205
const MCExpr * Value
If non-null, the value for a variable symbol.
Definition MCSymbol.h:130
bool isUsedInReloc() const
Definition MCSymbol.h:199
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:167
StringMapEntry< MCSymbolTableValue > MCSymbolTableEntry
MCContext stores MCSymbolTableValue in a string map (see MCSymbol::operator new).
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