Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:15

0001 //===- MCSymbolMachO.h -  ---------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 #ifndef LLVM_MC_MCSYMBOLMACHO_H
0009 #define LLVM_MC_MCSYMBOLMACHO_H
0010 
0011 #include "llvm/ADT/Twine.h"
0012 #include "llvm/MC/MCSymbol.h"
0013 #include "llvm/MC/MCSymbolTableEntry.h"
0014 
0015 namespace llvm {
0016 class MCSymbolMachO : public MCSymbol {
0017   /// We store the value for the 'desc' symbol field in the
0018   /// lowest 16 bits of the implementation defined flags.
0019   enum MachOSymbolFlags : uint16_t { // See <mach-o/nlist.h>.
0020     SF_DescFlagsMask                        = 0xFFFF,
0021 
0022     // Reference type flags.
0023     SF_ReferenceTypeMask                    = 0x0007,
0024     SF_ReferenceTypeUndefinedNonLazy        = 0x0000,
0025     SF_ReferenceTypeUndefinedLazy           = 0x0001,
0026     SF_ReferenceTypeDefined                 = 0x0002,
0027     SF_ReferenceTypePrivateDefined          = 0x0003,
0028     SF_ReferenceTypePrivateUndefinedNonLazy = 0x0004,
0029     SF_ReferenceTypePrivateUndefinedLazy    = 0x0005,
0030 
0031     // Other 'desc' flags.
0032     SF_ThumbFunc                            = 0x0008,
0033     SF_NoDeadStrip                          = 0x0020,
0034     SF_WeakReference                        = 0x0040,
0035     SF_WeakDefinition                       = 0x0080,
0036     SF_SymbolResolver                       = 0x0100,
0037     SF_AltEntry                             = 0x0200,
0038     SF_Cold                                 = 0x0400,
0039 
0040     // Common alignment
0041     SF_CommonAlignmentMask                  = 0xF0FF,
0042     SF_CommonAlignmentShift                 = 8
0043   };
0044 
0045 public:
0046   MCSymbolMachO(const MCSymbolTableEntry *Name, bool isTemporary)
0047       : MCSymbol(SymbolKindMachO, Name, isTemporary) {}
0048 
0049   bool isPrivateExtern() const { return IsPrivateExtern; }
0050   void setPrivateExtern(bool Value) { IsPrivateExtern = Value; }
0051 
0052   // Reference type methods.
0053 
0054   void clearReferenceType() const {
0055     modifyFlags(0, SF_ReferenceTypeMask);
0056   }
0057 
0058   void setReferenceTypeUndefinedLazy(bool Value) const {
0059     modifyFlags(Value ? SF_ReferenceTypeUndefinedLazy : 0,
0060                 SF_ReferenceTypeUndefinedLazy);
0061   }
0062 
0063   // Other 'desc' methods.
0064 
0065   void setThumbFunc() const {
0066     modifyFlags(SF_ThumbFunc, SF_ThumbFunc);
0067   }
0068 
0069   bool isNoDeadStrip() const {
0070     return getFlags() & SF_NoDeadStrip;
0071   }
0072   void setNoDeadStrip() const {
0073     modifyFlags(SF_NoDeadStrip, SF_NoDeadStrip);
0074   }
0075 
0076   bool isWeakReference() const {
0077     return getFlags() & SF_WeakReference;
0078   }
0079   void setWeakReference() const {
0080     modifyFlags(SF_WeakReference, SF_WeakReference);
0081   }
0082 
0083   bool isWeakDefinition() const {
0084     return getFlags() & SF_WeakDefinition;
0085   }
0086   void setWeakDefinition() const {
0087     modifyFlags(SF_WeakDefinition, SF_WeakDefinition);
0088   }
0089 
0090   bool isSymbolResolver() const {
0091     return getFlags() & SF_SymbolResolver;
0092   }
0093   void setSymbolResolver() const {
0094     modifyFlags(SF_SymbolResolver, SF_SymbolResolver);
0095   }
0096 
0097   void setAltEntry() const {
0098     modifyFlags(SF_AltEntry, SF_AltEntry);
0099   }
0100 
0101   bool isAltEntry() const {
0102     return getFlags() & SF_AltEntry;
0103   }
0104 
0105   void setCold() const { modifyFlags(SF_Cold, SF_Cold); }
0106 
0107   bool isCold() const { return getFlags() & SF_Cold; }
0108 
0109   void setDesc(unsigned Value) const {
0110     assert(Value == (Value & SF_DescFlagsMask) &&
0111            "Invalid .desc value!");
0112     setFlags(Value & SF_DescFlagsMask);
0113   }
0114 
0115   // Check whether a particular symbol is visible to the linker and is required
0116   // in the symbol table, or whether it can be discarded by the assembler. This
0117   // also effects whether the assembler treats the label as potentially defining
0118   // a separate atom.
0119   bool isSymbolLinkerVisible() const {
0120     // Non-temporary labels should always be visible to the linker.
0121     if (!isTemporary())
0122       return true;
0123 
0124     return isUsedInReloc();
0125   }
0126 
0127   /// Get the encoded value of the flags as they will be emitted in to
0128   /// the MachO binary
0129   uint16_t getEncodedFlags(bool EncodeAsAltEntry) const {
0130     uint16_t Flags = getFlags();
0131 
0132     // Common alignment is packed into the 'desc' bits.
0133     if (isCommon()) {
0134       if (MaybeAlign MaybeAlignment = getCommonAlignment()) {
0135         Align Alignment = *MaybeAlignment;
0136         unsigned Log2Size = Log2(Alignment);
0137         if (Log2Size > 15)
0138           report_fatal_error("invalid 'common' alignment '" +
0139                                  Twine(Alignment.value()) + "' for '" +
0140                                  getName() + "'",
0141                              false);
0142         Flags = (Flags & SF_CommonAlignmentMask) |
0143                 (Log2Size << SF_CommonAlignmentShift);
0144       }
0145     }
0146 
0147     if (EncodeAsAltEntry)
0148       Flags |= SF_AltEntry;
0149 
0150     return Flags;
0151   }
0152 
0153   static bool classof(const MCSymbol *S) { return S->isMachO(); }
0154 };
0155 }
0156 
0157 #endif