[llvm] r359115 - [JITLink] Add support for passing arguments to jit-linked code.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 24 10:23:05 PDT 2019
Author: lhames
Date: Wed Apr 24 10:23:05 2019
New Revision: 359115
URL: http://llvm.org/viewvc/llvm-project?rev=359115&view=rev
Log:
[JITLink] Add support for passing arguments to jit-linked code.
The --args option can now be used to pass arguments to code linked with
llvm-jitlink. E.g.
$ llvm-jitlink file1.o file2.o --args a b c
is equivalent to:
$ ld -o program file1.o file2.o
$ ./program a b c
Modified:
llvm/trunk/tools/llvm-jitlink/llvm-jitlink.cpp
Modified: llvm/trunk/tools/llvm-jitlink/llvm-jitlink.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-jitlink/llvm-jitlink.cpp?rev=359115&r1=359114&r2=359115&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-jitlink/llvm-jitlink.cpp (original)
+++ llvm/trunk/tools/llvm-jitlink/llvm-jitlink.cpp Wed Apr 24 10:23:05 2019
@@ -64,6 +64,10 @@ static cl::list<std::string>
Dylibs("dlopen", cl::desc("Dynamic libraries to load before linking"),
cl::ZeroOrMore);
+static cl::list<std::string> InputArgv("args", cl::Positional,
+ cl::desc("<program arguments>..."),
+ cl::ZeroOrMore, cl::PositionalEatsArgs);
+
static cl::opt<bool>
NoProcessSymbols("no-process-syms",
cl::desc("Do not resolve to llvm-jitlink process symbols"),
@@ -335,13 +339,18 @@ Triple getFirstFileTriple() {
return Obj->makeTriple();
}
-void setEntryPointNameIfNotProvided(const Session &S) {
+Error sanitizeArguments(const Session &S) {
if (EntryPointName.empty()) {
if (S.TT.getObjectFormat() == Triple::MachO)
EntryPointName = "_main";
else
EntryPointName = "main";
}
+
+ if (NoExec && !InputArgv.empty())
+ outs() << "Warning: --args passed to -noexec run will be ignored.\n";
+
+ return Error::success();
}
Error loadProcessSymbols(Session &S) {
@@ -568,6 +577,8 @@ Expected<int> runEntryPoint(Session &S,
std::vector<const char *> EntryPointArgs;
EntryPointArgs.push_back(PNStorage.get());
+ for (auto &InputArg : InputArgv)
+ EntryPointArgs.push_back(InputArg.data());
EntryPointArgs.push_back(nullptr);
using MainTy = int (*)(int, const char *[]);
@@ -588,7 +599,7 @@ int main(int argc, char *argv[]) {
Session S(getFirstFileTriple());
- setEntryPointNameIfNotProvided(S);
+ ExitOnErr(sanitizeArguments(S));
if (!NoProcessSymbols)
ExitOnErr(loadProcessSymbols(S));
More information about the llvm-commits
mailing list