diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp index 6b06d48964e3..d0869656a18e 100644 --- a/lld/lib/Driver/GnuLdDriver.cpp +++ b/lld/lib/Driver/GnuLdDriver.cpp @@ -232,6 +232,32 @@ static bool isPathUnderSysroot(StringRef sysroot, StringRef path) { return !path.empty(); } +static std::error_code +evaluateLinkerScriptGroup(ELFLinkingContext &ctx, StringRef path, + const script::Group *group, raw_ostream &diag) { + bool sysroot = (!ctx.getSysroot().empty() + && isPathUnderSysroot(ctx.getSysroot(), path)); + int numfiles = 0; + for (const script::Path &path : group->getPaths()) { + ErrorOr pathOrErr = path._isDashlPrefix + ? ctx.searchLibrary(path._path) : ctx.searchFile(path._path, sysroot); + if (std::error_code ec = pathOrErr.getError()) + return make_dynamic_error_code( + Twine("Unable to find file ") + path._path + ": " + ec.message()); + + std::vector> files + = loadFile(ctx, pathOrErr.get(), false); + for (std::unique_ptr &file : files) { + if (ctx.logInputFiles()) + diag << file->path() << "\n"; + ctx.getNodes().push_back(llvm::make_unique(std::move(file))); + ++numfiles; + } + } + ctx.getNodes().push_back(llvm::make_unique(numfiles)); + return std::error_code(); +} + static std::error_code evaluateLinkerScript(ELFLinkingContext &ctx, StringRef path, raw_ostream &diag) { @@ -248,32 +274,10 @@ evaluateLinkerScript(ELFLinkingContext &ctx, StringRef path, // Evaluate script commands. // Currently we only recognize GROUP() command. - bool sysroot = (!ctx.getSysroot().empty() - && isPathUnderSysroot(ctx.getSysroot(), path)); - for (const script::Command *c : script->_commands) { - auto *group = dyn_cast(c); - if (!group) - continue; - int numfiles = 0; - for (const script::Path &path : group->getPaths()) { - // TODO : Propagate Set WholeArchive/dashlPrefix - ErrorOr pathOrErr = path._isDashlPrefix - ? ctx.searchLibrary(path._path) : ctx.searchFile(path._path, sysroot); - if (std::error_code ec = pathOrErr.getError()) - return make_dynamic_error_code( - Twine("Unable to find file ") + path._path + ": " + ec.message()); - - std::vector> files - = loadFile(ctx, pathOrErr.get(), false); - for (std::unique_ptr &file : files) { - if (ctx.logInputFiles()) - diag << file->path() << "\n"; - ctx.getNodes().push_back(llvm::make_unique(std::move(file))); - ++numfiles; - } - } - ctx.getNodes().push_back(llvm::make_unique(numfiles)); - } + for (const script::Command *c : script->_commands) + if (auto *group = dyn_cast(c)) + if (std::error_code ec = evaluateLinkerScriptGroup(ctx, path, group, diag)) + return ec; return std::error_code(); }