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

Rafael EspĂ­ndola rafael.espindola at gmail.com
Thu Mar 13 08:34:12 PDT 2014


On 26 February 2014 07:30, 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).

The normal solution for this is to use a response file. This is
already implemented:

$ echo test.o > list
$ llvm-link -o foo.bc @list

Can you use that instead?

> 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
>



More information about the llvm-commits mailing list