Index: tools/lld/lld.cpp =================================================================== --- tools/lld/lld.cpp +++ tools/lld/lld.cpp @@ -20,9 +20,11 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Twine.h" +#include "llvm/Support/Error.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/Process.h" #include "llvm/Support/Signals.h" #include @@ -111,15 +113,25 @@ // and we use it to detect whether we are running tests or not. static bool canExitEarly() { return StringRef(getenv("LLD_IN_TEST")) != "1"; } +static ExitOnError ExitOnErr; + /// Universal linker main(). This linker emulates the gnu, darwin, or /// windows linker based on the argv[0] or -flavor option. -int main(int Argc, const char **Argv) { - // Standard set up, so program fails gracefully. - sys::PrintStackTraceOnErrorSignal(Argv[0]); - PrettyStackTraceProgram StackPrinter(Argc, Argv); - llvm_shutdown_obj Shutdown; +int main(int Argc_, const char **Argv_) { + // Print a stack trace if we signal out. + sys::PrintStackTraceOnErrorSignal(Argv_[0]); + PrettyStackTraceProgram X(Argc_, Argv_); + + ExitOnErr.setBanner("lld: "); + + SmallVector Argv; + SpecificBumpPtrAllocator ArgAllocator; + ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector( + Argv, makeArrayRef(Argv_, Argc_), ArgAllocator))); + + llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - std::vector Args(Argv, Argv + Argc); + std::vector Args(Argv.begin(), Argv.end()); switch (parseFlavor(Args)) { case Gnu: if (isPETarget(Args))