2014-01-04 07:12:02 +08:00
|
|
|
//===- 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"
|
|
|
|
|
2014-06-12 05:47:51 +08:00
|
|
|
#include "lld/Core/Simple.h"
|
2014-01-04 07:12:02 +08:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace mach_o {
|
|
|
|
|
|
|
|
class MachOFile : public SimpleFile {
|
|
|
|
public:
|
|
|
|
MachOFile(StringRef path) : SimpleFile(path) {}
|
|
|
|
|
2014-05-16 07:03:50 +08:00
|
|
|
void addDefinedAtom(StringRef name, Atom::Scope scope,
|
2014-05-28 09:16:35 +08:00
|
|
|
DefinedAtom::ContentType type, DefinedAtom::Merge merge,
|
2014-05-16 07:03:50 +08:00
|
|
|
ArrayRef<uint8_t> content, bool copyRefs) {
|
2014-01-14 06:28:02 +08:00
|
|
|
if (copyRefs) {
|
2014-01-11 09:07:43 +08:00
|
|
|
// Make a copy of the atom's name and content that is owned by this file.
|
2014-02-07 07:48:52 +08:00
|
|
|
name = name.copy(_allocator);
|
|
|
|
content = content.copy(_allocator);
|
2014-01-11 09:07:43 +08:00
|
|
|
}
|
2014-01-04 07:12:02 +08:00
|
|
|
MachODefinedAtom *atom =
|
2014-05-28 09:16:35 +08:00
|
|
|
new (_allocator) MachODefinedAtom(*this, name, scope, type, merge,
|
|
|
|
content);
|
2014-05-16 07:03:50 +08:00
|
|
|
addAtom(*atom);
|
|
|
|
}
|
|
|
|
|
2014-05-31 06:51:04 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-05-16 07:03:50 +08:00
|
|
|
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);
|
2014-01-04 07:12:02 +08:00
|
|
|
addAtom(*atom);
|
|
|
|
}
|
|
|
|
|
2014-02-03 03:34:55 +08:00
|
|
|
void addUndefinedAtom(StringRef name, bool copyRefs) {
|
|
|
|
if (copyRefs) {
|
2014-02-07 07:48:52 +08:00
|
|
|
// Make a copy of the atom's name that is owned by this file.
|
|
|
|
name = name.copy(_allocator);
|
2014-02-03 03:34:55 +08:00
|
|
|
}
|
|
|
|
SimpleUndefinedAtom *atom =
|
|
|
|
new (_allocator) SimpleUndefinedAtom(*this, name);
|
|
|
|
addAtom(*atom);
|
|
|
|
}
|
|
|
|
|
2014-05-16 04:59:23 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-04 07:12:02 +08:00
|
|
|
private:
|
|
|
|
llvm::BumpPtrAllocator _allocator;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace mach_o
|
|
|
|
} // end namespace lld
|
|
|
|
|
|
|
|
#endif
|