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