Add a libLTO API to query a memory buffer and check if it contains ObjC categories
The linker supports a feature to force load an object from a static
archive if it defines an Objective-C category.
This API supports this feature by looking at every section in the
module to find if a category is defined in the module.
llvm-svn: 275125
diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index e69f360..0c36c99 100644
--- a/llvm/tools/lto/lto.cpp
+++ b/llvm/tools/lto/lto.cpp
@@ -14,6 +14,7 @@
#include "llvm-c/lto.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/CodeGen/CommandFlags.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
@@ -180,6 +181,14 @@
return LTOModule::isBitcodeForTarget(Buffer->get(), target_triplet_prefix);
}
+bool lto_module_has_objc_category(const void *mem, size_t length) {
+ std::unique_ptr<MemoryBuffer> Buffer(LTOModule::makeBuffer(mem, length));
+ if (!Buffer)
+ return false;
+ LLVMContext Ctx;
+ return llvm::isBitcodeContainingObjCCategory(*Buffer, Ctx);
+}
+
bool lto_module_is_object_file_in_memory(const void* mem, size_t length) {
return LTOModule::isBitcodeFile(mem, length);
}