[llvm] r359168 - [llvm-rtdyld] Add support for passing command line arguments to rtdyld-run code.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 24 22:02:10 PDT 2019
Author: lhames
Date: Wed Apr 24 22:02:10 2019
New Revision: 359168
URL: http://llvm.org/viewvc/llvm-project?rev=359168&view=rev
Log:
[llvm-rtdyld] Add support for passing command line arguments to rtdyld-run code.
The --args option can now be used to pass arguments to code linked with
llvm-rtdyld. E.g.
$ llvm-rtdyld file1.o file2.o --args a b c
is equivalent to:
$ ld -o program file1.o file2.o
$ ./program a b c
This is the rtdyld counterpart to the jitlink change in r359115, and makes
benchmarking and comparison between the tools easier.
Modified:
llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
Modified: llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp?rev=359168&r1=359167&r2=359168&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp (original)
+++ llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp Wed Apr 24 22:02:10 2019
@@ -77,6 +77,10 @@ Dylibs("dylib",
cl::desc("Add library."),
cl::ZeroOrMore);
+static cl::list<std::string> InputArgv("args", cl::Positional,
+ cl::desc("<program arguments>..."),
+ cl::ZeroOrMore, cl::PositionalEatsArgs);
+
static cl::opt<std::string>
TripleName("triple", cl::desc("Target triple for disassembler"));
@@ -208,7 +212,15 @@ public:
if (I != DummyExterns.end())
return JITSymbol(I->second, JITSymbolFlags::Exported);
- return RTDyldMemoryManager::findSymbol(Name);
+ if (auto Sym = RTDyldMemoryManager::findSymbol(Name))
+ return Sym;
+ else if (auto Err = Sym.takeError())
+ ExitOnErr(std::move(Err));
+ else
+ ExitOnErr(make_error<StringError>("Could not find definition for \"" +
+ Name + "\"",
+ inconvertibleErrorCode()));
+ llvm_unreachable("Should have returned or exited by now");
}
void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
@@ -533,11 +545,13 @@ static int executeInput() {
int (*Main)(int, const char**) =
(int(*)(int,const char**)) uintptr_t(MainAddress);
- const char **Argv = new const char*[2];
+ std::vector<const char *> Argv;
// Use the name of the first input object module as argv[0] for the target.
- Argv[0] = InputFileList[0].c_str();
- Argv[1] = nullptr;
- return Main(1, Argv);
+ Argv.push_back(InputFileList[0].data());
+ for (auto &Arg : InputArgv)
+ Argv.push_back(Arg.data());
+ Argv.push_back(nullptr);
+ return Main(Argv.size() - 1, Argv.data());
}
static int checkAllExpressions(RuntimeDyldChecker &Checker) {
More information about the llvm-commits
mailing list