1 //===- InputSection.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_INPUT_SECTION_H
10 #define LLD_MACHO_INPUT_SECTION_H
12 #include "lld/Common/LLVM.h"
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/PointerUnion.h"
15 #include "llvm/BinaryFormat/MachO.h"
29 // The offset from the start of the subsection that this relocation belongs
32 // Adding this offset to the address of the target symbol or subsection gives
33 // the destination that this relocation refers to.
35 llvm::PointerUnion
<Symbol
*, InputSection
*> target
;
38 inline bool isZeroFill(uint8_t flags
) {
39 return (flags
& llvm::MachO::SECTION_TYPE
) == llvm::MachO::S_ZEROFILL
;
44 virtual ~InputSection() = default;
45 virtual uint64_t getSize() const { return data
.size(); }
46 virtual uint64_t getFileSize() const {
47 return isZeroFill(flags
) ? 0 : getSize();
49 uint64_t getFileOffset() const;
50 uint64_t getVA() const;
52 virtual void writeTo(uint8_t *buf
);
54 InputFile
*file
= nullptr;
58 OutputSection
*parent
= nullptr;
59 uint64_t outSecOff
= 0;
60 uint64_t outSecFileOff
= 0;
65 ArrayRef
<uint8_t> data
;
66 std::vector
<Reloc
> relocs
;
69 extern std::vector
<InputSection
*> inputSections
;