MCSymbolMachO.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #include "llvm/MC/MCSymbol.h"
  12. namespace llvm {
  13. class MCSymbolMachO : public MCSymbol {
  14. /// \brief We store the value for the 'desc' symbol field in the
  15. /// lowest 16 bits of the implementation defined flags.
  16. enum MachOSymbolFlags : uint16_t { // See <mach-o/nlist.h>.
  17. SF_DescFlagsMask = 0xFFFF,
  18. // Reference type flags.
  19. SF_ReferenceTypeMask = 0x0007,
  20. SF_ReferenceTypeUndefinedNonLazy = 0x0000,
  21. SF_ReferenceTypeUndefinedLazy = 0x0001,
  22. SF_ReferenceTypeDefined = 0x0002,
  23. SF_ReferenceTypePrivateDefined = 0x0003,
  24. SF_ReferenceTypePrivateUndefinedNonLazy = 0x0004,
  25. SF_ReferenceTypePrivateUndefinedLazy = 0x0005,
  26. // Other 'desc' flags.
  27. SF_ThumbFunc = 0x0008,
  28. SF_NoDeadStrip = 0x0020,
  29. SF_WeakReference = 0x0040,
  30. SF_WeakDefinition = 0x0080,
  31. SF_SymbolResolver = 0x0100,
  32. // Common alignment
  33. SF_CommonAlignmentMask = 0xF0FF,
  34. SF_CommonAlignmentShift = 8
  35. };
  36. public:
  37. MCSymbolMachO(const StringMapEntry<bool> *Name, bool isTemporary)
  38. : MCSymbol(SymbolKindMachO, Name, isTemporary) {}
  39. // Reference type methods.
  40. void clearReferenceType() const {
  41. modifyFlags(0, SF_ReferenceTypeMask);
  42. }
  43. void setReferenceTypeUndefinedLazy(bool Value) const {
  44. modifyFlags(Value ? SF_ReferenceTypeUndefinedLazy : 0,
  45. SF_ReferenceTypeUndefinedLazy);
  46. }
  47. // Other 'desc' methods.
  48. void setThumbFunc() const {
  49. modifyFlags(SF_ThumbFunc, SF_ThumbFunc);
  50. }
  51. bool isNoDeadStrip() const {
  52. return getFlags() & SF_NoDeadStrip;
  53. }
  54. void setNoDeadStrip() const {
  55. modifyFlags(SF_NoDeadStrip, SF_NoDeadStrip);
  56. }
  57. bool isWeakReference() const {
  58. return getFlags() & SF_WeakReference;
  59. }
  60. void setWeakReference() const {
  61. modifyFlags(SF_WeakReference, SF_WeakReference);
  62. }
  63. bool isWeakDefinition() const {
  64. return getFlags() & SF_WeakDefinition;
  65. }
  66. void setWeakDefinition() const {
  67. modifyFlags(SF_WeakDefinition, SF_WeakDefinition);
  68. }
  69. bool isSymbolResolver() const {
  70. return getFlags() & SF_SymbolResolver;
  71. }
  72. void setSymbolResolver() const {
  73. modifyFlags(SF_SymbolResolver, SF_SymbolResolver);
  74. }
  75. void setDesc(unsigned Value) const {
  76. assert(Value == (Value & SF_DescFlagsMask) &&
  77. "Invalid .desc value!");
  78. setFlags(Value & SF_DescFlagsMask);
  79. }
  80. /// \brief Get the encoded value of the flags as they will be emitted in to
  81. /// the MachO binary
  82. uint16_t getEncodedFlags() const {
  83. uint16_t Flags = getFlags();
  84. // Common alignment is packed into the 'desc' bits.
  85. if (isCommon()) {
  86. if (unsigned Align = getCommonAlignment()) {
  87. unsigned Log2Size = Log2_32(Align);
  88. assert((1U << Log2Size) == Align && "Invalid 'common' alignment!");
  89. if (Log2Size > 15)
  90. report_fatal_error("invalid 'common' alignment '" +
  91. Twine(Align) + "' for '" + getName() + "'",
  92. false);
  93. Flags = (Flags & SF_CommonAlignmentMask) |
  94. (Log2Size << SF_CommonAlignmentShift);
  95. }
  96. }
  97. return Flags;
  98. }
  99. static bool classof(const MCSymbol *S) { return S->isMachO(); }
  100. };
  101. }
  102. #endif