SWDEV-380857 - Fix bug when reading bitcode file into vector<char> buffer

The previous implementation using std::copy() resulted in
differences between the in-memory and on-disk representations.
With the updated implementation, we get the same contents.

Change-Id: Iadfae3cd7f7ba99538da2ac4f11f30f5a78260d8


[ROCm/clr commit: b17056cb93]
This commit is contained in:
Jacob Lambert
2023-05-05 21:16:39 -07:00
committato da Jacob Lambert
parent 34f9de0f7e
commit c22413efba
@@ -598,17 +598,21 @@ bool RTCLinkProgram::AddLinkerDataImpl(std::vector<char>& link_data, hiprtcJITIn
}
bool RTCLinkProgram::AddLinkerFile(std::string file_path, hiprtcJITInputType input_type) {
std::vector<char> link_file_info;
std::ifstream file_stream{file_path};
if (!file_stream.good()) {
return false;
}
std::copy(std::istream_iterator<char>(file_stream), std::istream_iterator<char>(),
std::back_inserter(link_file_info));
file_stream.close();
file_stream.seekg(0, std::ios::end);
std::streampos file_size = file_stream.tellg();
file_stream.seekg(0, std::ios::beg);
// Read the file contents
std::vector<char> link_file_info(file_size);
file_stream.read(link_file_info.data(), file_size);
file_stream.close();
std::string link_file_name("Linker Program");
return AddLinkerDataImpl(link_file_info, input_type, link_file_name);