Revert r259143, it broke check-lld on Windows (see PR26388).

llvm-svn: 259395
This commit is contained in:
Nico Weber 2016-02-01 20:03:53 +00:00
parent ac60e5f028
commit f07bd3b72d
7 changed files with 28 additions and 59 deletions

View File

@ -55,10 +55,8 @@ static std::pair<ELFKind, uint16_t> parseEmulation(StringRef S) {
if (S == "aarch64linux") if (S == "aarch64linux")
return {ELF64LEKind, EM_AARCH64}; return {ELF64LEKind, EM_AARCH64};
if (S == "i386pe" || S == "i386pep" || S == "thumb2pe") if (S == "i386pe" || S == "i386pep" || S == "thumb2pe")
error("Windows targets are not supported on the ELF frontend: " + S); fatal("Windows targets are not supported on the ELF frontend: " + S);
else fatal("Unknown emulation: " + S);
error("Unknown emulation: " + S);
return {ELFNoneKind, 0};
} }
// Returns slices of MB by parsing MB as an archive file. // Returns slices of MB by parsing MB as an archive file.
@ -86,8 +84,7 @@ void LinkerDriver::addFile(StringRef Path) {
if (Config->Verbose) if (Config->Verbose)
llvm::outs() << Path << "\n"; llvm::outs() << Path << "\n";
auto MBOrErr = MemoryBuffer::getFile(Path); auto MBOrErr = MemoryBuffer::getFile(Path);
if (error(MBOrErr, "cannot open " + Path)) fatal(MBOrErr, "cannot open " + Path);
return;
std::unique_ptr<MemoryBuffer> &MB = *MBOrErr; std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;
MemoryBufferRef MBRef = MB->getMemBufferRef(); MemoryBufferRef MBRef = MB->getMemBufferRef();
OwningMBs.push_back(std::move(MB)); // take MB ownership OwningMBs.push_back(std::move(MB)); // take MB ownership
@ -112,15 +109,6 @@ void LinkerDriver::addFile(StringRef Path) {
} }
} }
// Add a given library by searching it from input search paths.
void LinkerDriver::addLibrary(StringRef Name) {
std::string Path = searchLibrary(Name);
if (Path.empty())
error("Unable to find library -l" + Name);
else
addFile(Path);
}
// Some command line options or some combinations of them are not allowed. // Some command line options or some combinations of them are not allowed.
// This function checks for such errors. // This function checks for such errors.
static void checkOptions(opt::InputArgList &Args) { static void checkOptions(opt::InputArgList &Args) {
@ -128,15 +116,15 @@ static void checkOptions(opt::InputArgList &Args) {
// of executables or DSOs. We don't support that since the feature // of executables or DSOs. We don't support that since the feature
// does not seem to provide more value than the static archiver. // does not seem to provide more value than the static archiver.
if (Args.hasArg(OPT_relocatable)) if (Args.hasArg(OPT_relocatable))
error("-r option is not supported. Use 'ar' command instead."); fatal("-r option is not supported. Use 'ar' command instead.");
// The MIPS ABI as of 2016 does not support the GNU-style symbol lookup // The MIPS ABI as of 2016 does not support the GNU-style symbol lookup
// table which is a relatively new feature. // table which is a relatively new feature.
if (Config->EMachine == EM_MIPS && Config->GnuHash) if (Config->EMachine == EM_MIPS && Config->GnuHash)
error("The .gnu.hash section is not compatible with the MIPS target."); fatal("The .gnu.hash section is not compatible with the MIPS target.");
if (Config->EMachine == EM_AMDGPU && !Config->Entry.empty()) if (Config->EMachine == EM_AMDGPU && !Config->Entry.empty())
error("-e option is not valid for AMDGPU."); fatal("-e option is not valid for AMDGPU.");
} }
static StringRef static StringRef
@ -160,8 +148,6 @@ void LinkerDriver::main(ArrayRef<const char *> ArgsArr) {
readConfigs(Args); readConfigs(Args);
createFiles(Args); createFiles(Args);
checkOptions(Args); checkOptions(Args);
if (HasError)
return;
switch (Config->EKind) { switch (Config->EKind) {
case ELF32LEKind: case ELF32LEKind:
@ -177,7 +163,7 @@ void LinkerDriver::main(ArrayRef<const char *> ArgsArr) {
link<ELF64BE>(Args); link<ELF64BE>(Args);
return; return;
default: default:
error("-m or at least a .o file required"); fatal("-m or at least a .o file required");
} }
} }
@ -233,7 +219,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
if (auto *Arg = Args.getLastArg(OPT_O)) { if (auto *Arg = Args.getLastArg(OPT_O)) {
StringRef Val = Arg->getValue(); StringRef Val = Arg->getValue();
if (Val.getAsInteger(10, Config->Optimize)) if (Val.getAsInteger(10, Config->Optimize))
error("Invalid optimization level"); fatal("Invalid optimization level");
} }
if (auto *Arg = Args.getLastArg(OPT_hash_style)) { if (auto *Arg = Args.getLastArg(OPT_hash_style)) {
@ -244,7 +230,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
} else if (S == "both") { } else if (S == "both") {
Config->GnuHash = true; Config->GnuHash = true;
} else if (S != "sysv") } else if (S != "sysv")
error("Unknown hash style: " + S); fatal("Unknown hash style: " + S);
} }
for (auto *Arg : Args.filtered(OPT_undefined)) for (auto *Arg : Args.filtered(OPT_undefined))
@ -255,7 +241,7 @@ void LinkerDriver::createFiles(opt::InputArgList &Args) {
for (auto *Arg : Args) { for (auto *Arg : Args) {
switch (Arg->getOption().getID()) { switch (Arg->getOption().getID()) {
case OPT_l: case OPT_l:
addLibrary(Arg->getValue()); addFile(searchLibrary(Arg->getValue()));
break; break;
case OPT_INPUT: case OPT_INPUT:
case OPT_script: case OPT_script:
@ -282,8 +268,8 @@ void LinkerDriver::createFiles(opt::InputArgList &Args) {
} }
} }
if (Files.empty() && !HasError) if (Files.empty())
error("no input files."); fatal("no input files.");
} }
template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {

View File

@ -27,7 +27,6 @@ class LinkerDriver {
public: public:
void main(ArrayRef<const char *> Args); void main(ArrayRef<const char *> Args);
void addFile(StringRef Path); void addFile(StringRef Path);
void addLibrary(StringRef Name);
private: private:
void readConfigs(llvm::opt::InputArgList &Args); void readConfigs(llvm::opt::InputArgList &Args);

View File

@ -66,7 +66,7 @@ opt::InputArgList elf2::parseArgs(llvm::BumpPtrAllocator *A,
// Parse options and then do error checking. // Parse options and then do error checking.
opt::InputArgList Args = Table.ParseArgs(Vec, MissingIndex, MissingCount); opt::InputArgList Args = Table.ParseArgs(Vec, MissingIndex, MissingCount);
if (MissingCount) if (MissingCount)
error(Twine("missing arg value for \"") + Args.getArgString(MissingIndex) + fatal(Twine("missing arg value for \"") + Args.getArgString(MissingIndex) +
"\", expected " + Twine(MissingCount) + "\", expected " + Twine(MissingCount) +
(MissingCount == 1 ? " argument.\n" : " arguments")); (MissingCount == 1 ? " argument.\n" : " arguments"));
@ -74,7 +74,8 @@ opt::InputArgList elf2::parseArgs(llvm::BumpPtrAllocator *A,
for (auto *Arg : Unknowns) for (auto *Arg : Unknowns)
warning("warning: unknown argument: " + Arg->getSpelling()); warning("warning: unknown argument: " + Arg->getSpelling());
if (Unknowns.begin() != Unknowns.end()) if (Unknowns.begin() != Unknowns.end())
error("unknown argument(s) found"); fatal("unknown argument(s) found");
return Args; return Args;
} }
@ -103,7 +104,7 @@ std::string elf2::searchLibrary(StringRef Path) {
if (!S.empty()) if (!S.empty())
return S; return S;
} }
return ""; fatal("Unable to find library -l" + Path);
} }
// Makes a path by concatenating Dir and File. // Makes a path by concatenating Dir and File.

