Coverage Report

Created: 2019-07-24 05:18

/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
// 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"
13
14
namespace llvm {
15
class MCSymbolMachO : public MCSymbol {
16
  /// We store the value for the 'desc' symbol field in the
17
  /// lowest 16 bits of the implementation defined flags.
18
  enum MachOSymbolFlags : uint16_t { // See <mach-o/nlist.h>.
19
    SF_DescFlagsMask                        = 0xFFFF,
20
21
    // Reference type flags.
22
    SF_ReferenceTypeMask                    = 0x0007,
23
    SF_ReferenceTypeUndefinedNonLazy        = 0x0000,
24
    SF_ReferenceTypeUndefinedLazy           = 0x0001,
25
    SF_ReferenceTypeDefined                 = 0x0002,
26
    SF_ReferenceTypePrivateDefined          = 0x0003,
27
    SF_ReferenceTypePrivateUndefinedNonLazy = 0x0004,
28
    SF_ReferenceTypePrivateUndefinedLazy    = 0x0005,
29
30
    // Other 'desc' flags.
31
    SF_ThumbFunc                            = 0x0008,
32
    SF_NoDeadStrip                          = 0x0020,
33
    SF_WeakReference                        = 0x0040,
34
    SF_WeakDefinition                       = 0x0080,
35
    SF_SymbolResolver                       = 0x0100,
36
    SF_AltEntry                             = 0x0200,
37
    SF_Cold                                 = 0x0400,
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.58M
      : MCSymbol(SymbolKindMachO, Name, isTemporary) {}
47
48
  // Reference type methods.
49
50
5.55M
  void clearReferenceType() const {
51
5.55M
    modifyFlags(0, SF_ReferenceTypeMask);
52
5.55M
  }
53
54
321k
  void setReferenceTypeUndefinedLazy(bool Value) const {
55
321k
    modifyFlags(Value ? 
SF_ReferenceTypeUndefinedLazy8
:
0321k
,
56
321k
                SF_ReferenceTypeUndefinedLazy);
57
321k
  }
58
59
  // Other 'desc' methods.
60
61
10.3k
  void setThumbFunc() const {
62
10.3k
    modifyFlags(SF_ThumbFunc, SF_ThumbFunc);
63
10.3k
  }
64
65
0
  bool isNoDeadStrip() const {
66
0
    return getFlags() & SF_NoDeadStrip;
67
0
  }
68
7.33k
  void setNoDeadStrip() const {
69
7.33k
    modifyFlags(SF_NoDeadStrip, SF_NoDeadStrip);
70
7.33k
  }
71
72
0
  bool isWeakReference() const {
73
0
    return getFlags() & SF_WeakReference;
74
0
  }
75
15.7k
  void setWeakReference() const {
76
15.7k
    modifyFlags(SF_WeakReference, SF_WeakReference);
77
15.7k
  }
78
79
117k
  bool isWeakDefinition() const {
80
117k
    return getFlags() & SF_WeakDefinition;
81
117k
  }
82
246k
  void setWeakDefinition() const {
83
246k
    modifyFlags(SF_WeakDefinition, SF_WeakDefinition);
84
246k
  }
85
86
0
  bool isSymbolResolver() const {
87
0
    return getFlags() & SF_SymbolResolver;
88
0
  }
89
1
  void setSymbolResolver() const {
90
1
    modifyFlags(SF_SymbolResolver, SF_SymbolResolver);
91
1
  }
92
93
26
  void setAltEntry() const {
94
26
    modifyFlags(SF_AltEntry, SF_AltEntry);
95
26
  }
96
97
268
  bool isAltEntry() const {
98
268
    return getFlags() & SF_AltEntry;
99
268
  }
100
101
2
  void setCold() const { modifyFlags(SF_Cold, SF_Cold); }
102
103
0
  bool isCold() const { return getFlags() & SF_Cold; }
104
105
992
  void setDesc(unsigned Value) const {
106
992
    assert(Value == (Value & SF_DescFlagsMask) &&
107
992
           "Invalid .desc value!");
108
992
    setFlags(Value & SF_DescFlagsMask);
109
992
  }
110
111
  /// Get the encoded value of the flags as they will be emitted in to
112
  /// the MachO binary
113
857k
  uint16_t getEncodedFlags(bool EncodeAsAltEntry) const {
114
857k
    uint16_t Flags = getFlags();
115
857k
116
857k
    // Common alignment is packed into the 'desc' bits.
117
857k
    if (isCommon()) {
118
11.1k
      if (unsigned Align = getCommonAlignment()) {
119
11.0k
        unsigned Log2Size = Log2_32(Align);
120
11.0k
        assert((1U << Log2Size) == Align && "Invalid 'common' alignment!");
121
11.0k
        if (Log2Size > 15)
122
0
          report_fatal_error("invalid 'common' alignment '" +
123
0
                             Twine(Align) + "' for '" + getName() + "'",
124
0
                             false);
125
11.0k
        Flags = (Flags & SF_CommonAlignmentMask) |
126
11.0k
                (Log2Size << SF_CommonAlignmentShift);
127
11.0k
      }
128
11.1k
    }
129
857k
130
857k
    if (EncodeAsAltEntry)
131
2
      Flags |= SF_AltEntry;
132
857k
133
857k
    return Flags;
134
857k
  }
135
136
0
  static bool classof(const MCSymbol *S) { return S->isMachO(); }
137
};
138
}
139
140
#endif