1 //===- OutputSection.h ------------------------------------------*- C++ -*-===//
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
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"
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.
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;
59 OutputSegment
*parent
= nullptr;
66 uint32_t reserved1
= 0;
67 uint32_t reserved2
= 0;