[PATCH] D60378: [LLVM-C] Add Accessor for Mach-O Universal Binary Slices
Robert Widmann via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 7 11:23:33 PDT 2019
CodaFi created this revision.
CodaFi added reviewers: whitequark, deadalnix.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
Allow for retrieving an object file corresponding to an architecture-specific slice in a Mach-O universal binary file.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D60378
Files:
llvm/include/llvm-c/Object.h
llvm/lib/Object/Object.cpp
Index: llvm/lib/Object/Object.cpp
===================================================================
--- llvm/lib/Object/Object.cpp
+++ llvm/lib/Object/Object.cpp
@@ -15,6 +15,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Object/ObjectFile.h"
+#include "llvm/Object/MachOUniversal.h"
using namespace llvm;
using namespace object;
@@ -131,6 +132,20 @@
return BinaryTypeMapper::mapBinaryTypeToLLVMBinaryType(unwrap(BR)->getType());
}
+LLVMBinaryRef LLVMMachOUniversalBinaryCopyObjectForArch(LLVMBinaryRef BR,
+ const char *Arch,
+ size_t ArchLen,
+ char **ErrorMessage) {
+ auto universal = cast<MachOUniversalBinary>(unwrap(BR));
+ Expected<std::unique_ptr<ObjectFile>> ObjOrErr(
+ universal->getObjectForArch({Arch, ArchLen}));
+ if (!ObjOrErr) {
+ *ErrorMessage = strdup(toString(ObjOrErr.takeError()).c_str());
+ return nullptr;
+ }
+ return wrap(ObjOrErr.get().release());
+}
+
// ObjectFile creation
LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) {
std::unique_ptr<MemoryBuffer> Buf(unwrap(MemBuf));
Index: llvm/include/llvm-c/Object.h
===================================================================
--- llvm/include/llvm-c/Object.h
+++ llvm/include/llvm-c/Object.h
@@ -103,6 +103,21 @@
*/
LLVMBinaryType LLVMBinaryGetType(LLVMBinaryRef BR);
+/*
+ * For a Mach-O universal binary file, retrieves the object file corresponding
+ * to the given architecture if it is present as a slice.
+ *
+ * If NULL is returned, the \p ErrorMessage parameter is populated with the
+ * error's description. It is then the caller's responsibility to free this
+ * message by calling \c LLVMDisposeMessage.
+ *
+ * It is the responsiblity of the caller to free the returned object file by
+ * calling \c LLVMDisposeBinary.
+ */
+LLVMBinaryRef LLVMMachOUniversalBinaryCopyObjectForArch(LLVMBinaryRef BR,
+ const char *Arch,
+ size_t ArchLen,
+ char **ErrorMessage);
// ObjectFile creation
LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60378.194065.patch
Type: text/x-patch
Size: 2382 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190407/81b56821/attachment.bin>
More information about the llvm-commits
mailing list