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

Sean Silva silvas at purdue.edu
Fri Mar 14 14:09:49 PDT 2014


On Thu, Mar 13, 2014 at 11:34 AM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

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

I think this is a useful feature to have. Response files force all invokers
of llvm-link to know how to properly escape response files, which is an
inconvenience (that I personally ran into last Summer; do you remember the
hack that I had to use in order to feed all the files to llvm-link from the
LTO script? This option would have simplified things a fair amount).

-- 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
> >
> _______________________________________________
> 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/f83a4bb1/attachment.html>


More information about the llvm-commits mailing list