xref: /openbsd/gnu/llvm/lld/MachO/OutputSegment.h (revision dfe94b16)
1bb684c34Spatrick //===- OutputSegment.h ------------------------------------------*- C++ -*-===//
2bb684c34Spatrick //
3bb684c34Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4bb684c34Spatrick // See https://llvm.org/LICENSE.txt for license information.
5bb684c34Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6bb684c34Spatrick //
7bb684c34Spatrick //===----------------------------------------------------------------------===//
8bb684c34Spatrick 
9bb684c34Spatrick #ifndef LLD_MACHO_OUTPUT_SEGMENT_H
10bb684c34Spatrick #define LLD_MACHO_OUTPUT_SEGMENT_H
11bb684c34Spatrick 
12bb684c34Spatrick #include "OutputSection.h"
131cf9926bSpatrick #include "Symbols.h"
14bb684c34Spatrick #include "lld/Common/LLVM.h"
151cf9926bSpatrick #include "llvm/ADT/TinyPtrVector.h"
161cf9926bSpatrick 
171cf9926bSpatrick #include <limits>
181cf9926bSpatrick #include <vector>
19bb684c34Spatrick 
20*dfe94b16Srobert namespace lld::macho {
21bb684c34Spatrick 
22bb684c34Spatrick namespace segment_names {
23bb684c34Spatrick 
24bb684c34Spatrick constexpr const char dataConst[] = "__DATA_CONST";
251cf9926bSpatrick constexpr const char dataDirty[] = "__DATA_DIRTY";
261cf9926bSpatrick constexpr const char data[] = "__DATA";
271cf9926bSpatrick constexpr const char dwarf[] = "__DWARF";
281cf9926bSpatrick constexpr const char import[] = "__IMPORT";
291cf9926bSpatrick constexpr const char ld[] = "__LD"; // output only with -r
301cf9926bSpatrick constexpr const char linkEdit[] = "__LINKEDIT";
311cf9926bSpatrick constexpr const char llvm[] = "__LLVM";
321cf9926bSpatrick constexpr const char pageZero[] = "__PAGEZERO";
331cf9926bSpatrick constexpr const char textExec[] = "__TEXT_EXEC";
341cf9926bSpatrick constexpr const char text[] = "__TEXT";
35bb684c34Spatrick 
36bb684c34Spatrick } // namespace segment_names
37bb684c34Spatrick 
38bb684c34Spatrick class OutputSection;
39bb684c34Spatrick class InputSection;
40bb684c34Spatrick 
41bb684c34Spatrick class OutputSegment {
42bb684c34Spatrick public:
43bb684c34Spatrick   void addOutputSection(OutputSection *os);
441cf9926bSpatrick   void sortOutputSections();
451cf9926bSpatrick   void assignAddressesToStartEndSymbols();
46bb684c34Spatrick 
getSections()47bb684c34Spatrick   const std::vector<OutputSection *> &getSections() const { return sections; }
48bb684c34Spatrick   size_t numNonHiddenSections() const;
49bb684c34Spatrick 
50bb684c34Spatrick   uint64_t fileOff = 0;
511cf9926bSpatrick   uint64_t fileSize = 0;
521cf9926bSpatrick   uint64_t addr = 0;
531cf9926bSpatrick   uint64_t vmSize = 0;
541cf9926bSpatrick   int inputOrder = UnspecifiedInputOrder;
55bb684c34Spatrick   StringRef name;
56bb684c34Spatrick   uint32_t maxProt = 0;
57bb684c34Spatrick   uint32_t initProt = 0;
58*dfe94b16Srobert   uint32_t flags = 0;
59bb684c34Spatrick   uint8_t index;
60bb684c34Spatrick 
611cf9926bSpatrick   llvm::TinyPtrVector<Defined *> segmentStartSymbols;
621cf9926bSpatrick   llvm::TinyPtrVector<Defined *> segmentEndSymbols;
631cf9926bSpatrick 
64bb684c34Spatrick private:
65bb684c34Spatrick   std::vector<OutputSection *> sections;
66bb684c34Spatrick };
67bb684c34Spatrick 
68bb684c34Spatrick extern std::vector<OutputSegment *> outputSegments;
69bb684c34Spatrick 
701cf9926bSpatrick void sortOutputSegments();
71*dfe94b16Srobert void resetOutputSegments();
721cf9926bSpatrick 
73bb684c34Spatrick OutputSegment *getOrCreateOutputSegment(StringRef name);
74bb684c34Spatrick 
75*dfe94b16Srobert } // namespace lld::macho
76bb684c34Spatrick 
77bb684c34Spatrick #endif
78