PluginLoader.cpp revision d0fde30ce850b78371fd1386338350591f9ff494
1c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner//===-- PluginLoader.cpp - Implement -load command line option ------------===//
2b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell//
3b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell//                     The LLVM Compiler Infrastructure
4b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell//
5b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell// This file was developed by the LLVM research group and is distributed under
6b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell// the University of Illinois Open Source License. See LICENSE.TXT for details.
7b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell//
8b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell//===----------------------------------------------------------------------===//
9c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner//
10c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner// This file implements the -load <plugin> command line option processor.  When
11c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner// linked into a program, this new command line option is available that allows
12c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner// users to load shared objects into the running program.
13c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner//
14c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner// Note that there are no symbols exported by the .o file generated for this
15c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner// .cpp file.  Because of this, a program must link against support.o instead of
16c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner// support.a: otherwise this translation unit will not be included.
17c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner//
18c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner//===----------------------------------------------------------------------===//
19c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner
2056d86168720849e94cb39809a29e7c391300460dBrian Gaeke#include "Support/DynamicLinker.h"
21c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner#include "Support/CommandLine.h"
227a73b80b9052136c8cd2234eb3433a07df7cf38eJohn Criswell#include "Config/dlfcn.h"
237a73b80b9052136c8cd2234eb3433a07df7cf38eJohn Criswell#include "Config/link.h"
240c0edf8afc35a42b15a24ebb5fa5f3fc674290aeChris Lattner#include <iostream>
25c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner
26d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
27d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
28c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattnernamespace {
29c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner  struct PluginLoader {
30c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner    void operator=(const std::string &Filename) {
3156d86168720849e94cb39809a29e7c391300460dBrian Gaeke      std::string ErrorMessage;
3256d86168720849e94cb39809a29e7c391300460dBrian Gaeke      if (LinkDynamicObject (Filename.c_str (), &ErrorMessage))
3356d86168720849e94cb39809a29e7c391300460dBrian Gaeke        std::cerr << "Error opening '" << Filename << "': " << ErrorMessage
3456d86168720849e94cb39809a29e7c391300460dBrian Gaeke                  << "\n  -load request ignored.\n";
35c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner    }
36c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner  };
37c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner}
38c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner
39c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner// This causes operator= above to be invoked for every -load option.
400c0edf8afc35a42b15a24ebb5fa5f3fc674290aeChris Lattnerstatic cl::opt<PluginLoader, false, cl::parser<std::string> >
41c1b5d092a0f89db5356ae79d8cc4213118f230ddChris LattnerLoadOpt("load", cl::ZeroOrMore, cl::value_desc("plugin.so"),
42c1b5d092a0f89db5356ae79d8cc4213118f230ddChris Lattner        cl::desc("Load the specified plugin"));
43d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
44d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
45