1 //===- InputSection.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_INPUT_SECTION_H 10 #define LLD_MACHO_INPUT_SECTION_H 11 12 #include "lld/Common/LLVM.h" 13 #include "llvm/ADT/ArrayRef.h" 14 #include "llvm/ADT/PointerUnion.h" 15 #include "llvm/BinaryFormat/MachO.h" 16 17 namespace lld { 18 namespace macho { 19 20 class InputFile; 21 class InputSection; 22 class OutputSegment; 23 class Symbol; 24 25 struct Reloc { 26 uint8_t type; 27 uint32_t addend; 28 uint32_t offset; 29 llvm::PointerUnion<Symbol *, InputSection *> target; 30 }; 31 32 class InputSection { 33 public: 34 virtual ~InputSection() = default; 35 virtual size_t getSize() const { return data.size(); } 36 virtual uint64_t getFileSize() const { return getSize(); } 37 uint64_t getFileOffset() const; 38 // Don't emit section_64 headers for hidden sections. 39 virtual bool isHidden() const { return false; } 40 // Unneeded sections are omitted entirely (header and body). 41 virtual bool isNeeded() const { return true; } 42 virtual void writeTo(uint8_t *buf); 43 44 InputFile *file = nullptr; 45 OutputSegment *parent = nullptr; 46 StringRef name; 47 StringRef segname; 48 49 ArrayRef<uint8_t> data; 50 51 // TODO these properties ought to live in an OutputSection class. 52 // Move them once available. 53 uint64_t addr = 0; 54 uint32_t align = 1; 55 uint32_t sectionIndex = 0; 56 uint32_t flags = 0; 57 58 std::vector<Reloc> relocs; 59 }; 60 61 extern std::vector<InputSection *> inputSections; 62 63 } // namespace macho 64 } // namespace lld 65 66 #endif 67