blob: 4cacd01613368a7e82f4126c20379ff4739f56a0 [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
Brian Gaeke56d86162003-10-10 17:01:49 +000013#include "Support/DynamicLinker.h"
Chris Lattnerc1b5d092002-07-23 17:56:53 +000014#include "Support/CommandLine.h"
John Criswell7a73b802003-06-30 21:59:07 +000015#include "Config/dlfcn.h"
16#include "Config/link.h"
Chris Lattner0c0edf82002-07-25 06:17:51 +000017#include <iostream>
Chris Lattnerc1b5d092002-07-23 17:56:53 +000018
19namespace {
20 struct PluginLoader {
21 void operator=(const std::string &Filename) {
Brian Gaeke56d86162003-10-10 17:01:49 +000022 std::string ErrorMessage;
23 if (LinkDynamicObject (Filename.c_str (), &ErrorMessage))
24 std::cerr << "Error opening '" << Filename << "': " << ErrorMessage
25 << "\n -load request ignored.\n";
Chris Lattnerc1b5d092002-07-23 17:56:53 +000026 }
27 };
28}
29
30// This causes operator= above to be invoked for every -load option.
Chris Lattner0c0edf82002-07-25 06:17:51 +000031static cl::opt<PluginLoader, false, cl::parser<std::string> >
Chris Lattnerc1b5d092002-07-23 17:56:53 +000032LoadOpt("load", cl::ZeroOrMore, cl::value_desc("plugin.so"),
33 cl::desc("Load the specified plugin"));