Index: flang/tools/f18/f18.cpp =================================================================== --- flang/tools/f18/f18.cpp +++ flang/tools/f18/f18.cpp @@ -368,20 +368,24 @@ return {}; } -void Link(std::vector &relocatables, DriverOptions &driver) { +void Link(std::vector &liblist, std::vector &objects, + DriverOptions &driver) { if (!ParentProcess()) { std::vector argv; for (size_t j{0}; j < driver.F18_FCArgs.size(); ++j) { argv.push_back(driver.F18_FCArgs[j].data()); } - for (auto &relo : relocatables) { - argv.push_back(relo.data()); + for (auto &obj : objects) { + argv.push_back(obj.data()); } if (!driver.outputPath.empty()) { char dashO[3] = "-o"; argv.push_back(dashO); argv.push_back(driver.outputPath.data()); } + for (auto &lib : liblist) { + argv.push_back(lib.data()); + } Exec(argv, driver.verbose); } } @@ -396,6 +400,7 @@ bool isPGF90{driver.F18_FCArgs.back().rfind("pgf90") != std::string::npos}; std::list args{argList(argc, argv)}; + std::vector objlist, liblist; std::string prefix{args.front()}; args.pop_front(); prefix += ": "; @@ -412,32 +417,37 @@ Fortran::common::IntrinsicTypeDefaultKinds defaultKinds; - std::vector fortranSources, otherSources, relocatables; + std::vector fortranSources, otherSources; bool anyFiles{false}; while (!args.empty()) { std::string arg{std::move(args.front())}; + auto dot{arg.rfind(".")}; + std::string suffix{arg.substr(dot + 1)}; + std::string prefix{arg.substr(0, 2)}; args.pop_front(); if (arg.empty()) { } else if (arg.at(0) != '-') { anyFiles = true; - auto dot{arg.rfind(".")}; if (dot == std::string::npos) { driver.F18_FCArgs.push_back(arg); } else { - std::string suffix{arg.substr(dot + 1)}; if (suffix == "f" || suffix == "F" || suffix == "ff" || suffix == "f90" || suffix == "F90" || suffix == "ff90" || suffix == "f95" || suffix == "F95" || suffix == "ff95" || suffix == "cuf" || suffix == "CUF" || suffix == "f18" || suffix == "F18" || suffix == "ff18") { fortranSources.push_back(arg); - } else if (suffix == "o" || suffix == "a") { - relocatables.push_back(arg); + } else if (suffix == "o" || suffix == "so") { + objlist.push_back(arg); + } else if (suffix == "a") { + liblist.push_back(arg); } else { otherSources.push_back(arg); } } + } else if (prefix == "-l" || suffix == "a") { + liblist.push_back(arg); } else if (arg == "-") { fortranSources.push_back("-"); } else if (arg == "--") { @@ -674,17 +684,17 @@ for (const auto &path : fortranSources) { std::string relo{CompileFortran(path, options, driver, defaultKinds)}; if (!driver.compileOnly && !relo.empty()) { - relocatables.push_back(relo); + objlist.push_back(relo); } } for (const auto &path : otherSources) { std::string relo{CompileOtherLanguage(path, driver)}; if (!driver.compileOnly && !relo.empty()) { - relocatables.push_back(relo); + objlist.push_back(relo); } } - if (!relocatables.empty()) { - Link(relocatables, driver); + if (!objlist.empty()) { + Link(liblist, objlist, driver); } return exitStatus; }