Coverage Report

Created: 2018-09-23 16:00

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/MC/MCSymbolMachO.h
Line
Count
Source (jump to first uncovered line)
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
12
#include "llvm/ADT/Twine.h"
13
#include "llvm/MC/MCSymbol.h"
14
15
namespace llvm {
16
class 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
39
    // Common alignment
40
    SF_CommonAlignmentMask                  = 0xF0FF,
41
    SF_CommonAlignmentShift                 = 8
42
  };
43
44
public:
45
  MCSymbolMachO(const StringMapEntry<bool> *Name, bool isTemporary)
46
6.90M
      : MCSymbol(SymbolKindMachO, Name, isTemporary) {}
47
48
  // Reference type methods.
49
50
5.82M
  void clearReferenceType() const {
51
5.82M
    modifyFlags(0, SF_ReferenceTypeMask);
52
5.82M
  }
53
54
322k
  void setReferenceTypeUndefinedLazy(bool Value) const {
55
322k
    modifyFlags(Value ? 
SF_ReferenceTypeUndefinedLazy8
:
0322k
,
56
322k
                SF_ReferenceTypeUndefinedLazy);
57
322k
  }
58
59
  // Other 'desc' methods.
60
61
10.1k
  void setThumbFunc() const {
62
10.1k
    modifyFlags(SF_ThumbFunc, SF_ThumbFunc);
63
10.1k
  }
64
65
  bool isNoDeadStrip() const {
66
    return getFlags() & SF_NoDeadStrip;
67
  }
68
7.21k
  void setNoDeadStrip() const {
69
7.21k
    modifyFlags(SF_NoDeadStrip, SF_NoDeadStrip);
70
7.21k
  }
71
72
  bool isWeakReference() const {
73
    return getFlags() & SF_WeakReference;
74
  }
75
15.4k
  void setWeakReference() const {
76
15.4k
    modifyFlags(SF_WeakReference, SF_WeakReference);
77
15.4k
  }
78
79
196k
  bool isWeakDefinition() const {
80
196k
    return getFlags() & SF_WeakDefinition;
81
196k
  }
82
245k
  void setWeakDefinition() const {
83
245k
    modifyFlags(SF_WeakDefinition, SF_WeakDefinition);
84
245k
  }
85
86
  bool isSymbolResolver() const {
87
    return getFlags() & SF_SymbolResolver;
88
  }
89
1
  void setSymbolResolver() const {
90
1
    modifyFlags(SF_SymbolResolver, SF_SymbolResolver);
91
1
  }
92
93
21
  void setAltEntry() const {
94
21
    modifyFlags(SF_AltEntry, SF_AltEntry);
95
21
  }
96
97
98
  bool isAltEntry() const {
98
98
    return getFlags() & SF_AltEntry;
99
98
  }
100
101
976
  void setDesc(unsigned Value) const {
102
976
    assert(Value == (Value & SF_DescFlagsMask) &&
103
976
           "Invalid .desc value!");
104
976
    setFlags(Value & SF_DescFlagsMask);
105
976
  }
106
107
  /// Get the encoded value of the flags as they will be emitted in to
108
  /// the MachO binary
109
881k
  uint16_t getEncodedFlags(bool EncodeAsAltEntry) const {
110
881k
    uint16_t Flags = getFlags();
111
881k
112
881k
    // Common alignment is packed into the 'desc' bits.
113
881k
    if (isCommon()) {
114
11.0k
      if (unsigned Align = getCommonAlignment()) {
115
11.0k
        unsigned Log2Size = Log2_32(Align);
116
11.0k
        assert((1U << Log2Size) == Align && "Invalid 'common' alignment!");
117
11.0k
        if (Log2Size > 15)
118
0
          report_fatal_error("invalid 'common' alignment '" +
119
0
                             Twine(Align) + "' for '" + getName() + "'",
120
0
                             false);
121
11.0k
        Flags = (Flags & SF_CommonAlignmentMask) |
122
11.0k
                (Log2Size << SF_CommonAlignmentShift);
123
11.0k
      }
124
11.0k
    }
125
881k
126
881k
    if (EncodeAsAltEntry)
127
2
      Flags |= SF_AltEntry;
128
881k
129
881k
    return Flags;
130
881k
  }
131
132
  static bool classof(const MCSymbol *S) { return S->isMachO(); }
133
};
134
}
135
136
#endif