1 //===-- PluginLoader.cpp - Implement -load command line option ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the -load <plugin> command line option processor. When
11 // linked into a program, this new command line option is available that allows
12 // users to load shared objects into the running program.
14 // Note that there are no symbols exported by the .o file generated for this
15 // .cpp file. Because of this, a program must link against support.o instead of
16 // support.a: otherwise this translation unit will not be included.
18 //===----------------------------------------------------------------------===//
20 #include "Support/DynamicLinker.h"
21 #include "Support/CommandLine.h"
22 #include "Config/dlfcn.h"
23 #include "Config/link.h"
29 void operator=(const std::string &Filename) {
30 std::string ErrorMessage;
31 if (LinkDynamicObject (Filename.c_str (), &ErrorMessage))
32 std::cerr << "Error opening '" << Filename << "': " << ErrorMessage
33 << "\n -load request ignored.\n";
38 // This causes operator= above to be invoked for every -load option.
39 static cl::opt<PluginLoader, false, cl::parser<std::string> >
40 LoadOpt("load", cl::ZeroOrMore, cl::value_desc("plugin" SHLIBEXT),
41 cl::desc("Load the specified plugin"));