diff --git a/projects/clr/rocclr/runtime/device/pal/palcompiler.cpp b/projects/clr/rocclr/runtime/device/pal/palcompiler.cpp index 460e7ee80e..ae452d5678 100644 --- a/projects/clr/rocclr/runtime/device/pal/palcompiler.cpp +++ b/projects/clr/rocclr/runtime/device/pal/palcompiler.cpp @@ -345,6 +345,7 @@ LightningProgram::compileImpl( "-c -emit-llvm -target amdgcn-amd-amdhsa-opencl -x cl " << driverOptions << " -include opencl-c.h " << "\n*/\n\n" << sourceCode; + f.close(); } else { buildLog_ += "Warning: opening the file to dump the OpenCL source failed.\n"; @@ -394,9 +395,11 @@ LightningProgram::compileImpl( elfSectionType_ = amd::OclElf::LLVMIR; if (options->isDumpFlagSet(amd::option::DUMP_BC_ORIGINAL)) { - std::ofstream f(options->getDumpFileName("_original.bc").c_str(), std::ios::trunc); + std::ofstream f(options->getDumpFileName("_original.bc").c_str(), + std::ios::binary | std::ios::trunc); if(f.is_open()) { f.write(llvmBinary_.data(), llvmBinary_.size()); + f.close(); } else { buildLog_ += "Warning: opening the file to dump the compiled IR failed.\n"; diff --git a/projects/clr/rocclr/runtime/device/pal/palprogram.cpp b/projects/clr/rocclr/runtime/device/pal/palprogram.cpp index dccee6d56d..4e9ed615a5 100644 --- a/projects/clr/rocclr/runtime/device/pal/palprogram.cpp +++ b/projects/clr/rocclr/runtime/device/pal/palprogram.cpp @@ -1196,9 +1196,11 @@ LightningProgram::linkImpl(amd::option::Options *options) } if (options->isDumpFlagSet(amd::option::DUMP_BC_LINKED)) { - std::ofstream f(options->getDumpFileName("_linked.bc").c_str(), std::ios::trunc); + std::ofstream f(options->getDumpFileName("_linked.bc").c_str(), + std::ios::binary | std::ios::trunc); if(f.is_open()) { f.write(linked_bc->Buf().data(), linked_bc->Size()); + f.close(); } else { buildLog_ += "Warning: opening the file to dump the linked IR failed.\n"; @@ -1239,9 +1241,11 @@ LightningProgram::linkImpl(amd::option::Options *options) } if (options->isDumpFlagSet(amd::option::DUMP_O)) { - std::ofstream f(options->getDumpFileName(".so").c_str(), std::ios::trunc); + std::ofstream f(options->getDumpFileName(".so").c_str(), + std::ios::binary | std::ios::trunc); if(f.is_open()) { f.write(out_exec->Buf().data(), out_exec->Size()); + f.close(); } else { buildLog_ += "Warning: opening the file to dump the code object failed.\n";