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 constexpr const char ld[] = "__LD"; // output only with -r 26 constexpr const char dwarf[] = "__DWARF"; 27 28 } // namespace segment_names 29 30 class OutputSection; 31 class InputSection; 32 33 class OutputSegment { 34 public: firstSection()35 const OutputSection *firstSection() const { return sections.front(); } lastSection()36 const OutputSection *lastSection() const { return sections.back(); } 37 38 void addOutputSection(OutputSection *os); sortOutputSections(llvm::function_ref<bool (OutputSection *,OutputSection *)> comparator)39 void sortOutputSections( 40 llvm::function_ref<bool(OutputSection *, OutputSection *)> comparator) { 41 llvm::stable_sort(sections, comparator); 42 } 43 getSections()44 const std::vector<OutputSection *> &getSections() const { return sections; } 45 size_t numNonHiddenSections() const; 46 47 uint64_t fileOff = 0; 48 StringRef name; 49 uint32_t maxProt = 0; 50 uint32_t initProt = 0; 51 uint8_t index; 52 53 private: 54 std::vector<OutputSection *> sections; 55 }; 56 57 extern std::vector<OutputSegment *> outputSegments; 58 59 OutputSegment *getOrCreateOutputSegment(StringRef name); 60 61 } // namespace macho 62 } // namespace lld 63 64 #endif 65