View File

@ -24,18 +24,14 @@ void error(const Twine &Msg) {
HasError = true; HasError = true;
} }
bool error(std::error_code EC, const Twine &Prefix) { void error(std::error_code EC, const Twine &Prefix) {
if (!EC) if (EC)
return false; error(Prefix + ": " + EC.message());
error(Prefix + ": " + EC.message());
return true;
} }
bool error(std::error_code EC) { void error(std::error_code EC) {
if (!EC) if (EC)
return false; error(EC.message());
error(EC.message());
return true;
} }
void fatal(const Twine &Msg) { void fatal(const Twine &Msg) {

View File

@ -20,16 +20,13 @@ extern bool HasError;
void warning(const Twine &Msg); void warning(const Twine &Msg);
void error(const Twine &Msg); void error(const Twine &Msg);
bool error(std::error_code EC, const Twine &Prefix); void error(std::error_code EC, const Twine &Prefix);
bool error(std::error_code EC); void error(std::error_code EC);
template <typename T> bool error(const ErrorOr<T> &V, const Twine &Prefix) { template <typename T> void error(const ErrorOr<T> &V, const Twine &Prefix) {
return error(V.getError(), Prefix); error(V.getError(), Prefix);
}
template <typename T> bool error(const ErrorOr<T> &V) {
return error(V.getError());
} }
template <typename T> void error(const ErrorOr<T> &V) { error(V.getError()); }
LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg); LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg);
void fatal(std::error_code EC, const Twine &Prefix); void fatal(std::error_code EC, const Twine &Prefix);
@ -38,7 +35,6 @@ void fatal(std::error_code EC);
template <typename T> void fatal(const ErrorOr<T> &V, const Twine &Prefix) { template <typename T> void fatal(const ErrorOr<T> &V, const Twine &Prefix) {
fatal(V.getError(), Prefix); fatal(V.getError(), Prefix);
} }
template <typename T> void fatal(const ErrorOr<T> &V) { fatal(V.getError()); } template <typename T> void fatal(const ErrorOr<T> &V) { fatal(V.getError()); }
} // namespace elf2 } // namespace elf2

View File

@ -178,7 +178,7 @@ void LinkerScript::addFile(StringRef S) {
else else
Driver->addFile(Saver.save(Config->Sysroot + "/" + S.substr(1))); Driver->addFile(Saver.save(Config->Sysroot + "/" + S.substr(1)));
} else if (S.startswith("-l")) { } else if (S.startswith("-l")) {
Driver->addLibrary(S.substr(2)); Driver->addFile(searchLibrary(S.substr(2)));
} else if (sys::fs::exists(S)) { } else if (sys::fs::exists(S)) {
Driver->addFile(S); Driver->addFile(S);
} else { } else {

View File

@ -1,9 +0,0 @@
# RUN: not ld.lld -unknown1 -unknown2 -m foo /no/such/file -lnosuchlib \
# RUN: 2>&1 | FileCheck %s
# CHECK: warning: unknown argument: -unknown1
# CHECK: warning: unknown argument: -unknown2
# CHECK: unknown argument(s) found
# CHECK: Unknown emulation: foo
# CHECK: cannot open /no/such/file
# CHECK: Unable to find library -lnosuchlib