From c22413efbacd4297803c35c6ecceb3809155f0b2 Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Fri, 5 May 2023 21:16:39 -0700 Subject: [PATCH] SWDEV-380857 - Fix bug when reading bitcode file into vector 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: b17056cb93e457aff17983af65396c3a510a72d1] --- projects/clr/hipamd/src/hiprtc/hiprtcInternal.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/projects/clr/hipamd/src/hiprtc/hiprtcInternal.cpp b/projects/clr/hipamd/src/hiprtc/hiprtcInternal.cpp index a27042bbc2..484964c602 100644 --- a/projects/clr/hipamd/src/hiprtc/hiprtcInternal.cpp +++ b/projects/clr/hipamd/src/hiprtc/hiprtcInternal.cpp @@ -598,17 +598,21 @@ bool RTCLinkProgram::AddLinkerDataImpl(std::vector& link_data, hiprtcJITIn } bool RTCLinkProgram::AddLinkerFile(std::string file_path, hiprtcJITInputType input_type) { - std::vector link_file_info; - std::ifstream file_stream{file_path}; if (!file_stream.good()) { return false; } - std::copy(std::istream_iterator(file_stream), std::istream_iterator(), - 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 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);