Coverage Report

Created: 2019-02-21 13:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/MC/MCSectionMachO.h
Line
Count
Source (jump to first uncovered line)
1
//===- MCSectionMachO.h - MachO Machine Code Sections -----------*- 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
//
9
// This file declares the MCSectionMachO class.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_MC_MCSECTIONMACHO_H
14
#define LLVM_MC_MCSECTIONMACHO_H
15
16
#include "llvm/ADT/StringRef.h"
17
#include "llvm/BinaryFormat/MachO.h"
18
#include "llvm/MC/MCSection.h"
19
20
namespace llvm {
21
22
/// This represents a section on a Mach-O system (used by Mac OS X).  On a Mac
23
/// system, these are also described in /usr/include/mach-o/loader.h.
24
class MCSectionMachO final : public MCSection {
25
  char SegmentName[16];  // Not necessarily null terminated!
26
  char SectionName[16];  // Not necessarily null terminated!
27
28
  /// This is the SECTION_TYPE and SECTION_ATTRIBUTES field of a section, drawn
29
  /// from the enums below.
30
  unsigned TypeAndAttributes;
31
32
  /// The 'reserved2' field of a section, used to represent the size of stubs,
33
  /// for example.
34
  unsigned Reserved2;
35
36
  MCSectionMachO(StringRef Segment, StringRef Section, unsigned TAA,
37
                 unsigned reserved2, SectionKind K, MCSymbol *Begin);
38
  friend class MCContext;
39
public:
40
41
1.47M
  StringRef getSegmentName() const {
42
1.47M
    // SegmentName is not necessarily null terminated!
43
1.47M
    if (SegmentName[15])
44
46
      return StringRef(SegmentName, 16);
45
1.47M
    return StringRef(SegmentName);
46
1.47M
  }
47
151k
  StringRef getSectionName() const {
48
151k
    // SectionName is not necessarily null terminated!
49
151k
    if (SectionName[15])
50
15.4k
      return StringRef(SectionName, 16);
51
136k
    return StringRef(SectionName);
52
136k
  }
53
54
96.4k
  unsigned getTypeAndAttributes() const { return TypeAndAttributes; }
55
83.7k
  unsigned getStubSize() const { return Reserved2; }
56
57
3.32M
  MachO::SectionType getType() const {
58
3.32M
    return static_cast<MachO::SectionType>(TypeAndAttributes &
59
3.32M
                                           MachO::SECTION_TYPE);
60
3.32M
  }
61
6.93M
  bool hasAttribute(unsigned Value) const {
62
6.93M
    return (TypeAndAttributes & Value) != 0;
63
6.93M
  }
64
65
  /// Parse the section specifier indicated by "Spec". This is a string that can
66
  /// appear after a .section directive in a mach-o flavored .s file.  If
67
  /// successful, this fills in the specified Out parameters and returns an
68
  /// empty string.  When an invalid section specifier is present, this returns
69
  /// a string indicating the problem. If no TAA was parsed, TAA is not altered,
70
  /// and TAAWasSet becomes false.
71
  static std::string ParseSectionSpecifier(StringRef Spec,       // In.
72
                                           StringRef &Segment,   // Out.
73
                                           StringRef &Section,   // Out.
74
                                           unsigned  &TAA,       // Out.
75
                                           bool      &TAAParsed, // Out.
76
                                           unsigned  &StubSize); // Out.
77
78
  void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
79
                            raw_ostream &OS,
80
                            const MCExpr *Subsection) const override;
81
  bool UseCodeAlign() const override;
82
  bool isVirtualSection() const override;
83
84
0
  static bool classof(const MCSection *S) {
85
0
    return S->getVariant() == SV_MachO;
86
0
  }
87
};
88
89
} // end namespace llvm
90
91
#endif