*/
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.
*
#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;
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();