[llvm-commits] [llvm] r172749 - in /llvm/trunk: docs/ReleaseNotes.rst include/llvm/Linker.h lib/Linker/CMakeLists.txt lib/Linker/LinkArchives.cpp lib/Linker/LinkItems.cpp lib/Linker/Linker.cpp
Rafael EspĂndola
rafael.espindola at gmail.com
Wed Feb 20 13:55:26 PST 2013
This is awesome! Thanks!
On 17 January 2013 14:52, Daniel Dunbar <daniel at zuster.org> wrote:
> Author: ddunbar
> Date: Thu Jan 17 13:52:25 2013
> New Revision: 172749
>
> URL: http://llvm.org/viewvc/llvm-project?rev=172749&view=rev
> Log:
> [Linker] Drop support for IR-level extended linking support (archives, etc.).
>
> - This code is dead, and the "right" way to get this support is to use the
> platform-specific linker-integrated LTO mechanisms, or the forthcoming LLVM
> linker.
>
> Removed:
> llvm/trunk/lib/Linker/LinkArchives.cpp
> llvm/trunk/lib/Linker/LinkItems.cpp
> Modified:
> llvm/trunk/docs/ReleaseNotes.rst
> llvm/trunk/include/llvm/Linker.h
> llvm/trunk/lib/Linker/CMakeLists.txt
> llvm/trunk/lib/Linker/Linker.cpp
>
> Modified: llvm/trunk/docs/ReleaseNotes.rst
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ReleaseNotes.rst?rev=172749&r1=172748&r2=172749&view=diff
> ==============================================================================
> --- llvm/trunk/docs/ReleaseNotes.rst (original)
> +++ llvm/trunk/docs/ReleaseNotes.rst Thu Jan 17 13:52:25 2013
> @@ -500,7 +500,9 @@
> The ``TargetData`` structure has been renamed to ``DataLayout`` and moved to
> ``VMCore`` to remove a dependency on ``Target``.
>
> -#. ...
> +#. The IR-level extended linker APIs (for example, to link bitcode files out of
> + archives) have been removed. Any existing clients of these features should
> + move to using a linker with integrated LTO support.
>
> Tools Changes
> -------------
>
> Modified: llvm/trunk/include/llvm/Linker.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Linker.h?rev=172749&r1=172748&r2=172749&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Linker.h (original)
> +++ llvm/trunk/include/llvm/Linker.h Thu Jan 17 13:52:25 2013
> @@ -153,93 +153,6 @@
> /// @brief Set control flags.
> void setFlags(unsigned flags) { Flags = flags; }
>
> - /// 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.
> - /// @returns true if an error occurred, false otherwise
> - /// @see LinkItemKind
> - /// @see getLastError
> - bool LinkInItems (
> - const ItemList& Items, ///< Set of libraries/files to link in
> - ItemList& NativeItems ///< Output list of native files/libs
> - );
> -
> - /// 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.
> - bool LinkInFiles (
> - const std::vector<sys::Path> & Files ///< Files to link in
> - );
> -
> - /// This function links a single bitcode file, \p File, into the composite
> - /// module. Note that this does not attempt to resolve symbols. This method
> - /// just loads the bitcode file and calls LinkInModule on it. If an error
> - /// 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(
> - 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
> - /// 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
> - /// LinkInArchive. If an error occurs, the Linker's error string is set.
> - /// @see LinkInArchive
> - /// @see getLastError
> - /// @returns true if an error occurs, false otherwise
> - /// @brief Link libraries into the module
> - bool LinkInLibraries (
> - const std::vector<std::string> & Libraries ///< Libraries to link in
> - );
> -
> - /// 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
> - /// 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
> - /// set.
> - /// @see LinkInArchive
> - /// @see getLastError
> - /// @returns true if an error occurs, false otherwise
> - /// @brief Link one library into the module
> - bool LinkInLibrary (
> - StringRef Library, ///< The library to link in
> - bool& is_native ///< Indicates if lib a native library
> - );
> -
> - /// 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
> - /// symbols can be found. If an error occurs, the error string is set.
> - /// To speed up this function, ensure 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.
> - /// @brief Link in one archive.
> - 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
> @@ -268,13 +181,6 @@
> static bool LinkModules(Module* Dest, Module* Src, unsigned Mode,
> std::string* ErrorMsg);
>
> - /// This function looks through the Linker's LibPaths to find a library with
> - /// the name \p Filename. If the library cannot be found, the returned path
> - /// 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.
> - sys::Path FindLib(StringRef Filename);
> -
> /// @}
> /// @name Implementation
> /// @{
>
> Modified: llvm/trunk/lib/Linker/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/CMakeLists.txt?rev=172749&r1=172748&r2=172749&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Linker/CMakeLists.txt (original)
> +++ llvm/trunk/lib/Linker/CMakeLists.txt Thu Jan 17 13:52:25 2013
> @@ -1,6 +1,4 @@
> add_llvm_library(LLVMLinker
> - LinkArchives.cpp
> - LinkItems.cpp
> LinkModules.cpp
> Linker.cpp
> )
>
> Removed: llvm/trunk/lib/Linker/LinkArchives.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkArchives.cpp?rev=172748&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Linker/LinkArchives.cpp (original)
> +++ llvm/trunk/lib/Linker/LinkArchives.cpp (removed)
> @@ -1,197 +0,0 @@
> -//===- lib/Linker/LinkArchives.cpp - Link LLVM objects and libraries ------===//
> -//
> -// The LLVM Compiler Infrastructure
> -//
> -// This file is distributed under the University of Illinois Open Source
> -// License. See LICENSE.TXT for details.
> -//
> -//===----------------------------------------------------------------------===//
> -//
> -// This file contains routines to handle linking together LLVM bitcode files,
> -// and to handle annoying things like static libraries.
> -//
> -//===----------------------------------------------------------------------===//
> -
> -#include "llvm/Linker.h"
> -#include "llvm/ADT/SetOperations.h"
> -#include "llvm/Bitcode/Archive.h"
> -#include "llvm/IR/Module.h"
> -#include <memory>
> -#include <set>
> -using namespace llvm;
> -
> -/// GetAllUndefinedSymbols - calculates the set of undefined symbols that still
> -/// exist in an LLVM module. This is a bit tricky because there may be two
> -/// symbols with the same name but different LLVM types that will be resolved to
> -/// each other but aren't currently (thus we need to treat it as resolved).
> -///
> -/// Inputs:
> -/// M - The module in which to find undefined symbols.
> -///
> -/// Outputs:
> -/// UndefinedSymbols - A set of C++ strings containing the name of all
> -/// undefined symbols.
> -///
> -static void
> -GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols) {
> - std::set<std::string> DefinedSymbols;
> - UndefinedSymbols.clear();
> -
> - // If the program doesn't define a main, try pulling one in from a .a file.
> - // This is needed for programs where the main function is defined in an
> - // archive, such f2c'd programs.
> - Function *Main = M->getFunction("main");
> - if (Main == 0 || Main->isDeclaration())
> - UndefinedSymbols.insert("main");
> -
> - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
> - if (I->hasName()) {
> - if (I->isDeclaration())
> - UndefinedSymbols.insert(I->getName());
> - else if (!I->hasLocalLinkage()) {
> - assert(!I->hasDLLImportLinkage()
> - && "Found dllimported non-external symbol!");
> - DefinedSymbols.insert(I->getName());
> - }
> - }
> -
> - for (Module::global_iterator I = M->global_begin(), E = M->global_end();
> - I != E; ++I)
> - if (I->hasName()) {
> - if (I->isDeclaration())
> - UndefinedSymbols.insert(I->getName());
> - else if (!I->hasLocalLinkage()) {
> - assert(!I->hasDLLImportLinkage()
> - && "Found dllimported non-external symbol!");
> - DefinedSymbols.insert(I->getName());
> - }
> - }
> -
> - for (Module::alias_iterator I = M->alias_begin(), E = M->alias_end();
> - I != E; ++I)
> - if (I->hasName())
> - DefinedSymbols.insert(I->getName());
> -
> - // Prune out any defined symbols from the undefined symbols set...
> - for (std::set<std::string>::iterator I = UndefinedSymbols.begin();
> - I != UndefinedSymbols.end(); )
> - if (DefinedSymbols.count(*I))
> - UndefinedSymbols.erase(I++); // This symbol really is defined!
> - else
> - ++I; // Keep this symbol in the undefined symbols list
> -}
> -
> -/// LinkInArchive - opens an archive library and link in all objects which
> -/// provide symbols that are currently undefined.
> -///
> -/// Inputs:
> -/// Filename - The pathname of the archive.
> -///
> -/// Return Value:
> -/// TRUE - An error occurred.
> -/// FALSE - No errors.
> -bool
> -Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
> - // Make sure this is an archive file we're dealing with
> - if (!Filename.isArchive())
> - return error("File '" + Filename.str() + "' is not an archive.");
> -
> - // Open the archive file
> - verbose("Linking archive file '" + Filename.str() + "'");
> -
> - // Find all of the symbols currently undefined in the bitcode program.
> - // If all the symbols are defined, the program is complete, and there is
> - // no reason to link in any archive files.
> - std::set<std::string> UndefinedSymbols;
> - GetAllUndefinedSymbols(Composite, UndefinedSymbols);
> -
> - if (UndefinedSymbols.empty()) {
> - verbose("No symbols undefined, skipping library '" + Filename.str() + "'");
> - return false; // No need to link anything in!
> - }
> -
> - std::string ErrMsg;
> - std::auto_ptr<Archive> AutoArch (
> - Archive::OpenAndLoadSymbols(Filename, Context, &ErrMsg));
> -
> - Archive* arch = AutoArch.get();
> -
> - if (!arch)
> - return error("Cannot read archive '" + Filename.str() +
> - "': " + ErrMsg);
> - if (!arch->isBitcodeArchive()) {
> - is_native = true;
> - return false;
> - }
> - is_native = false;
> -
> - // Save a set of symbols that are not defined by the archive. Since we're
> - // entering a loop, there's no point searching for these multiple times. This
> - // variable is used to "set_subtract" from the set of undefined symbols.
> - std::set<std::string> NotDefinedByArchive;
> -
> - // Save the current set of undefined symbols, because we may have to make
> - // multiple passes over the archive:
> - std::set<std::string> CurrentlyUndefinedSymbols;
> -
> - do {
> - CurrentlyUndefinedSymbols = UndefinedSymbols;
> -
> - // Find the modules we need to link into the target module. Note that arch
> - // keeps ownership of these modules and may return the same Module* from a
> - // subsequent call.
> - SmallVector<Module*, 16> Modules;
> - if (!arch->findModulesDefiningSymbols(UndefinedSymbols, Modules, &ErrMsg))
> - return error("Cannot find symbols in '" + Filename.str() +
> - "': " + ErrMsg);
> -
> - // If we didn't find any more modules to link this time, we are done
> - // searching this archive.
> - if (Modules.empty())
> - break;
> -
> - // Any symbols remaining in UndefinedSymbols after
> - // findModulesDefiningSymbols are ones that the archive does not define. So
> - // we add them to the NotDefinedByArchive variable now.
> - NotDefinedByArchive.insert(UndefinedSymbols.begin(),
> - UndefinedSymbols.end());
> -
> - // Loop over all the Modules that we got back from the archive
> - for (SmallVectorImpl<Module*>::iterator I=Modules.begin(), E=Modules.end();
> - I != E; ++I) {
> -
> - // Get the module we must link in.
> - std::string moduleErrorMsg;
> - Module* aModule = *I;
> - if (aModule != NULL) {
> - if (aModule->MaterializeAll(&moduleErrorMsg))
> - return error("Could not load a module: " + moduleErrorMsg);
> -
> - verbose(" Linking in module: " + aModule->getModuleIdentifier());
> -
> - // Link it in
> - if (LinkInModule(aModule, &moduleErrorMsg))
> - return error("Cannot link in module '" +
> - aModule->getModuleIdentifier() + "': " + moduleErrorMsg);
> - }
> - }
> -
> - // Get the undefined symbols from the aggregate module. This recomputes the
> - // symbols we still need after the new modules have been linked in.
> - GetAllUndefinedSymbols(Composite, UndefinedSymbols);
> -
> - // At this point we have two sets of undefined symbols: UndefinedSymbols
> - // which holds the undefined symbols from all the modules, and
> - // NotDefinedByArchive which holds symbols we know the archive doesn't
> - // define. There's no point searching for symbols that we won't find in the
> - // archive so we subtract these sets.
> - set_subtract(UndefinedSymbols, NotDefinedByArchive);
> -
> - // If there's no symbols left, no point in continuing to search the
> - // archive.
> - if (UndefinedSymbols.empty())
> - break;
> - } while (CurrentlyUndefinedSymbols != UndefinedSymbols);
> -
> - return false;
> -}
>
> Removed: llvm/trunk/lib/Linker/LinkItems.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkItems.cpp?rev=172748&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Linker/LinkItems.cpp (original)
> +++ llvm/trunk/lib/Linker/LinkItems.cpp (removed)
> @@ -1,216 +0,0 @@
> -//===- lib/Linker/LinkItems.cpp - Link LLVM objects and libraries ---------===//
> -//
> -// The LLVM Compiler Infrastructure
> -//
> -// This file is distributed under the University of Illinois Open Source
> -// License. See LICENSE.TXT for details.
> -//
> -//===----------------------------------------------------------------------===//
> -//
> -// This file contains routines to handle linking together LLVM bitcode files,
> -// and to handle annoying things like static libraries.
> -//
> -//===----------------------------------------------------------------------===//
> -
> -#include "llvm/Linker.h"
> -#include "llvm/Bitcode/ReaderWriter.h"
> -#include "llvm/IR/Module.h"
> -#include "llvm/Support/ErrorHandling.h"
> -#include "llvm/Support/MemoryBuffer.h"
> -#include "llvm/Support/Path.h"
> -#include "llvm/Support/system_error.h"
> -using namespace llvm;
> -
> -// LinkItems - This function is the main entry point into linking. It takes a
> -// list of LinkItem which indicates the order the files should be linked and
> -// how each file should be treated (plain file or with library search). The
> -// function only links bitcode and produces a result list of items that are
> -// native objects.
> -bool
> -Linker::LinkInItems(const ItemList& Items, ItemList& NativeItems) {
> - // Clear the NativeItems just in case
> - NativeItems.clear();
> -
> - // For each linkage item ...
> - for (ItemList::const_iterator I = Items.begin(), E = Items.end();
> - I != E; ++I) {
> - if (I->second) {
> - // Link in the library suggested.
> - bool is_native = false;
> - if (LinkInLibrary(I->first, is_native))
> - return true;
> - if (is_native)
> - NativeItems.push_back(*I);
> - } else {
> - // Link in the file suggested
> - bool is_native = false;
> - if (LinkInFile(sys::Path(I->first), is_native))
> - return true;
> - if (is_native)
> - NativeItems.push_back(*I);
> - }
> - }
> -
> - return false;
> -}
> -
> -
> -/// LinkInLibrary - links one library into the HeadModule.
> -///
> -bool Linker::LinkInLibrary(StringRef Lib, bool& is_native) {
> - is_native = false;
> - // Determine where this library lives.
> - sys::Path Pathname = FindLib(Lib);
> - if (Pathname.isEmpty())
> - return error("Cannot find library '" + Lib.str() + "'");
> -
> - // If its an archive, try to link it in
> - std::string Magic;
> - Pathname.getMagicNumber(Magic, 64);
> - switch (sys::IdentifyFileType(Magic.c_str(), 64)) {
> - default: llvm_unreachable("Bad file type identification");
> - case sys::Unknown_FileType:
> - return warning("Supposed library '" + Lib.str() + "' isn't a library.");
> -
> - case sys::Bitcode_FileType:
> - // LLVM ".so" file.
> - if (LinkInFile(Pathname, is_native))
> - return true;
> - break;
> -
> - case sys::Archive_FileType:
> - if (LinkInArchive(Pathname, is_native))
> - return error("Cannot link archive '" + Pathname.str() + "'");
> - break;
> -
> - case sys::ELF_Relocatable_FileType:
> - case sys::ELF_SharedObject_FileType:
> - case sys::Mach_O_Object_FileType:
> - case sys::Mach_O_FixedVirtualMemorySharedLib_FileType:
> - case sys::Mach_O_DynamicallyLinkedSharedLib_FileType:
> - case sys::Mach_O_DynamicallyLinkedSharedLibStub_FileType:
> - case sys::COFF_FileType:
> - is_native = true;
> - break;
> - }
> - return false;
> -}
> -
> -/// LinkLibraries - takes the specified library files and links them into the
> -/// main bitcode object file.
> -///
> -/// Inputs:
> -/// Libraries - The list of libraries to link into the module.
> -///
> -/// Return value:
> -/// FALSE - No error.
> -/// TRUE - Error.
> -///
> -bool Linker::LinkInLibraries(const std::vector<std::string> &Libraries) {
> -
> - // Process the set of libraries we've been provided.
> - bool is_native = false;
> - for (unsigned i = 0; i < Libraries.size(); ++i)
> - if (LinkInLibrary(Libraries[i], is_native))
> - return true;
> -
> - return false;
> -}
> -
> -/// LinkInFile - opens a bitcode file and links in all objects which
> -/// provide symbols that are currently undefined.
> -///
> -/// Inputs:
> -/// File - The pathname of the bitcode file.
> -///
> -/// Outputs:
> -/// ErrorMessage - A C++ string detailing what error occurred, if any.
> -///
> -/// Return Value:
> -/// TRUE - An error occurred.
> -/// FALSE - No errors.
> -///
> -bool Linker::LinkInFile(const sys::Path &File, bool &is_native) {
> - is_native = false;
> -
> - // Check for a file of name "-", which means "read standard input"
> - if (File.str() == "-") {
> - std::auto_ptr<Module> M;
> - OwningPtr<MemoryBuffer> Buffer;
> - error_code ec;
> - if (!(ec = MemoryBuffer::getSTDIN(Buffer))) {
> - if (!Buffer->getBufferSize()) {
> - Error = "standard input is empty";
> - } else {
> - M.reset(ParseBitcodeFile(Buffer.get(), Context, &Error));
> - if (M.get())
> - if (!LinkInModule(M.get(), &Error))
> - return false;
> - }
> - }
> - return error("Cannot link stdin: " + ec.message());
> - }
> -
> - // Determine what variety of file it is.
> - std::string Magic;
> - if (!File.getMagicNumber(Magic, 64))
> - return error("Cannot find linker input '" + File.str() + "'");
> -
> - switch (sys::IdentifyFileType(Magic.c_str(), 64)) {
> - default: llvm_unreachable("Bad file type identification");
> - case sys::Unknown_FileType:
> - return warning("Ignoring file '" + File.str() +
> - "' because does not contain bitcode.");
> -
> - case sys::Archive_FileType:
> - // A user may specify an ar archive without -l, perhaps because it
> - // is not installed as a library. Detect that and link the archive.
> - if (LinkInArchive(File, is_native))
> - return true;
> - break;
> -
> - case sys::Bitcode_FileType: {
> - verbose("Linking bitcode file '" + File.str() + "'");
> - std::auto_ptr<Module> M(LoadObject(File));
> - if (M.get() == 0)
> - return error("Cannot load file '" + File.str() + "': " + Error);
> - if (LinkInModule(M.get(), &Error))
> - return error("Cannot link file '" + File.str() + "': " + Error);
> -
> - verbose("Linked in file '" + File.str() + "'");
> - break;
> - }
> -
> - case sys::ELF_Relocatable_FileType:
> - case sys::ELF_SharedObject_FileType:
> - case sys::Mach_O_Object_FileType:
> - case sys::Mach_O_FixedVirtualMemorySharedLib_FileType:
> - case sys::Mach_O_DynamicallyLinkedSharedLib_FileType:
> - case sys::Mach_O_DynamicallyLinkedSharedLibStub_FileType:
> - case sys::COFF_FileType:
> - is_native = true;
> - break;
> - }
> - return false;
> -}
> -
> -/// LinkFiles - takes a module and a list of files and links them all together.
> -/// It locates the file either in the current directory, as its absolute
> -/// or relative pathname, or as a file somewhere in LLVM_LIB_SEARCH_PATH.
> -///
> -/// Inputs:
> -/// Files - A vector of sys::Path indicating the LLVM bitcode filenames
> -/// to be linked. The names can refer to a mixture of pure LLVM
> -/// bitcode files and archive (ar) formatted files.
> -///
> -/// Return value:
> -/// FALSE - No errors.
> -/// TRUE - Some error occurred.
> -///
> -bool Linker::LinkInFiles(const std::vector<sys::Path> &Files) {
> - bool is_native;
> - for (unsigned i = 0; i < Files.size(); ++i)
> - if (LinkInFile(Files[i], is_native))
> - return true;
> - return false;
> -}
>
> Modified: llvm/trunk/lib/Linker/Linker.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/Linker.cpp?rev=172749&r1=172748&r2=172749&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Linker/Linker.cpp (original)
> +++ llvm/trunk/lib/Linker/Linker.cpp Thu Jan 17 13:52:25 2013
> @@ -112,70 +112,3 @@
> Error += ": " + ParseErrorMessage;
> return std::auto_ptr<Module>();
> }
> -
> -// IsLibrary - Determine if "Name" is a library in "Directory". Return
> -// a non-empty sys::Path if its found, an empty one otherwise.
> -static inline sys::Path IsLibrary(StringRef Name,
> - const sys::Path &Directory) {
> -
> - sys::Path FullPath(Directory);
> -
> - // Try the libX.a form
> - FullPath.appendComponent(("lib" + Name).str());
> - FullPath.appendSuffix("a");
> - if (FullPath.isArchive())
> - return FullPath;
> -
> - // Try the libX.bca form
> - FullPath.eraseSuffix();
> - FullPath.appendSuffix("bca");
> - if (FullPath.isArchive())
> - return FullPath;
> -
> - // Try the libX.so (or .dylib) form
> - FullPath.eraseSuffix();
> - FullPath.appendSuffix(sys::Path::GetDLLSuffix());
> - if (FullPath.isDynamicLibrary()) // Native shared library?
> - return FullPath;
> - if (FullPath.isBitcodeFile()) // .so file containing bitcode?
> - return FullPath;
> -
> - // Try libX form, to make it possible to add dependency on the
> - // specific version of .so, like liblzma.so.1.0.0
> - FullPath.eraseSuffix();
> - if (FullPath.isDynamicLibrary()) // Native shared library?
> - return FullPath;
> - if (FullPath.isBitcodeFile()) // .so file containing bitcode?
> - return FullPath;
> -
> - // Not found .. fall through
> -
> - // Indicate that the library was not found in the directory.
> - FullPath.clear();
> - return FullPath;
> -}
> -
> -/// FindLib - Try to convert Filename into the name of a file that we can open,
> -/// if it does not already name a file we can open, by first trying to open
> -/// Filename, then libFilename.[suffix] for each of a set of several common
> -/// library suffixes, in each of the directories in LibPaths. Returns an empty
> -/// Path if no matching file can be found.
> -///
> -sys::Path
> -Linker::FindLib(StringRef Filename) {
> - // Determine if the pathname can be found as it stands.
> - sys::Path FilePath(Filename);
> - if (FilePath.canRead() &&
> - (FilePath.isArchive() || FilePath.isDynamicLibrary()))
> - return FilePath;
> -
> - // Iterate over the directories in Paths to see if we can find the library
> - // there.
> - for (unsigned Index = 0; Index != LibPaths.size(); ++Index) {
> - sys::Path Directory(LibPaths[Index]);
> - sys::Path FullPath = IsLibrary(Filename, Directory);
> - if (!FullPath.isEmpty())
> - return FullPath;
> - }
> - return sys::Path();
> -}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list