From cb0ff86a3d2c5e85b8f5305f3b7b78539c3f3ea4 Mon Sep 17 00:00:00 2001 From: David Salinas Date: Tue, 29 Nov 2022 18:04:16 +0000 Subject: [PATCH] SWDEV-362823 - remove code to extract hip-clang bundles from .a files --- amd/hipcc/src/hipBin_amd.h | 179 +------------------------------------ 1 file changed, 1 insertion(+), 178 deletions(-) diff --git a/amd/hipcc/src/hipBin_amd.h b/amd/hipcc/src/hipBin_amd.h index 236a1528c56145..6c906aa041c816 100644 --- a/amd/hipcc/src/hipBin_amd.h +++ b/amd/hipcc/src/hipBin_amd.h @@ -638,184 +638,7 @@ void HipBinAmd::executeHipCCCmd(vector argv) { swallowArg = 1; } - // process linker response file for hip-clang - // extract object files from static library and pass them directly to - // hip-clang in command line. - // TODO(hipcc): Remove this after hip-clang switch to lto and lld is able to - // handle clang-offload-bundler bundles. - if ((hipBinUtilPtr_->stringRegexMatch(arg, "^-Wl,@.*")) || - (hipBinUtilPtr_->stringRegexMatch(arg, "^@.*"))) { - // arg will have options type(-Wl,@ or @) and filename - vector split_arg = hipBinUtilPtr_->splitStr(targetsStr, '@'); - string file = split_arg.at(1); - ifstream in(file); - if (!in.is_open()) { - std::cerr << "unable to open file for reading: " << file << endl; - exit(-1); - } - string new_arg; - string tmpdir = hipBinUtilPtr_->getTempDir(); - fs::path new_file = tmpdir; - new_file /= "response_file"; - ofstream out(new_file); - if (!out.is_open()) { - std::cerr << "unable to open file for writing: " << - new_file.string() << endl; - exit(-1); - } - string line; - while (getline(in, line)) { - line = hipBinUtilPtr_->trim(line); - if ((hipBinUtilPtr_->stringRegexMatch(line, ".*\\.a$")) || - (hipBinUtilPtr_->stringRegexMatch(line, ".*\\.lo$"))) { - //## process static library for hip-clang - //## extract object files from static library and - //## pass them directly to hip-clang. - //## ToDo: Remove this after hip-clang switch to lto and - //## lld is able to handle clang-offload-bundler bundles. - string libFile = line; - string path = fs::absolute(line).string(); - // Check if all files in .a are object files. - string cmd = "cd "+ tmpdir + "; ar xv " + path; - SystemCmdOut sysOut; - sysOut = hipBinUtilPtr_->exec(cmd.c_str()); - string cmdOut = sysOut.out; - vector objs = hipBinUtilPtr_->splitStr(cmdOut, '\n'); - bool allIsObj = 1; - string realObjs = ""; - for (unsigned int i=0; i < objs.size(); i++) { - string obj = objs.at(i); - obj = hipBinUtilPtr_->trim(obj); - regex toReplace("x - "); - obj = hipBinUtilPtr_->replaceRegex(obj, toReplace, ""); - obj = "\"" + tmpdir + "/" + obj; - cmd = "file " + obj; - SystemCmdOut sysOut; - sysOut = hipBinUtilPtr_->exec(cmd.c_str()); - string fileType = sysOut.out; - bool isObj; - (hipBinUtilPtr_->substringPresent(fileType, "ELF") || - hipBinUtilPtr_->substringPresent(fileType, "COFF")) ? - isObj = true : isObj = false; - allIsObj = allIsObj && isObj; - if (isObj) { - realObjs = realObjs + " " + obj; - } else { - inputs.push_back(obj); - new_arg = "\"" + new_arg + obj + "\""; - } - } // end of objs for loop - realObjs = hipBinUtilPtr_->trim(realObjs); - if (allIsObj) { - out << line << "\n"; - } else if (!realObjs.empty()) { - fs::path libFilefs = libFile; - string libBaseName = libFilefs.stem().string(); - string libDir = libFilefs.parent_path().string(); - string libExt = libFilefs.extension().string(); - string libBaseNameTemp = libBaseName + "XXXXXX"; - libBaseName = hipBinUtilPtr_->mktempFile(libBaseNameTemp) + libExt; - cmd = "cd " + tmpdir + "; ar rc " + libBaseName + " " +realObjs; - SystemCmdOut sysOut; - sysOut = hipBinUtilPtr_->exec(cmd.c_str()); - string cmdOut = sysOut.out; - out << tmpdir + "/"+ libBaseName + "\n"; - } - } else if (hipBinUtilPtr_->stringRegexMatch(line, ".*\\.o$")) { - string cmd = "file " + line; - SystemCmdOut sysOut; - sysOut = hipBinUtilPtr_->exec(cmd.c_str()); - string fileType = sysOut.out; - bool isObj; - (hipBinUtilPtr_->substringPresent(fileType, "ELF") || - hipBinUtilPtr_->substringPresent(fileType, "COFF")) ? - isObj = true : isObj = false; - if (isObj) { - out << line << "\n"; - } else { - inputs.push_back(line); - new_arg = "\"" + new_arg + " " + line + "\""; - } - } else { - out << line << "\n"; - } - } // end of while loop - in.close(); - out.close(); - arg = "\"" + new_arg +" " +split_arg.at(0) + "\\" + new_file.string(); - escapeArg = 0; - } else if ((hipBinUtilPtr_->stringRegexMatch(arg, ".*\\.a$")) || - (hipBinUtilPtr_->stringRegexMatch(arg, ".*\\.lo$"))) { - string new_arg = ""; - string tmpdir = hipBinUtilPtr_->getTempDir(); - string libFile = arg; - string path = fs::absolute(arg).string(); - string cmd = "cd "+ tmpdir + "; ar xv " + path; - SystemCmdOut sysOut; - sysOut = hipBinUtilPtr_->exec(cmd.c_str()); - string cmdOut = sysOut.out; - vector objs = hipBinUtilPtr_->splitStr(cmdOut, '\n'); - bool allIsObj = 1; - string realObjs = ""; - for (unsigned int i =0; i< objs.size(); i++) { - string obj = objs.at(i); - obj = hipBinUtilPtr_->trim(obj); - regex toReplace("x - "); - string replaceWith = ""; - obj = hipBinUtilPtr_->replaceRegex(obj, toReplace , replaceWith); - obj = "\"" + tmpdir + "/" + obj + "\""; - string cmd = "file " + obj; - SystemCmdOut sysOut; - sysOut = hipBinUtilPtr_->exec(cmd.c_str()); - string fileType = sysOut.out; - bool isObj; - isObj = (hipBinUtilPtr_->substringPresent(fileType, "ELF") || - hipBinUtilPtr_->substringPresent(fileType, "COFF")); - if (hipBinUtilPtr_->substringPresent(fileType, "ELF")) { - cmd = "llvm-readelf -e -W " + obj; - SystemCmdOut sysOut; - sysOut = hipBinUtilPtr_->exec(cmd.c_str()); - string sections = sysOut.out; - isObj = !(hipBinUtilPtr_->substringPresent( - sections, "__CLANG_OFFLOAD_BUNDLE__")); - } - allIsObj = (allIsObj && isObj); - if (isObj) { - realObjs = realObjs + " " + obj; - } else { - inputs.push_back(obj); - if (new_arg != "") { - new_arg += " "; - } - new_arg += "\"" + obj + "\""; - } - } // end of objs for loop - - realObjs = hipBinUtilPtr_->trim(realObjs); - if (allIsObj) { - new_arg = arg; - } else if (!realObjs.empty()) { - fs::path libFilefs = libFile; - string libBaseName = libFilefs.stem().string(); - string libDir = libFilefs.parent_path().string(); - string libExt = libFilefs.extension().string(); - string libBaseNameTemp = libBaseName + "XXXXXX"; - libBaseName = hipBinUtilPtr_->mktempFile( - libBaseNameTemp) + libExt; - string cmd = "cd " + tmpdir +"; ar rc " + - libBaseName + " " + realObjs; - SystemCmdOut sysOut; - sysOut = hipBinUtilPtr_->exec(cmd.c_str()); - string cmdOut = sysOut.out; - new_arg += "\"" + tmpdir +"/" + libBaseName + "\""; - } - arg = "\"" + new_arg + "\""; - escapeArg = 0; - if (hipBinUtilPtr_->stringRegexMatch(toolArgs, ".*-Xlinker$")) { - toolArgs = toolArgs.substr(0, -8); - toolArgs = hipBinUtilPtr_->trim(toolArgs); - } - } else if (arg == "-x") { // end of substring \.a || .lo section + if (arg == "-x") { fileTypeFlag = 1; } else if ((arg == "c" && prevArg == "-x") || (arg == "-xc")) { fileTypeFlag = 1;