[Dexter][NFC] Add Missing Commands to Commands.md Contents
[llvm-project.git] / lld / MachO / OutputSection.h
blobc526a8343afe1b2a1062c2bf5ed899b48fdb826c
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 //===----------------------------------------------------------------------===//
9 #ifndef LLD_MACHO_OUTPUT_SECTION_H
10 #define LLD_MACHO_OUTPUT_SECTION_H
12 #include "lld/Common/LLVM.h"
13 #include "llvm/ADT/DenseMap.h"
15 namespace lld {
16 namespace macho {
18 class InputSection;
19 class OutputSegment;
21 // Output sections represent the finalized sections present within the final
22 // linked executable. They can represent special sections (like the symbol
23 // table), or represent coalesced sections from the various inputs given to the
24 // linker with the same segment / section name.
25 class OutputSection {
26 public:
27 enum Kind {
28 MergedKind,
29 SyntheticKind,
32 OutputSection(Kind kind, StringRef name) : name(name), sectionKind(kind) {}
33 virtual ~OutputSection() = default;
34 Kind kind() const { return sectionKind; }
36 // These accessors will only be valid after finalizing the section.
37 uint64_t getSegmentOffset() const;
39 // How much space the section occupies in the address space.
40 virtual uint64_t getSize() const = 0;
41 // How much space the section occupies in the file. Most sections are copied
42 // as-is so their file size is the same as their address space size.
43 virtual uint64_t getFileSize() const { return getSize(); }
45 // Hidden sections omit header content, but body content may still be present.
46 virtual bool isHidden() const { return false; }
47 // Unneeded sections are omitted entirely (header and body).
48 virtual bool isNeeded() const { return true; }
50 // Specifically finalizes addresses and section size, not content.
51 virtual void finalize() {
52 // TODO investigate refactoring synthetic section finalization logic into
53 // overrides of this function.
56 virtual void writeTo(uint8_t *buf) const = 0;
58 StringRef name;
59 OutputSegment *parent = nullptr;
61 uint32_t index = 0;
62 uint64_t addr = 0;
63 uint64_t fileOff = 0;
64 uint32_t align = 1;
65 uint32_t flags = 0;
66 uint32_t reserved1 = 0;
67 uint32_t reserved2 = 0;
69 private:
70 Kind sectionKind;
73 } // namespace macho
74 } // namespace lld
76 #endif