[llvm] r361705 - [LLVM-C] Add Accessor for Mach-O Universal Binary Slices
Robert Widmann via llvm-commits
llvm-commits at lists.llvm.org
Sat May 25 09:47:28 PDT 2019
Author: codafi
Date: Sat May 25 09:47:27 2019
New Revision: 361705
URL: http://llvm.org/viewvc/llvm-project?rev=361705&view=rev
Log:
[LLVM-C] Add Accessor for Mach-O Universal Binary Slices
Summary: Allow for retrieving an object file corresponding to an architecture-specific slice in a Mach-O universal binary file.
Reviewers: whitequark, deadalnix
Reviewed By: whitequark
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60378
Modified:
llvm/trunk/include/llvm-c/Object.h
llvm/trunk/lib/Object/Object.cpp
Modified: llvm/trunk/include/llvm-c/Object.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Object.h?rev=361705&r1=361704&r2=361705&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Object.h (original)
+++ llvm/trunk/include/llvm-c/Object.h Sat May 25 09:47:27 2019
@@ -102,6 +102,22 @@ LLVMMemoryBufferRef LLVMBinaryCopyMemory
*/
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);
+
/**
* Retrieve a copy of the section iterator for this object file.
*
Modified: llvm/trunk/lib/Object/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Object.cpp?rev=361705&r1=361704&r2=361705&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Object.cpp (original)
+++ llvm/trunk/lib/Object/Object.cpp Sat May 25 09:47:27 2019
@@ -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 @@ LLVMBinaryType LLVMBinaryGetType(LLVMBin
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());
+}
+
LLVMSectionIteratorRef LLVMObjectFileCopySectionIterator(LLVMBinaryRef BR) {
auto OF = cast<ObjectFile>(unwrap(BR));
auto sections = OF->sections();
More information about the llvm-commits
mailing list