-// This file was developed by Reid Spencer and is distributed under the
-// University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
//===----------------------------------------------------------------------===//
//
// This file defines the interface to the module/file/archive linker.
//===----------------------------------------------------------------------===//
//
// This file defines the interface to the module/file/archive linker.
-/// Module object which is the composite of the modules and libraries linked
-/// into it. The composite Module can be retrieved via the getModule() method.
-/// In this case the Linker still retains ownership of the Module. If the
-/// releaseModule() method is used, the ownership of the Module is transferred
+/// Module object which is the composite of the modules and libraries linked
+/// into it. The composite Module can be retrieved via the getModule() method.
+/// In this case the Linker still retains ownership of the Module. If the
+/// releaseModule() method is used, the ownership of the Module is transferred
-/// The Linker can link Modules from memory, bytecode files, or bytecode
-/// archives. It retains a set of search paths in which to find any libraries
-/// presented to it. By default, the linker will generate error and warning
-/// messages to std::cerr but this capability can be turned off with the
+/// The Linker can link Modules from memory, bitcode files, or bitcode
+/// archives. It retains a set of search paths in which to find any libraries
+/// presented to it. By default, the linker will generate error and warning
+/// messages to stderr but this capability can be turned off with the
/// QuietWarnings and QuietErrors flags. It can also be instructed to verbosely
/// print out the linking actions it is taking with the Verbose flag.
/// @brief The LLVM Linker.
/// QuietWarnings and QuietErrors flags. It can also be instructed to verbosely
/// print out the linking actions it is taking with the Verbose flag.
/// @brief The LLVM Linker.
public:
/// This type is used to pass the linkage items (libraries and files) to
/// the LinkItems function. It is composed of string/bool pairs. The string
public:
/// This type is used to pass the linkage items (libraries and files) to
/// the LinkItems function. It is composed of string/bool pairs. The string
- /// provides the name of the file or library (as with the -l option). The
- /// bool should be true for libraries and false for files, signifying
+ /// provides the name of the file or library (as with the -l option). The
+ /// bool should be true for libraries and false for files, signifying
/// "isLibrary".
/// @brief A list of linkage items
typedef std::vector<std::pair<std::string,bool> > ItemList;
/// This enumeration is used to control various optional features of the
/// "isLibrary".
/// @brief A list of linkage items
typedef std::vector<std::pair<std::string,bool> > ItemList;
/// This enumeration is used to control various optional features of the
- Verbose = 1, ///< Print to std::cerr what steps the linker is taking
- QuietWarnings = 2, ///< Don't print errors and warnings to std::cerr.
- QuietErrors = 4, ///< Indicate that this link is for a native executable
+ Verbose = 1, ///< Print to stderr what steps the linker is taking
+ QuietWarnings = 2, ///< Don't print warnings to stderr.
+ QuietErrors = 4 ///< Don't print errors to stderr.
/// Construct the Linker with an empty module which will be given the
/// name \p progname. \p progname will also be used for error messages.
/// @brief Construct with empty module
/// Construct the Linker with an empty module which will be given the
/// name \p progname. \p progname will also be used for error messages.
/// @brief Construct with empty module
- Linker(const std::string& progname, unsigned Flags = 0 );
+ Linker(StringRef progname, ///< name of tool running linker
+ StringRef modulename, ///< name of linker's end-result module
+ LLVMContext &C, ///< Context for global info
+ unsigned Flags = 0 ///< ControlFlags (one or more |'d together)
+ );
/// Construct the Linker with a previously defined module, \p aModule. Use
/// \p progname for the name of the program in error messages.
/// @brief Construct with existing module
/// Construct the Linker with a previously defined module, \p aModule. Use
/// \p progname for the name of the program in error messages.
/// @brief Construct with existing module
/// linked into it via the various LinkIn* methods. This method does not
/// release the Module to the caller. The Linker retains ownership and will
/// linked into it via the various LinkIn* methods. This method does not
/// release the Module to the caller. The Linker retains ownership and will
/// @see releaseModule
/// @brief Get the linked/composite module.
Module* getModule() const { return Composite; }
/// This method releases the composite Module into which linking is being
/// done. Ownership of the composite Module is transferred to the caller who
/// @see releaseModule
/// @brief Get the linked/composite module.
Module* getModule() const { return Composite; }
/// This method releases the composite Module into which linking is being
/// done. Ownership of the composite Module is transferred to the caller who
- /// must arrange for its destruct. After this method is called, the Linker
- /// terminates the linking session for the returned Module. It will no
- /// longer utilize the returned Module but instead resets itself for
- /// subsequent linking as if the constructor had been called. The Linker's
- /// LibPaths and flags to be reset, and memory will be released.
- /// @brief Release the linked/composite module.
+ /// must arrange for its destruct. After this method is called, the Linker
+ /// terminates the linking session for the returned Module. It will no
+ /// longer utilize the returned Module but instead resets itself for
+ /// subsequent linking as if the constructor had been called. The Linker's
+ /// LibPaths and flags to be reset, and memory will be released.
+ /// @brief Release the linked/composite module.
/// @brief Get the Linkers library path
const std::vector<sys::Path>& getLibPaths() const { return LibPaths; }
/// This method returns an error string suitable for printing to the user.
/// The return value will be empty unless an error occurred in one of the
/// LinkIn* methods. In those cases, the LinkIn* methods will have returned
/// @brief Get the Linkers library path
const std::vector<sys::Path>& getLibPaths() const { return LibPaths; }
/// This method returns an error string suitable for printing to the user.
/// The return value will be empty unless an error occurred in one of the
/// LinkIn* methods. In those cases, the LinkIn* methods will have returned
/// this function always returns the last error that occurred. Note that if
/// the Quiet control flag is not set, the error string will have already
/// this function always returns the last error that occurred. Note that if
/// the Quiet control flag is not set, the error string will have already
void addPath(const sys::Path& path);
/// Add a set of paths to the list of paths that the linker will search. The
void addPath(const sys::Path& path);
/// Add a set of paths to the list of paths that the linker will search. The
/// added to the end of the Linker's list. Order will be retained.
/// @brief Add a set of paths.
void addPaths(const std::vector<std::string>& paths);
/// added to the end of the Linker's list. Order will be retained.
/// @brief Add a set of paths.
void addPaths(const std::vector<std::string>& paths);
/// link a set of linkage items into a module. A linkage item is either a
/// file name with fully qualified path, or a library for which the Linker's
/// LibraryPath will be utilized to locate the library. The bool value in
/// link a set of linkage items into a module. A linkage item is either a
/// file name with fully qualified path, or a library for which the Linker's
/// LibraryPath will be utilized to locate the library. The bool value in
- /// the LinkItemKind should be set to true for libraries. This function
- /// allows linking to preserve the order of specification associated with
- /// the command line, or for other purposes. Each item will be linked in
- /// turn as it occurs in \p Items.
+ /// the LinkItemKind should be set to true for libraries. This function
+ /// allows linking to preserve the order of specification associated with
+ /// the command line, or for other purposes. Each item will be linked in
+ /// turn as it occurs in \p Items.
- /// This function links the bytecode \p Files into the composite module.
- /// Note that this does not do any linking of unresolved symbols. The \p
- /// Files are all completely linked into \p HeadModule regardless of
- /// unresolved symbols. This function just loads each bytecode file and
- /// calls LinkInModule on them.
+ /// This function links the bitcode \p Files into the composite module.
+ /// Note that this does not do any linking of unresolved symbols. The \p
+ /// Files are all completely linked into \p HeadModule regardless of
+ /// unresolved symbols. This function just loads each bitcode file and
+ /// calls LinkInModule on them.
/// @returns true if an error occurs, false otherwise
/// @see getLastError
/// @brief Link in multiple files.
/// @returns true if an error occurs, false otherwise
/// @see getLastError
/// @brief Link in multiple files.
/// occurs, the Linker's error string is set.
/// @returns true if an error occurs, false otherwise
/// @see getLastError
/// @brief Link in a single file.
bool LinkInFile(
/// occurs, the Linker's error string is set.
/// @returns true if an error occurs, false otherwise
/// @see getLastError
/// @brief Link in a single file.
bool LinkInFile(
- /// This function provides a way to selectively link in a set of modules,
- /// found in libraries, based on the unresolved symbols in the composite
+ /// This function provides a way to selectively link in a set of modules,
+ /// found in libraries, based on the unresolved symbols in the composite
/// module. Each item in \p Libraries should be the base name of a library,
/// as if given with the -l option of a linker tool. The Linker's LibPaths
/// module. Each item in \p Libraries should be the base name of a library,
/// as if given with the -l option of a linker tool. The Linker's LibPaths
/// @returns true if an error occurs, false otherwise
/// @brief Link one library into the module
bool LinkInLibrary (
/// @returns true if an error occurs, false otherwise
/// @brief Link one library into the module
bool LinkInLibrary (
- /// This function links one bytecode archive, \p Filename, into the module.
- /// The archive is searched to resolve outstanding symbols. Any modules in
- /// the archive that resolve outstanding symbols will be linked in. The
- /// library is searched repeatedly until no more modules that resolve
+ /// This function links one bitcode archive, \p Filename, into the module.
+ /// The archive is searched to resolve outstanding symbols. Any modules in
+ /// the archive that resolve outstanding symbols will be linked in. The
+ /// library is searched repeatedly until no more modules that resolve
/// llvm-ranlib or the S option was given to llvm-ar when the archive was
/// created. These tools add a symbol table to the archive which makes the
/// search for undefined symbols much faster.
/// @see getLastError
/// llvm-ranlib or the S option was given to llvm-ar when the archive was
/// created. These tools add a symbol table to the archive which makes the
/// search for undefined symbols much faster.
/// @see getLastError
- /// by calling LinkModules. All the other LinkIn* methods eventually
- /// result in calling this method to link a Module into the Linker's
- /// composite.
+ /// by calling LinkModules. All the other LinkIn* methods eventually
+ /// result in calling this method to link a Module into the Linker's
+ /// composite.
/// @see LinkModules
/// @returns True if an error occurs, false otherwise.
/// @brief Link in a module.
bool LinkInModule(
/// @see LinkModules
/// @returns True if an error occurs, false otherwise.
/// @brief Link in a module.
bool LinkInModule(
- Module* Src ///< Module linked into \p Dest
- ) { return LinkModules(Composite, Src, &Error); }
+ Module* Src, ///< Module linked into \p Dest
+ std::string* ErrorMsg = 0 /// Error/diagnostic string
+ ) {
+ return LinkModules(Composite, Src, ErrorMsg );
+ }
/// control of the \p Src module and link it into the \p Dest module. The
/// \p Src module will be destructed or subsumed by this method. In either
/// case it is not usable by the caller after this method is invoked. Only
/// control of the \p Src module and link it into the \p Dest module. The
/// \p Src module will be destructed or subsumed by this method. In either
/// case it is not usable by the caller after this method is invoked. Only
/// Linker's composite module such that types, global variables, functions,
/// and etc. are matched and resolved. If an error occurs, this function
/// returns true and ErrorMsg is set to a descriptive message about the
/// Linker's composite module such that types, global variables, functions,
/// and etc. are matched and resolved. If an error occurs, this function
/// returns true and ErrorMsg is set to a descriptive message about the
/// will be empty (i.e. sys::Path::isEmpty() will return true).
/// @returns A sys::Path to the found library
/// @brief Find a library from its short name.
/// will be empty (i.e. sys::Path::isEmpty() will return true).
/// @returns A sys::Path to the found library
/// @brief Find a library from its short name.
/// Module it contains (wrapped in an auto_ptr), or 0 if an error occurs.
std::auto_ptr<Module> LoadObject(const sys::Path& FN);
/// Module it contains (wrapped in an auto_ptr), or 0 if an error occurs.
std::auto_ptr<Module> LoadObject(const sys::Path& FN);
- bool warning(const std::string& message);
- bool error(const std::string& message);
- void verbose(const std::string& message);
+ bool warning(StringRef message);
+ bool error(StringRef message);
+ void verbose(StringRef message);
Module* Composite; ///< The composite module linked together
std::vector<sys::Path> LibPaths; ///< The library search paths
unsigned Flags; ///< Flags to control optional behavior.
std::string Error; ///< Text of error that occurred.
std::string ProgramName; ///< Name of the program being linked
/// @}
Module* Composite; ///< The composite module linked together
std::vector<sys::Path> LibPaths; ///< The library search paths
unsigned Flags; ///< Flags to control optional behavior.
std::string Error; ///< Text of error that occurred.
std::string ProgramName; ///< Name of the program being linked
/// @}