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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208739
91177308-0d34-0410-b5e6-
96231b3b80d8
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/Object/MachO.h"
#include "llvm/Support/CommandLine.h"
#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"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Memory.h"
#include "llvm/Support/MemoryBuffer.h"
cl::desc("Function to call as entry point."),
cl::init("_main"));
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
/* *** */
// A trivial memory manager that doesn't do anything fancy, just uses the
+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() {
/* *** */
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("-");
// If we don't have any input files, read from stdin.
if (!InputFileList.size())
InputFileList.push_back("-");
}
static int executeInput() {
}
static int executeInput() {
+ // Load any dylibs requested on the command line.
+ loadDylibs();
+
// Instantiate a dynamic linker.
TrivialMemoryManager MemMgr;
RuntimeDyld Dyld(&MemMgr);
// Instantiate a dynamic linker.
TrivialMemoryManager MemMgr;
RuntimeDyld Dyld(&MemMgr);