summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2014-05-13 22:37:41 +0000
committerLang Hames <lhames@gmail.com>2014-05-13 22:37:41 +0000
commitd311c0ea46b3baf9bc1332646513a87d0b94befb (patch)
tree0a8e6a2fc3f77676267237b90d7eaa0959f15b54 /llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
parent5716928ae2203f6ede337db2c7d86dc906a91027 (diff)
downloadbcm5719-llvm-d311c0ea46b3baf9bc1332646513a87d0b94befb.tar.gz
bcm5719-llvm-d311c0ea46b3baf9bc1332646513a87d0b94befb.zip
[tools][llvm-rtdyld] Add a '-dylib <file>' option to llvm-rtdyld to load shared
libraries before linking and executing the target objects. This allows programs that use external calls (e.g. to libc) to be run under llvm-rtdyld. llvm-svn: 208739
Diffstat (limited to 'llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp')
-rw-r--r--llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
index 2cea30cabde..be5c345c617 100644
--- a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
+++ b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
@@ -18,6 +18,7 @@
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/Object/MachO.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Memory.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -51,6 +52,11 @@ EntryPoint("entry",
cl::desc("Function to call as entry point."),
cl::init("_main"));
+static cl::list<std::string>
+Dylibs("dylib",
+ cl::desc("Add library."),
+ cl::ZeroOrMore);
+
/* *** */
// A trivial memory manager that doesn't do anything fancy, just uses the
@@ -121,9 +127,25 @@ static int Error(const Twine &Msg) {
return 1;
}
+static void loadDylibs() {
+ for (const std::string &Dylib : Dylibs) {
+ if (sys::fs::is_regular_file(Dylib)) {
+ std::string ErrMsg;
+ if (sys::DynamicLibrary::LoadLibraryPermanently(Dylib.c_str(), &ErrMsg))
+ llvm::errs() << "Error loading '" << Dylib << "': "
+ << ErrMsg << "\n";
+ } else
+ llvm::errs() << "Dylib not found: '" << Dylib << "'.\n";
+ }
+}
+
+
/* *** */
static int printLineInfoForInput() {
+ // Load any dylibs requested on the command line.
+ loadDylibs();
+
// If we don't have any input files, read from stdin.
if (!InputFileList.size())
InputFileList.push_back("-");
@@ -182,6 +204,9 @@ static int printLineInfoForInput() {
}
static int executeInput() {
+ // Load any dylibs requested on the command line.
+ loadDylibs();
+
// Instantiate a dynamic linker.
TrivialMemoryManager MemMgr;
RuntimeDyld Dyld(&MemMgr);
OpenPOWER on IntegriCloud