blob: 1729bb33655769b8487060778bd3d4e046e16e07 [file] [log] [blame]
Chris Lattnerc1b5d092002-07-23 17:56:53 +00001//===-- PluginLoader.cpp - Implement -load command line option ------------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
3// The LLVM Compiler Infrastructure
4//
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.
7//
8//===----------------------------------------------------------------------===//
Chris Lattnerc1b5d092002-07-23 17:56:53 +00009//
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.
13//
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.
17//
18//===----------------------------------------------------------------------===//
19
Brian Gaeke56d86162003-10-10 17:01:49 +000020#include "Support/DynamicLinker.h"
Chris Lattnerc1b5d092002-07-23 17:56:53 +000021#include "Support/CommandLine.h"
John Criswell7a73b802003-06-30 21:59:07 +000022#include "Config/dlfcn.h"
23#include "Config/link.h"
Chris Lattner0c0edf82002-07-25 06:17:51 +000024#include <iostream>
Chris Lattnerc1b5d092002-07-23 17:56:53 +000025
Brian Gaeked0fde302003-11-11 22:41:34 +000026namespace llvm {
27
Chris Lattnerc1b5d092002-07-23 17:56:53 +000028namespace {
29 struct PluginLoader {
30 void operator=(const std::string &Filename) {
Brian Gaeke56d86162003-10-10 17:01:49 +000031 std::string ErrorMessage;
32 if (LinkDynamicObject (Filename.c_str (), &ErrorMessage))
33 std::cerr << "Error opening '" << Filename << "': " << ErrorMessage
34 << "\n -load request ignored.\n";
Chris Lattnerc1b5d092002-07-23 17:56:53 +000035 }
36 };
37}
38
39// This causes operator= above to be invoked for every -load option.
Chris Lattner0c0edf82002-07-25 06:17:51 +000040static cl::opt<PluginLoader, false, cl::parser<std::string> >
Chris Lattnerc1b5d092002-07-23 17:56:53 +000041LoadOpt("load", cl::ZeroOrMore, cl::value_desc("plugin.so"),
42 cl::desc("Load the specified plugin"));
Brian Gaeked0fde302003-11-11 22:41:34 +000043
44} // End llvm namespace