summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/File.h
diff options
context:
space:
mode:
authorNick Kledzik <kledzik@apple.com>2014-01-11 01:07:43 +0000
committerNick Kledzik <kledzik@apple.com>2014-01-11 01:07:43 +0000
commit6edd722a2cff95551808ee02e69c8882633f6283 (patch)
tree8c61a8d6616a054d236b88ef99023d313fe5aa1e /lld/lib/ReaderWriter/MachO/File.h
parent976d94b834c08251b240b059700498cb9a5791ec (diff)
downloadbcm5719-llvm-6edd722a2cff95551808ee02e69c8882633f6283.tar.gz
bcm5719-llvm-6edd722a2cff95551808ee02e69c8882633f6283.zip
[mach-o] enable mach-o and native yaml to be intermixed
The main goal of this patch is to allow "mach-o encoded as yaml" and "native encoded as yaml" documents to be intermixed. They are distinguished via yaml tags at the start of the document. This will enable all mach-o test cases to be written using yaml instead of checking in object files. The Registry was extend to allow yaml tag handlers to be registered. The mach-o Reader adds a yaml tag handler for the tag "!mach-o". Additionally, this patch fixes some buffer ownership issues. When parsing mach-o binaries, the mach-o atoms can have pointers back into the memory mapped .o file. But with yaml encoded mach-o, name and content are ephemeral, so a copyRefs parameter was added to cause the mach-o atoms to make their own copy. llvm-svn: 198986
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/File.h')
-rw-r--r--lld/lib/ReaderWriter/MachO/File.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/lld/lib/ReaderWriter/MachO/File.h b/lld/lib/ReaderWriter/MachO/File.h
index e002a93e4b4..dad5462c098 100644
--- a/lld/lib/ReaderWriter/MachO/File.h
+++ b/lld/lib/ReaderWriter/MachO/File.h
@@ -21,7 +21,16 @@ class MachOFile : public SimpleFile {
public:
MachOFile(StringRef path) : SimpleFile(path) {}
- void addDefinedAtom(StringRef name, ArrayRef<uint8_t> content) {
+ void addDefinedAtom(StringRef name, ArrayRef<uint8_t> content, bool cpyRefs) {
+ if (cpyRefs) {
+ // Make a copy of the atom's name and content that is owned by this file.
+ char *s = _allocator.Allocate<char>(name.size());
+ memcpy(s, name.data(), name.size());
+ name = StringRef(s, name.size());
+ uint8_t *bytes = _allocator.Allocate<uint8_t>(content.size());
+ memcpy(bytes, content.data(), content.size());
+ content = llvm::makeArrayRef(bytes, content.size());
+ }
MachODefinedAtom *atom =
new (_allocator) MachODefinedAtom(*this, name, content);
addAtom(*atom);
OpenPOWER on IntegriCloud