forked from OSchip/llvm-project
Order of libraries and source files in the f18 frontend
When the f18 frontend calls the link editor, put the libraries and object files in the correct order. Fixes the issues reported here https://github.com/flang-compiler/flang/issues/897 Reviewed By: sscalpone, AlexisPerry Differential Revision: https://reviews.llvm.org/D84340
This commit is contained in:
parent
6784d82d5b
commit
ca0bf440db
|
@ -369,20 +369,24 @@ std::string CompileOtherLanguage(std::string path, DriverOptions &driver) {
|
|||
return {};
|
||||
}
|
||||
|
||||
void Link(std::vector<std::string> &relocatables, DriverOptions &driver) {
|
||||
void Link(std::vector<std::string> &liblist, std::vector<std::string> &objects,
|
||||
DriverOptions &driver) {
|
||||
if (!ParentProcess()) {
|
||||
std::vector<char *> 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);
|
||||
}
|
||||
}
|
||||
|
@ -397,6 +401,7 @@ int main(int argc, char *const argv[]) {
|
|||
bool isPGF90{driver.F18_FCArgs.back().rfind("pgf90") != std::string::npos};
|
||||
|
||||
std::list<std::string> args{argList(argc, argv)};
|
||||
std::vector<std::string> objlist, liblist;
|
||||
std::string prefix{args.front()};
|
||||
args.pop_front();
|
||||
prefix += ": ";
|
||||
|
@ -413,32 +418,37 @@ int main(int argc, char *const argv[]) {
|
|||
|
||||
Fortran::common::IntrinsicTypeDefaultKinds defaultKinds;
|
||||
|
||||
std::vector<std::string> fortranSources, otherSources, relocatables;
|
||||
std::vector<std::string> 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 == "--") {
|
||||
|
@ -682,17 +692,17 @@ int main(int argc, char *const argv[]) {
|
|||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue