Skip to content

Commit cb0ff86

Browse files
author
David Salinas
committed
SWDEV-362823 - remove code to extract hip-clang bundles from .a files
1 parent 359504a commit cb0ff86

File tree

1 file changed

+1
-178
lines changed

1 file changed

+1
-178
lines changed

amd/hipcc/src/hipBin_amd.h

Lines changed: 1 addition & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -638,184 +638,7 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
638638
swallowArg = 1;
639639
}
640640

641-
// process linker response file for hip-clang
642-
// extract object files from static library and pass them directly to
643-
// hip-clang in command line.
644-
// TODO(hipcc): Remove this after hip-clang switch to lto and lld is able to
645-
// handle clang-offload-bundler bundles.
646-
if ((hipBinUtilPtr_->stringRegexMatch(arg, "^-Wl,@.*")) ||
647-
(hipBinUtilPtr_->stringRegexMatch(arg, "^@.*"))) {
648-
// arg will have options type(-Wl,@ or @) and filename
649-
vector<string> split_arg = hipBinUtilPtr_->splitStr(targetsStr, '@');
650-
string file = split_arg.at(1);
651-
ifstream in(file);
652-
if (!in.is_open()) {
653-
std::cerr << "unable to open file for reading: " << file << endl;
654-
exit(-1);
655-
}
656-
string new_arg;
657-
string tmpdir = hipBinUtilPtr_->getTempDir();
658-
fs::path new_file = tmpdir;
659-
new_file /= "response_file";
660-
ofstream out(new_file);
661-
if (!out.is_open()) {
662-
std::cerr << "unable to open file for writing: " <<
663-
new_file.string() << endl;
664-
exit(-1);
665-
}
666-
string line;
667-
while (getline(in, line)) {
668-
line = hipBinUtilPtr_->trim(line);
669-
if ((hipBinUtilPtr_->stringRegexMatch(line, ".*\\.a$")) ||
670-
(hipBinUtilPtr_->stringRegexMatch(line, ".*\\.lo$"))) {
671-
//## process static library for hip-clang
672-
//## extract object files from static library and
673-
//## pass them directly to hip-clang.
674-
//## ToDo: Remove this after hip-clang switch to lto and
675-
//## lld is able to handle clang-offload-bundler bundles.
676-
string libFile = line;
677-
string path = fs::absolute(line).string();
678-
// Check if all files in .a are object files.
679-
string cmd = "cd "+ tmpdir + "; ar xv " + path;
680-
SystemCmdOut sysOut;
681-
sysOut = hipBinUtilPtr_->exec(cmd.c_str());
682-
string cmdOut = sysOut.out;
683-
vector<string> objs = hipBinUtilPtr_->splitStr(cmdOut, '\n');
684-
bool allIsObj = 1;
685-
string realObjs = "";
686-
for (unsigned int i=0; i < objs.size(); i++) {
687-
string obj = objs.at(i);
688-
obj = hipBinUtilPtr_->trim(obj);
689-
regex toReplace("x - ");
690-
obj = hipBinUtilPtr_->replaceRegex(obj, toReplace, "");
691-
obj = "\"" + tmpdir + "/" + obj;
692-
cmd = "file " + obj;
693-
SystemCmdOut sysOut;
694-
sysOut = hipBinUtilPtr_->exec(cmd.c_str());
695-
string fileType = sysOut.out;
696-
bool isObj;
697-
(hipBinUtilPtr_->substringPresent(fileType, "ELF") ||
698-
hipBinUtilPtr_->substringPresent(fileType, "COFF")) ?
699-
isObj = true : isObj = false;
700-
allIsObj = allIsObj && isObj;
701-
if (isObj) {
702-
realObjs = realObjs + " " + obj;
703-
} else {
704-
inputs.push_back(obj);
705-
new_arg = "\"" + new_arg + obj + "\"";
706-
}
707-
} // end of objs for loop
708-
realObjs = hipBinUtilPtr_->trim(realObjs);
709-
if (allIsObj) {
710-
out << line << "\n";
711-
} else if (!realObjs.empty()) {
712-
fs::path libFilefs = libFile;
713-
string libBaseName = libFilefs.stem().string();
714-
string libDir = libFilefs.parent_path().string();
715-
string libExt = libFilefs.extension().string();
716-
string libBaseNameTemp = libBaseName + "XXXXXX";
717-
libBaseName = hipBinUtilPtr_->mktempFile(libBaseNameTemp) + libExt;
718-
cmd = "cd " + tmpdir + "; ar rc " + libBaseName + " " +realObjs;
719-
SystemCmdOut sysOut;
720-
sysOut = hipBinUtilPtr_->exec(cmd.c_str());
721-
string cmdOut = sysOut.out;
722-
out << tmpdir + "/"+ libBaseName + "\n";
723-
}
724-
} else if (hipBinUtilPtr_->stringRegexMatch(line, ".*\\.o$")) {
725-
string cmd = "file " + line;
726-
SystemCmdOut sysOut;
727-
sysOut = hipBinUtilPtr_->exec(cmd.c_str());
728-
string fileType = sysOut.out;
729-
bool isObj;
730-
(hipBinUtilPtr_->substringPresent(fileType, "ELF") ||
731-
hipBinUtilPtr_->substringPresent(fileType, "COFF")) ?
732-
isObj = true : isObj = false;
733-
if (isObj) {
734-
out << line << "\n";
735-
} else {
736-
inputs.push_back(line);
737-
new_arg = "\"" + new_arg + " " + line + "\"";
738-
}
739-
} else {
740-
out << line << "\n";
741-
}
742-
} // end of while loop
743-
in.close();
744-
out.close();
745-
arg = "\"" + new_arg +" " +split_arg.at(0) + "\\" + new_file.string();
746-
escapeArg = 0;
747-
} else if ((hipBinUtilPtr_->stringRegexMatch(arg, ".*\\.a$")) ||
748-
(hipBinUtilPtr_->stringRegexMatch(arg, ".*\\.lo$"))) {
749-
string new_arg = "";
750-
string tmpdir = hipBinUtilPtr_->getTempDir();
751-
string libFile = arg;
752-
string path = fs::absolute(arg).string();
753-
string cmd = "cd "+ tmpdir + "; ar xv " + path;
754-
SystemCmdOut sysOut;
755-
sysOut = hipBinUtilPtr_->exec(cmd.c_str());
756-
string cmdOut = sysOut.out;
757-
vector<string> objs = hipBinUtilPtr_->splitStr(cmdOut, '\n');
758-
bool allIsObj = 1;
759-
string realObjs = "";
760-
for (unsigned int i =0; i< objs.size(); i++) {
761-
string obj = objs.at(i);
762-
obj = hipBinUtilPtr_->trim(obj);
763-
regex toReplace("x - ");
764-
string replaceWith = "";
765-
obj = hipBinUtilPtr_->replaceRegex(obj, toReplace , replaceWith);
766-
obj = "\"" + tmpdir + "/" + obj + "\"";
767-
string cmd = "file " + obj;
768-
SystemCmdOut sysOut;
769-
sysOut = hipBinUtilPtr_->exec(cmd.c_str());
770-
string fileType = sysOut.out;
771-
bool isObj;
772-
isObj = (hipBinUtilPtr_->substringPresent(fileType, "ELF") ||
773-
hipBinUtilPtr_->substringPresent(fileType, "COFF"));
774-
if (hipBinUtilPtr_->substringPresent(fileType, "ELF")) {
775-
cmd = "llvm-readelf -e -W " + obj;
776-
SystemCmdOut sysOut;
777-
sysOut = hipBinUtilPtr_->exec(cmd.c_str());
778-
string sections = sysOut.out;
779-
isObj = !(hipBinUtilPtr_->substringPresent(
780-
sections, "__CLANG_OFFLOAD_BUNDLE__"));
781-
}
782-
allIsObj = (allIsObj && isObj);
783-
if (isObj) {
784-
realObjs = realObjs + " " + obj;
785-
} else {
786-
inputs.push_back(obj);
787-
if (new_arg != "") {
788-
new_arg += " ";
789-
}
790-
new_arg += "\"" + obj + "\"";
791-
}
792-
} // end of objs for loop
793-
794-
realObjs = hipBinUtilPtr_->trim(realObjs);
795-
if (allIsObj) {
796-
new_arg = arg;
797-
} else if (!realObjs.empty()) {
798-
fs::path libFilefs = libFile;
799-
string libBaseName = libFilefs.stem().string();
800-
string libDir = libFilefs.parent_path().string();
801-
string libExt = libFilefs.extension().string();
802-
string libBaseNameTemp = libBaseName + "XXXXXX";
803-
libBaseName = hipBinUtilPtr_->mktempFile(
804-
libBaseNameTemp) + libExt;
805-
string cmd = "cd " + tmpdir +"; ar rc " +
806-
libBaseName + " " + realObjs;
807-
SystemCmdOut sysOut;
808-
sysOut = hipBinUtilPtr_->exec(cmd.c_str());
809-
string cmdOut = sysOut.out;
810-
new_arg += "\"" + tmpdir +"/" + libBaseName + "\"";
811-
}
812-
arg = "\"" + new_arg + "\"";
813-
escapeArg = 0;
814-
if (hipBinUtilPtr_->stringRegexMatch(toolArgs, ".*-Xlinker$")) {
815-
toolArgs = toolArgs.substr(0, -8);
816-
toolArgs = hipBinUtilPtr_->trim(toolArgs);
817-
}
818-
} else if (arg == "-x") { // end of substring \.a || .lo section
641+
if (arg == "-x") {
819642
fileTypeFlag = 1;
820643
} else if ((arg == "c" && prevArg == "-x") || (arg == "-xc")) {
821644
fileTypeFlag = 1;

0 commit comments

Comments
 (0)