X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FLinker.h;h=66a848336709fe54b1718f35310e278b69528fcf;hb=10d4c586ed86a8663eb0a0c0184a9f8e9bc9a2b4;hp=1b8e7516b44ac6b80d2456b43bcbbbc6c53ce303;hpb=e5caf877e9355ba68cfb6d995e0b1a2b2a466288;p=oota-llvm.git diff --git a/include/llvm/Linker.h b/include/llvm/Linker.h index 1b8e7516b44..66a84833670 100644 --- a/include/llvm/Linker.h +++ b/include/llvm/Linker.h @@ -1,10 +1,10 @@ //===- llvm/Linker.h - Module Linker Interface ------------------*- C++ -*-===// -// +// // The LLVM Compiler Infrastructure // -// This file was developed by Reid Spencer and is distributed under the +// 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 defines the interface to the module/file/archive linker. @@ -16,21 +16,22 @@ #include "llvm/System/Path.h" #include +#include namespace llvm { class Module; /// This class provides the core functionality of linking in LLVM. It retains a -/// 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 /// to the caller and the Linker object is only suitable for destruction. -/// 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, 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 /// 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. @@ -41,18 +42,18 @@ class 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 - /// 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 > ItemList; /// This enumeration is used to control various optional features of the - /// linker. + /// linker. enum ControlFlags { 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 + QuietErrors = 4 ///< Indicate that this link is for a native executable }; /// @} @@ -62,7 +63,11 @@ class Linker { /// 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( + const std::string& progname, ///< name of tool running linker + const std::string& modulename, ///< name of linker's end-result module + 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. @@ -78,33 +83,33 @@ class Linker { /// @{ public: /// This method gets the composite module into which linking is being - /// done. The Composite module starts out empty and accumulates modules + /// done. The Composite module starts out empty and accumulates modules /// linked into it via the various LinkIn* methods. This method does not /// release the Module to the caller. The Linker retains ownership and will - /// destruct the Module when the Linker is destructed. + /// destruct the Module when the Linker is destructed. /// @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. Module* releaseModule(); /// This method gets the list of libraries that form the path that the - /// Linker will search when it is presented with a library name. + /// Linker will search when it is presented with a library name. /// @brief Get the Linkers library path const std::vector& 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 - /// true, indicating an error occurred. At most one error is retained so + /// true, indicating an error occurred. At most one error is retained so /// 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 /// been printed to std::cerr. @@ -124,7 +129,7 @@ class Linker { void addPath(const sys::Path& path); /// Add a set of paths to the list of paths that the linker will search. The - /// Linker accumulates the set of libraries added. The \p paths will be + /// Linker accumulates the set of libraries added. The \p paths will be /// added to the end of the Linker's list. Order will be retained. /// @brief Add a set of paths. void addPaths(const std::vector& paths); @@ -140,27 +145,28 @@ class Linker { /// @brief Set control flags. void setFlags(unsigned flags) { Flags = flags; } - /// This method is the main interface to the linker. It can be used to + /// This method is the main interface to the linker. It can be used to /// 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. /// @returns true if an error occurred, false otherwise /// @see LinkItemKind /// @see getLastError /// @throws nothing bool LinkInItems ( - const ItemList& Items // Set of libraries/files to link in + const ItemList& Items, ///< Set of libraries/files to link in + ItemList& NativeItems ///< Output list of native files/libs ); - /// 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 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. /// @returns true if an error occurs, false otherwise /// @see getLastError /// @brief Link in multiple files. @@ -176,14 +182,15 @@ class Linker { /// @see getLastError /// @brief Link in a single file. bool LinkInFile( - const sys::Path& File ///< File to link in. + const sys::Path& File, ///< File to link in. + bool &is_native ///< Indicates if the file is native object file ); - /// 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 - /// are searched for the \p Libraries and any found will be linked in with + /// are searched for the \p Libraries and any found will be linked in with /// LinkInArchive. If an error occurs, the Linker's error string is set. /// @see LinkInArchive /// @see getLastError @@ -193,9 +200,9 @@ class Linker { const std::vector & Libraries ///< Libraries to link in ); - /// This function provides a way to selectively link in a set of modules, + /// This function provides a way to selectively link in a set of modules, /// found in one library, based on the unresolved symbols in the composite - /// module.The \p Library should be the base name of a library, as if given + /// module.The \p Library should be the base name of a library, as if given /// with the -l option of a linker tool. The Linker's LibPaths are searched /// for the \P Library and if found, it will be linked in with via the /// LinkInArchive method. If an error occurs, the Linker's error string is @@ -205,41 +212,46 @@ class Linker { /// @returns true if an error occurs, false otherwise /// @brief Link one library into the module bool LinkInLibrary ( - const std::string& Library ///< The library to link in + const std::string& Library, ///< The library to link in + bool& is_native ///< Indicates if lib a native library ); /// 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 + /// 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 /// symbols can be found. If an error occurs, the error string is set. - /// To speed up this function, ensure the the archive has been processed + /// To speed up this function, ensure the the archive has been processed /// 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 - /// @returns true if an error occurs, otherwise false. + /// @returns true if an error occurs, otherwise false. /// @brief Link in one archive. - bool LinkInArchive( - const sys::Path& Filename ///< Filename of the archive to link + bool LinkInArchive( + const sys::Path& Filename, ///< Filename of the archive to link + bool& is_native ///< Indicates if archive is a native archive ); /// This method links the \p Src module into the Linker's Composite module - /// 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( - 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 ); + } - /// This is the heart of the linker. This method will take unconditional + /// This is the heart of the linker. This method will take unconditional /// 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 - /// the \p Dest module will remain. The \p Src module is linked into the + /// the \p Dest module will remain. The \p Src module is linked into 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 @@ -277,7 +289,7 @@ class Linker { std::string Error; ///< Text of error that occurred. std::string ProgramName; ///< Name of the program being linked /// @} - + }; } // End llvm namespace