1 //===- OutputSegment.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 
9 #ifndef LLD_MACHO_OUTPUT_SEGMENT_H
10 #define LLD_MACHO_OUTPUT_SEGMENT_H
11 
12 #include "lld/Common/LLVM.h"
13 #include "llvm/ADT/MapVector.h"
14 
15 namespace lld {
16 namespace macho {
17 
18 namespace segment_names {
19 
20 constexpr const char *text = "__TEXT";
21 constexpr const char *pageZero = "__PAGEZERO";
22 constexpr const char *linkEdit = "__LINKEDIT";
23 
24 } // namespace segment_names
25 
26 class InputSection;
27 
28 class OutputSegment {
29 public:
30   InputSection *firstSection() const { return sections.front().second.at(0); }
31 
32   InputSection *lastSection() const { return sections.back().second.back(); }
33 
34   bool isNeeded() const {
35     return !sections.empty() || name == segment_names::linkEdit;
36   }
37 
38   void addSection(InputSection *);
39 
40   const llvm::MapVector<StringRef, std::vector<InputSection *>> &
41   getSections() const {
42     return sections;
43   }
44 
45   uint64_t fileOff = 0;
46   StringRef name;
47   uint32_t numNonHiddenSections = 0;
48   uint32_t maxProt = 0;
49   uint32_t initProt = 0;
50   uint8_t index;
51 
52 private:
53   llvm::MapVector<StringRef, std::vector<InputSection *>> sections;
54 };
55 
56 extern std::vector<OutputSegment *> outputSegments;
57 
58 OutputSegment *getOutputSegment(StringRef name);
59 OutputSegment *getOrCreateOutputSegment(StringRef name);
60 
61 } // namespace macho
62 } // namespace lld
63 
64 #endif
65