blob: b973b16a508cecf7aa5d334b92d6156146774620 [file] [log] [blame]
Chris Lattnerc1b5d092002-07-23 17:56:53 +00001//===-- 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
13#include "Support/CommandLine.h"
John Criswell7a73b802003-06-30 21:59:07 +000014#include "Config/dlfcn.h"
15#include "Config/link.h"
Chris Lattner0c0edf82002-07-25 06:17:51 +000016#include <iostream>
Chris Lattnerc1b5d092002-07-23 17:56:53 +000017
18namespace {
19 struct PluginLoader {
20 void operator=(const std::string &Filename) {
21 if (dlopen(Filename.c_str(), RTLD_NOW) == 0)
22 std::cerr << "Error opening '" << Filename << "': " << dlerror()
23 << "\n -load request ignored.\n";
24 }
25 };
26}
27
28// This causes operator= above to be invoked for every -load option.
Chris Lattner0c0edf82002-07-25 06:17:51 +000029static cl::opt<PluginLoader, false, cl::parser<std::string> >
Chris Lattnerc1b5d092002-07-23 17:56:53 +000030LoadOpt("load", cl::ZeroOrMore, cl::value_desc("plugin.so"),
31 cl::desc("Load the specified plugin"));