Chris Lattner | c1b5d09 | 2002-07-23 17:56:53 +0000 | [diff] [blame] | 1 | //===-- PluginLoader.cpp - Implement -load command line option ------------===// |
| 2 | // |
| 3 | // This file implements the -load <plugin> command line option processor. When |
| 4 | // linked into a program, this new command line option is available that allows |
| 5 | // users to load shared objects into the running program. |
| 6 | // |
| 7 | // Note that there are no symbols exported by the .o file generated for this |
| 8 | // .cpp file. Because of this, a program must link against support.o instead of |
| 9 | // support.a: otherwise this translation unit will not be included. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Brian Gaeke | 56d8616 | 2003-10-10 17:01:49 +0000 | [diff] [blame^] | 13 | #include "Support/DynamicLinker.h" |
Chris Lattner | c1b5d09 | 2002-07-23 17:56:53 +0000 | [diff] [blame] | 14 | #include "Support/CommandLine.h" |
John Criswell | 7a73b80 | 2003-06-30 21:59:07 +0000 | [diff] [blame] | 15 | #include "Config/dlfcn.h" |
| 16 | #include "Config/link.h" |
Chris Lattner | 0c0edf8 | 2002-07-25 06:17:51 +0000 | [diff] [blame] | 17 | #include <iostream> |
Chris Lattner | c1b5d09 | 2002-07-23 17:56:53 +0000 | [diff] [blame] | 18 | |
| 19 | namespace { |
| 20 | struct PluginLoader { |
| 21 | void operator=(const std::string &Filename) { |
Brian Gaeke | 56d8616 | 2003-10-10 17:01:49 +0000 | [diff] [blame^] | 22 | std::string ErrorMessage; |
| 23 | if (LinkDynamicObject (Filename.c_str (), &ErrorMessage)) |
| 24 | std::cerr << "Error opening '" << Filename << "': " << ErrorMessage |
| 25 | << "\n -load request ignored.\n"; |
Chris Lattner | c1b5d09 | 2002-07-23 17:56:53 +0000 | [diff] [blame] | 26 | } |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | // This causes operator= above to be invoked for every -load option. |
Chris Lattner | 0c0edf8 | 2002-07-25 06:17:51 +0000 | [diff] [blame] | 31 | static cl::opt<PluginLoader, false, cl::parser<std::string> > |
Chris Lattner | c1b5d09 | 2002-07-23 17:56:53 +0000 | [diff] [blame] | 32 | LoadOpt("load", cl::ZeroOrMore, cl::value_desc("plugin.so"), |
| 33 | cl::desc("Load the specified plugin")); |