Start adding support for generating CC1 command lines from CompilerInvocation
[llvm-project.git] / lld / MachO / InputSection.h
blob96ae0cbe6ea44207a32f6292b4fa42e7bb422a65
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 //===----------------------------------------------------------------------===//
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"
17 namespace lld {
18 namespace macho {
20 class InputFile;
21 class InputSection;
22 class OutputSection;
23 class Symbol;
25 struct Reloc {
26 uint8_t type;
27 bool pcrel;
28 uint8_t length;
29 // The offset from the start of the subsection that this relocation belongs
30 // to.
31 uint32_t offset;
32 // Adding this offset to the address of the target symbol or subsection gives
33 // the destination that this relocation refers to.
34 uint64_t addend;
35 llvm::PointerUnion<Symbol *, InputSection *> target;
38 inline bool isZeroFill(uint8_t flags) {
39 return (flags & llvm::MachO::SECTION_TYPE) == llvm::MachO::S_ZEROFILL;
42 class InputSection {
43 public:
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;
55 StringRef name;
56 StringRef segname;
58 OutputSection *parent = nullptr;
59 uint64_t outSecOff = 0;
60 uint64_t outSecFileOff = 0;
62 uint32_t align = 1;
63 uint32_t flags = 0;
65 ArrayRef<uint8_t> data;
66 std::vector<Reloc> relocs;
69 extern std::vector<InputSection *> inputSections;
71 } // namespace macho
72 } // namespace lld
74 #endif