[PATCH] Add support for a directory argument to llvm-link

Sean Silva silvas at purdue.edu
Fri Mar 14 14:18:04 PDT 2014


On Wed, Feb 26, 2014 at 7:30 AM, Khilan Gudka <Khilan.Gudka at cl.cam.ac.uk>wrote:

> Hi #llvm,
>
> Sometimes when linking a very large number of bit code files together, it
> is not possible if the number exceeds that allowed by the shell. This patch
> adds a -dir flag to llvm-link that allows a single directory to be passed.
> For example:
>
> llvm-link -o linked.bc -dir myDir
>
> This follows the intended philosophy of keeping llvm-link simple
> (exclusively either a directory, or a list of files).
>

This seems counterintuitive and complex to me (complex web of
restrictions). I feel the natural order of things should be that it
interprets positional arguments as files to be linked (i.e. the current
behavior), and any number of `-dir foo/` arguments are scanned for bitcode
files which are added to the list of files to link.

Even better: there is no -dir argument. Positional arguments can be either
bitcode files, or directories. If a positional argument happens to be a
directory, it is scanned for bitcode files, which are added to the list of
inputs. It is not an error to specify a directory that contains no bitcode
files.

-- Sean Silva


>
> http://llvm-reviews.chandlerc.com/D2885
>
> Files:
>   tools/llvm-link/llvm-link.cpp
>
> Index: tools/llvm-link/llvm-link.cpp
> ===================================================================
> --- tools/llvm-link/llvm-link.cpp
> +++ tools/llvm-link/llvm-link.cpp
> @@ -19,19 +19,22 @@
>  #include "llvm/IR/Module.h"
>  #include "llvm/IRReader/IRReader.h"
>  #include "llvm/Support/CommandLine.h"
> +#include "llvm/Support/FileSystem.h"
>  #include "llvm/Support/ManagedStatic.h"
>  #include "llvm/Support/Path.h"
>  #include "llvm/Support/PrettyStackTrace.h"
>  #include "llvm/Support/Signals.h"
>  #include "llvm/Support/SourceMgr.h"
>  #include "llvm/Support/SystemUtils.h"
> +#include "llvm/Support/system_error.h"
>  #include "llvm/Support/ToolOutputFile.h"
>  #include <memory>
>  using namespace llvm;
> +using namespace llvm::sys::fs;
>
>  static cl::list<std::string>
>  InputFilenames(cl::Positional, cl::OneOrMore,
> -               cl::desc("<input bitcode files>"));
> +               cl::desc("<input bitcode files|input bitcode directory>"));
>
>  static cl::opt<std::string>
>  OutputFilename("o", cl::desc("Override output filename"), cl::init("-"),
> @@ -50,6 +53,9 @@
>  static cl::opt<bool>
>  DumpAsm("d", cl::desc("Print assembly as linked"), cl::Hidden);
>
> +static cl::opt<bool>
> +Directory("dir", cl::desc("Input argument is a directory containing
> bitcode files"));
> +
>  // LoadFile - Read the specified bitcode file in and return it.  This
> routine
>  // searches the link path for the specified file to try to find it...
>  //
> @@ -75,6 +81,26 @@
>    llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
>    cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
>
> +  if (Directory) {
> +    if (InputFilenames.size() > 1) {
> +      errs() << "Error: More than one directory specified\n";
> +      return -1;
> +    }
> +
> +    // fill InputFilenames with the name of the files in the argument
> directory,
> +    // thus allowing the code below to work with no changes
> +    error_code ec; // output parameter to store error codes
> +    std::string dir = InputFilenames[0];
> +    InputFilenames.clear();
> +    for (directory_iterator I = directory_iterator(dir, ec), E; I != E;
> I.increment(ec)) {
> +      if (ec != ec.success()) {
> +        errs() << "Error iterating directory: " << ec.message() << "\n";
> +        return -1;
> +      }
> +      InputFilenames.push_back(I->path());
> +    }
> +  }
> +
>    unsigned BaseArg = 0;
>    std::string ErrorMessage;
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140314/76041026/attachment.html>


More information about the llvm-commits mailing list