Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -25,6 +25,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Path.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/raw_ostream.h" #include @@ -59,6 +60,10 @@ return !HasError; } +static std::string getOutputName() { + return sys::path::filename(Config->OutputFile); +} + // Parses a linker -m option. static std::tuple parseEmulation(StringRef Emul) { uint8_t OSABI = 0; @@ -88,9 +93,10 @@ if (Ret.first == ELFNoneKind) { if (S == "i386pe" || S == "i386pep" || S == "thumb2pe") - error("Windows targets are not supported on the ELF frontend: " + Emul); + error(getOutputName() + + ": Windows targets are not supported on the ELF frontend: " + Emul); else - error("unknown emulation: " + Emul); + error(getOutputName() + ": unknown emulation: " + Emul); } return std::make_tuple(Ret.first, Ret.second, OSABI); } @@ -152,7 +158,8 @@ return; case file_magic::elf_shared_object: if (Config->Relocatable) { - error("attempted static link of dynamic object " + Path); + error(getOutputName() + ": attempted static link of dynamic object " + + Path); return; } Files.push_back(createSharedFile(MBRef)); @@ -171,7 +178,7 @@ auto MBOrErr = MemoryBuffer::getFile(Path); if (auto EC = MBOrErr.getError()) { - error(EC, "cannot open " + Path); + error(EC, getOutputName() + ": cannot open " + Path); return None; } std::unique_ptr &MB = *MBOrErr; @@ -188,7 +195,7 @@ void LinkerDriver::addLibrary(StringRef Name) { std::string Path = searchLibrary(Name); if (Path.empty()) - error("unable to find library -l" + Name); + error(getOutputName() + ": unable to find library -l" + Name); else addFile(Path); } @@ -217,23 +224,25 @@ // The MIPS ABI as of 2016 does not support the GNU-style symbol lookup // table which is a relatively new feature. if (Config->EMachine == EM_MIPS && Config->GnuHash) - error("the .gnu.hash section is not compatible with the MIPS target."); + error(getOutputName() + + ": the .gnu.hash section is not compatible with the MIPS target."); if (Config->EMachine == EM_AMDGPU && !Config->Entry.empty()) - error("-e option is not valid for AMDGPU."); + error(getOutputName() + ": -e option is not valid for AMDGPU."); if (Config->Pie && Config->Shared) - error("-shared and -pie may not be used together"); + error(getOutputName() + ": -shared and -pie may not be used together"); if (Config->Relocatable) { if (Config->Shared) - error("-r and -shared may not be used together"); + error(getOutputName() + ": -r and -shared may not be used together"); if (Config->GcSections) - error("-r and --gc-sections may not be used together"); + error(getOutputName() + + ": -r and --gc-sections may not be used together"); if (Config->ICF) - error("-r and --icf may not be used together"); + error(getOutputName() + ": -r and --icf may not be used together"); if (Config->Pie) - error("-r and -pie may not be used together"); + error(getOutputName() + ": -r and -pie may not be used together"); } } @@ -276,7 +285,7 @@ Value = Value.substr(Pos + 1); uint64_t Result; if (Value.getAsInteger(0, Result)) - error("invalid " + Key + ": " + Value); + error(getOutputName() + ": invalid " + Key + ": " + Value); return Result; } } @@ -304,7 +313,8 @@ Cpio->append("version.txt", getLLDVersion() + "\n"); } else error(F.getError(), - Twine("--reproduce: failed to open ") + Path + ".cpio"); + Twine(getOutputName() + ": --reproduce: failed to open ") + Path + + ".cpio"); } readConfigs(Args); @@ -347,7 +357,7 @@ return UnresolvedPolicy::Ignore; if (S == "ignore-in-shared-libs" || S == "report-all") return UnresolvedPolicy::ReportError; - error("unknown --unresolved-symbols value: " + S); + error(getOutputName() + ": unknown --unresolved-symbols value: " + S); } return UnresolvedPolicy::ReportError; } @@ -361,7 +371,7 @@ return Target2Policy::Abs; if (S == "got-rel") return Target2Policy::GotRel; - error("unknown --target2 option: " + S); + error(getOutputName() + ": unknown --target2 option: " + S); } return Target2Policy::GotRel; } @@ -371,7 +381,7 @@ StringRef S = Arg->getValue(); if (S == "binary") return true; - error("unknown --oformat value: " + S); + error(getOutputName() + ": unknown --oformat value: " + S); } return false; } @@ -409,7 +419,7 @@ if (S.startswith("0x")) S = S.drop_front(2); if (S.getAsInteger(16, VA)) - error("invalid argument: " + stringize(Arg)); + error(getOutputName() + ": invalid argument: " + stringize(Arg)); return VA; } @@ -438,7 +448,7 @@ if (S == "name") return SortSectionPolicy::Name; if (!S.empty()) - error("unknown --sort-section rule: " + S); + error(getOutputName() + ": unknown --sort-section rule: " + S); return SortSectionPolicy::Default; } @@ -508,19 +518,25 @@ Config->LtoAAPipeline = getString(Args, OPT_lto_aa_pipeline); Config->LtoNewPmPasses = getString(Args, OPT_lto_newpm_passes); Config->OutputFile = getString(Args, OPT_o); + // Default output filename is "a.out" by the Unix tradition. + if (Config->OutputFile.empty()) + Config->OutputFile = "a.out"; + Config->SoName = getString(Args, OPT_soname); Config->Sysroot = getString(Args, OPT_sysroot); Config->Optimize = getInteger(Args, OPT_O, 1); Config->LtoO = getInteger(Args, OPT_lto_O, 2); if (Config->LtoO > 3) - error("invalid optimization level for LTO: " + getString(Args, OPT_lto_O)); + error(getOutputName() + ": invalid optimization level for LTO: " + + getString(Args, OPT_lto_O)); Config->LtoPartitions = getInteger(Args, OPT_lto_partitions, 1); if (Config->LtoPartitions == 0) - error("--lto-partitions: number of threads must be > 0"); + error(getOutputName() + + ": --lto-partitions: number of threads must be > 0"); Config->ThinLtoJobs = getInteger(Args, OPT_thinlto_jobs, -1u); if (Config->ThinLtoJobs == 0) - error("--thinlto-jobs: number of threads must be > 0"); + error(getOutputName() + ": --thinlto-jobs: number of threads must be > 0"); Config->ZCombreloc = !hasZOption(Args, "nocombreloc"); Config->ZExecstack = hasZOption(Args, "execstack"); @@ -672,7 +688,7 @@ Config->MipsN32Abi = Config->EMachine == EM_MIPS && isMipsN32Abi(F); return; } - error("target emulation unknown: -m or at least one .o file required"); + error(getOutputName() + ": target emulation unknown: -m or at least one .o file required"); } // Parses -image-base option. @@ -712,10 +728,6 @@ (Config->EMachine == EM_MIPS && Config->EKind == ELF64LEKind); Config->ImageBase = getImageBase(Args); - // Default output filename is "a.out" by the Unix tradition. - if (Config->OutputFile.empty()) - Config->OutputFile = "a.out"; - // Handle --trace-symbol. for (auto *Arg : Args.filtered(OPT_trace_symbol)) Symtab.trace(Arg->getValue());