summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2016-07-11 23:10:18 +0000
committerMehdi Amini <mehdi.amini@apple.com>2016-07-11 23:10:18 +0000
commit45e997da60432acabe2118fa68c56a44504645e9 (patch)
tree07a4ec304475867a7a930e9c78b118aa430db69a /tools
parent9e937064ea231bceb6ca13df6dd09e6cbeaeb6aa (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275125 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/llvm-lto/llvm-lto.cpp19
-rw-r--r--tools/lto/lto.cpp9
-rw-r--r--tools/lto/lto.exports1
3 files changed, 29 insertions, 0 deletions
diff --git a/tools/llvm-lto/llvm-lto.cpp b/tools/llvm-lto/llvm-lto.cpp
index f3c6c62d496..84dce23aee2 100644
--- a/tools/llvm-lto/llvm-lto.cpp
+++ b/tools/llvm-lto/llvm-lto.cpp
@@ -156,6 +156,10 @@ static cl::opt<bool> RestoreGlobalsLinkage(
"restore-linkage", cl::init(false),
cl::desc("Restore original linkage of globals prior to CodeGen"));
+static cl::opt<bool> CheckHasObjC(
+ "check-for-objc", cl::init(false),
+ cl::desc("Only check if the module has objective-C defined in it"));
+
namespace {
struct ModuleInfo {
std::vector<bool> CanBeHidden;
@@ -714,6 +718,21 @@ int main(int argc, char **argv) {
return 0;
}
+ if (CheckHasObjC) {
+ for (auto &Filename : InputFilenames) {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
+ MemoryBuffer::getFile(Filename);
+ error(BufferOrErr, "error loading file '" + Filename + "'");
+ auto Buffer = std::move(BufferOrErr.get());
+ LLVMContext Ctx;
+ if (llvm::isBitcodeContainingObjCCategory(*Buffer, Ctx))
+ outs() << "Bitcode " << Filename << " contains ObjC\n";
+ else
+ outs() << "Bitcode " << Filename << " does not contain ObjC\n";
+ }
+ return 0;
+ }
+
if (ThinLTOMode.getNumOccurrences()) {
if (ThinLTOMode.getNumOccurrences() > 1)
report_fatal_error("You can't specify more than one -thinlto-action");
diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp
index e69f360b074..0c36c99c07f 100644
--- a/tools/lto/lto.cpp
+++ b/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 @@ bool lto_module_is_object_file_for_target(const char* path,
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);
}
diff --git a/tools/lto/lto.exports b/tools/lto/lto.exports
index 83a59437e81..74091c2641b 100644
--- a/tools/lto/lto.exports
+++ b/tools/lto/lto.exports
@@ -18,6 +18,7 @@ lto_module_is_object_file
lto_module_is_object_file_for_target
lto_module_is_object_file_in_memory
lto_module_is_object_file_in_memory_for_target
+lto_module_has_objc_category
lto_module_dispose
lto_api_version
lto_codegen_set_diagnostic_handler