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 "Relocations.h"
13
14#include "lld/Common/LLVM.h"
15#include "llvm/ADT/ArrayRef.h"
16#include "llvm/BinaryFormat/MachO.h"
17
18namespace lld {
19namespace macho {
20
21class InputFile;
22class InputSection;
23class OutputSection;
24class Symbol;
25class Defined;
26
27class InputSection {
28public:
29 virtual ~InputSection() = default;
30 virtual uint64_t getSize() const { return data.size(); }
31 virtual uint64_t getFileSize() const;
32 uint64_t getFileOffset() const;
33 uint64_t getVA() const;
34
35 virtual void writeTo(uint8_t *buf);
36
37 InputFile *file = nullptr;
38 StringRef name;
39 StringRef segname;
40
41 OutputSection *parent = nullptr;
42 uint64_t outSecOff = 0;
43 uint64_t outSecFileOff = 0;
44
45 uint32_t align = 1;
46 uint32_t flags = 0;
47
48 ArrayRef<uint8_t> data;
49 std::vector<Reloc> relocs;
50};
51
52inline uint8_t sectionType(uint32_t flags) {
53 return flags & llvm::MachO::SECTION_TYPE;
54}
55
56inline bool isZeroFill(uint32_t flags) {
57 return llvm::MachO::isVirtualSection(sectionType(flags));
58}
59
60inline bool isThreadLocalVariables(uint32_t flags) {
61 return sectionType(flags) == llvm::MachO::S_THREAD_LOCAL_VARIABLES;
62}
63
64// These sections contain the data for initializing thread-local variables.
65inline bool isThreadLocalData(uint32_t flags) {
66 return sectionType(flags) == llvm::MachO::S_THREAD_LOCAL_REGULAR ||
67 sectionType(flags) == llvm::MachO::S_THREAD_LOCAL_ZEROFILL;
68}
69
70inline bool isDebugSection(uint32_t flags) {
71 return (flags & llvm::MachO::SECTION_ATTRIBUTES_USR) ==
72 llvm::MachO::S_ATTR_DEBUG;
73}
74
75bool isCodeSection(InputSection *);
76
77extern std::vector<InputSection *> inputSections;
78
79namespace section_names {
80
81constexpr const char authGot[] = "__auth_got";
82constexpr const char authPtr[] = "__auth_ptr";
83constexpr const char binding[] = "__binding";
84constexpr const char bitcodeBundle[] = "__bundle";
85constexpr const char cfString[] = "__cfstring";
86constexpr const char codeSignature[] = "__code_signature";
87constexpr const char common[] = "__common";
88constexpr const char compactUnwind[] = "__compact_unwind";
89constexpr const char data[] = "__data";
90constexpr const char debugAbbrev[] = "__debug_abbrev";
91constexpr const char debugInfo[] = "__debug_info";
92constexpr const char debugStr[] = "__debug_str";
93constexpr const char ehFrame[] = "__eh_frame";
94constexpr const char export_[] = "__export";
95constexpr const char functionStarts[] = "__func_starts";
96constexpr const char got[] = "__got";
97constexpr const char header[] = "__mach_header";
98constexpr const char indirectSymbolTable[] = "__ind_sym_tab";
99constexpr const char const_[] = "__const";
100constexpr const char lazySymbolPtr[] = "__la_symbol_ptr";
101constexpr const char lazyBinding[] = "__lazy_binding";
102constexpr const char moduleInitFunc[] = "__mod_init_func";
103constexpr const char moduleTermFunc[] = "__mod_term_func";
104constexpr const char nonLazySymbolPtr[] = "__nl_symbol_ptr";
105constexpr const char objcCatList[] = "__objc_catlist";
106constexpr const char objcClassList[] = "__objc_classlist";
107constexpr const char objcConst[] = "__objc_const";
108constexpr const char objcImageInfo[] = "__objc_imageinfo";
109constexpr const char objcNonLazyCatList[] = "__objc_nlcatlist";
110constexpr const char objcNonLazyClassList[] = "__objc_nlclslist";
111constexpr const char objcProtoList[] = "__objc_protolist";
112constexpr const char pageZero[] = "__pagezero";
113constexpr const char pointers[] = "__pointers";
114constexpr const char rebase[] = "__rebase";
115constexpr const char staticInit[] = "__StaticInit";
116constexpr const char stringTable[] = "__string_table";
117constexpr const char stubHelper[] = "__stub_helper";
118constexpr const char stubs[] = "__stubs";
119constexpr const char swift[] = "__swift";
120constexpr const char symbolTable[] = "__symbol_table";
121constexpr const char textCoalNt[] = "__textcoal_nt";
122constexpr const char text[] = "__text";
123constexpr const char threadPtrs[] = "__thread_ptrs";
124constexpr const char threadVars[] = "__thread_vars";
125constexpr const char unwindInfo[] = "__unwind_info";
126constexpr const char weakBinding[] = "__weak_binding";
127constexpr const char zeroFill[] = "__zerofill";
128
129} // namespace section_names
130
131} // namespace macho
132
133std::string toString(const macho::InputSection *);
134
135} // namespace lld
136
137#endif
138