173
|
1 //===- OutputSection.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_SECTION_H
|
|
10 #define LLD_MACHO_OUTPUT_SECTION_H
|
|
11
|
|
12 #include "lld/Common/LLVM.h"
|
|
13 #include "llvm/ADT/DenseMap.h"
|
|
14
|
221
|
15 #include <limits>
|
|
16
|
173
|
17 namespace lld {
|
|
18 namespace macho {
|
|
19
|
|
20 class InputSection;
|
|
21 class OutputSegment;
|
|
22
|
223
|
23 // The default order value for OutputSections that are not constructed from
|
|
24 // InputSections (i.e. SyntheticSections). We make it less than INT_MAX in order
|
|
25 // not to conflict with the ordering of zerofill sections, which must always be
|
|
26 // placed at the end of their segment.
|
|
27 constexpr int UnspecifiedInputOrder = std::numeric_limits<int>::max() - 1024;
|
|
28
|
173
|
29 // Output sections represent the finalized sections present within the final
|
|
30 // linked executable. They can represent special sections (like the symbol
|
|
31 // table), or represent coalesced sections from the various inputs given to the
|
|
32 // linker with the same segment / section name.
|
|
33 class OutputSection {
|
|
34 public:
|
|
35 enum Kind {
|
221
|
36 ConcatKind,
|
173
|
37 SyntheticKind,
|
|
38 };
|
|
39
|
|
40 OutputSection(Kind kind, StringRef name) : name(name), sectionKind(kind) {}
|
|
41 virtual ~OutputSection() = default;
|
|
42 Kind kind() const { return sectionKind; }
|
|
43
|
|
44 // These accessors will only be valid after finalizing the section.
|
|
45 uint64_t getSegmentOffset() const;
|
|
46
|
|
47 // How much space the section occupies in the address space.
|
221
|
48 virtual uint64_t getSize() const = 0;
|
173
|
49 // How much space the section occupies in the file. Most sections are copied
|
|
50 // as-is so their file size is the same as their address space size.
|
|
51 virtual uint64_t getFileSize() const { return getSize(); }
|
|
52
|
|
53 // Hidden sections omit header content, but body content may still be present.
|
|
54 virtual bool isHidden() const { return false; }
|
|
55 // Unneeded sections are omitted entirely (header and body).
|
|
56 virtual bool isNeeded() const { return true; }
|
|
57
|
|
58 virtual void finalize() {
|
|
59 // TODO investigate refactoring synthetic section finalization logic into
|
|
60 // overrides of this function.
|
|
61 }
|
|
62
|
|
63 virtual void writeTo(uint8_t *buf) const = 0;
|
|
64
|
|
65 StringRef name;
|
|
66 OutputSegment *parent = nullptr;
|
221
|
67 // For output sections that don't have explicit ordering requirements, their
|
|
68 // output order should be based on the order of the input sections they
|
|
69 // contain.
|
223
|
70 int inputOrder = UnspecifiedInputOrder;
|
173
|
71
|
|
72 uint32_t index = 0;
|
|
73 uint64_t addr = 0;
|
|
74 uint64_t fileOff = 0;
|
|
75 uint32_t align = 1;
|
|
76 uint32_t flags = 0;
|
221
|
77 uint32_t reserved1 = 0;
|
|
78 uint32_t reserved2 = 0;
|
173
|
79
|
|
80 private:
|
|
81 Kind sectionKind;
|
|
82 };
|
|
83
|
|
84 } // namespace macho
|
|
85 } // namespace lld
|
|
86
|
|
87 #endif
|