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 "OutputSection.h" 13 #include "lld/Common/LLVM.h" 14 15 namespace lld { 16 namespace macho { 17 18 namespace segment_names { 19 20 constexpr const char pageZero[] = "__PAGEZERO"; 21 constexpr const char text[] = "__TEXT"; 22 constexpr const char data[] = "__DATA"; 23 constexpr const char linkEdit[] = "__LINKEDIT"; 24 constexpr const char dataConst[] = "__DATA_CONST"; 25 26 } // namespace segment_names 27 28 class OutputSection; 29 class InputSection; 30 31 class OutputSegment { 32 public: 33 const OutputSection *firstSection() const { return sections.front(); } 34 const OutputSection *lastSection() const { return sections.back(); } 35 36 void addOutputSection(OutputSection *os); 37 void sortOutputSections( 38 llvm::function_ref<bool(OutputSection *, OutputSection *)> comparator) { 39 llvm::stable_sort(sections, comparator); 40 } 41 42 const std::vector<OutputSection *> &getSections() const { return sections; } 43 size_t numNonHiddenSections() const; 44 45 uint64_t fileOff = 0; 46 StringRef name; 47 uint32_t maxProt = 0; 48 uint32_t initProt = 0; 49 uint8_t index; 50 51 private: 52 std::vector<OutputSection *> sections; 53 }; 54 55 extern std::vector<OutputSegment *> outputSegments; 56 57 OutputSegment *getOrCreateOutputSegment(StringRef name); 58 59 } // namespace macho 60 } // namespace lld 61 62 #endif 63