1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
//===- lib/ReaderWriter/MachO/File.h --------------------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_READER_WRITER_MACHO_FILE_H
#define LLD_READER_WRITER_MACHO_FILE_H
#include "Atoms.h"
#include "lld/ReaderWriter/Simple.h"
namespace lld {
namespace mach_o {
class MachOFile : public SimpleFile {
public:
MachOFile(StringRef path) : SimpleFile(path) {}
void addDefinedAtom(StringRef name, Atom::Scope scope,
DefinedAtom::ContentType type, DefinedAtom::Merge merge,
ArrayRef<uint8_t> content, bool copyRefs) {
if (copyRefs) {
// Make a copy of the atom's name and content that is owned by this file.
name = name.copy(_allocator);
content = content.copy(_allocator);
}
MachODefinedAtom *atom =
new (_allocator) MachODefinedAtom(*this, name, scope, type, merge,
content);
addAtom(*atom);
}
void addDefinedAtomInCustomSection(StringRef name, Atom::Scope scope,
DefinedAtom::ContentType type, DefinedAtom::Merge merge,
ArrayRef<uint8_t> content, StringRef sectionName,
bool copyRefs) {
if (copyRefs) {
// Make a copy of the atom's name and content that is owned by this file.
name = name.copy(_allocator);
content = content.copy(_allocator);
sectionName = sectionName.copy(_allocator);
}
MachODefinedCustomSectionAtom *atom =
new (_allocator) MachODefinedCustomSectionAtom(*this, name, scope, type,
merge, content, sectionName);
addAtom(*atom);
}
void addZeroFillDefinedAtom(StringRef name, Atom::Scope scope, uint64_t size,
bool copyRefs) {
if (copyRefs) {
// Make a copy of the atom's name and content that is owned by this file.
name = name.copy(_allocator);
}
MachODefinedAtom *atom =
new (_allocator) MachODefinedAtom(*this, name, scope, size);
addAtom(*atom);
}
void addUndefinedAtom(StringRef name, bool copyRefs) {
if (copyRefs) {
// Make a copy of the atom's name that is owned by this file.
name = name.copy(_allocator);
}
SimpleUndefinedAtom *atom =
new (_allocator) SimpleUndefinedAtom(*this, name);
addAtom(*atom);
}
void addTentativeDefAtom(StringRef name, Atom::Scope scope, uint64_t size,
DefinedAtom::Alignment align, bool copyRefs) {
if (copyRefs) {
// Make a copy of the atom's name that is owned by this file.
name = name.copy(_allocator);
}
MachOTentativeDefAtom *atom =
new (_allocator) MachOTentativeDefAtom(*this, name, scope, size, align);
addAtom(*atom);
}
private:
llvm::BumpPtrAllocator _allocator;
};
} // end namespace mach_o
} // end namespace lld
#endif
|