From 6327dbc4ccca7ccc184305a8d51b219cf6d84776 Mon Sep 17 00:00:00 2001 From: Alex Xie Date: Fri, 13 Nov 2020 14:39:10 -0500 Subject: [PATCH] SWDEV-258808 - OCLSeparateCompile subtest of oclcompiler error [PAL to KFD/ROCr][ROCr_Runtime][Vega10] OCLSeparateCompile subtest of oclcompiler from ocltst test package is encountering clLinkProgram() failed (chksum 0x00000001) error If runtime does not provide a file name as dump file to ELF library, ELF library use a temp file in current folder. The current folder can be not writable for several reasons: 1. The application current folder might be system folder, the user does not have write permission. 2. The current folder is under a readonly file system. This happens for embedded customers. Tested in VEGA10. Issue was fixed. Change-Id: Ic0e9f040b7c7583914301673cce237ab28b0c0cb --- rocclr/device/device.cpp | 10 +++++++++- rocclr/device/device.hpp | 5 ++++- rocclr/device/devprogram.cpp | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/rocclr/device/device.cpp b/rocclr/device/device.cpp index 5d06068c3d..0e7c24ebdb 100644 --- a/rocclr/device/device.cpp +++ b/rocclr/device/device.cpp @@ -749,6 +749,10 @@ bool ClBinary::createElfBinary(bool doencrypt, Program::type_t type) { return false; } + if (tempFile_) { + std::remove(fname_.c_str()); + } + #if defined(HAVE_BLOWFISH_H) if (doencrypt) { // Increase the size by 64 to accomodate extra headers @@ -863,7 +867,8 @@ void ClBinary::resetElfIn() { } } -bool ClBinary::setElfOut(unsigned char eclass, const char* outFile) { +bool ClBinary::setElfOut(unsigned char eclass, + const char* outFile, bool tempFile) { elfOut_ = new amd::Elf(eclass, nullptr, 0, outFile, amd::Elf::ELF_C_WRITE); if ((elfOut_ == nullptr) || !elfOut_->isSuccessful()) { if (elfOut_) { @@ -874,6 +879,9 @@ bool ClBinary::setElfOut(unsigned char eclass, const char* outFile) { return false; } + fname_ = outFile; + tempFile_ = tempFile; + return setElfTarget(); } diff --git a/rocclr/device/device.hpp b/rocclr/device/device.hpp index 7c125e6531..de9fe4226e 100644 --- a/rocclr/device/device.hpp +++ b/rocclr/device/device.hpp @@ -907,7 +907,7 @@ class ClBinary : public amd::HeapObject { void resetElfIn(); //! set out elf - bool setElfOut(unsigned char eclass, const char* outFile); + bool setElfOut(unsigned char eclass, const char* outFile, bool tempFile); void resetElfOut(); //! Set elf header information @@ -1056,6 +1056,9 @@ class ClBinary : public amd::HeapObject { int encryptCode_; //!< Encryption Code for input binary (0 for not encrypted) + std::string fname_; //!< name of elf dump file + bool tempFile_; //!< Is the elf dump file temporary + protected: amd::Elf* elfIn_; //!< ELF object for input ELF binary amd::Elf* elfOut_; //!< ELF object for output ELF binary diff --git a/rocclr/device/devprogram.cpp b/rocclr/device/devprogram.cpp index 403c5ec756..d8e7ef3b65 100644 --- a/rocclr/device/devprogram.cpp +++ b/rocclr/device/devprogram.cpp @@ -1371,15 +1371,20 @@ bool Program::initBuild(amd::option::Options* options) { // Elf Binary setup std::string outFileName; + bool tempFile = false; // true means hsail required clBinary()->init(options, true); if (options->isDumpFlagSet(amd::option::DUMP_BIF)) { outFileName = options->getDumpFileName(".bin"); + } else { + // elf lib needs a writable temp file + outFileName = amd::Os::getTempFileName(); + tempFile = true; } if (!clBinary()->setElfOut(LP64_SWITCH(ELFCLASS32, ELFCLASS64), - (outFileName.size() > 0) ? outFileName.c_str() : nullptr)) { + (outFileName.size() > 0) ? outFileName.c_str() : nullptr, tempFile)) { LogError("Setup elf out for gpu failed"); return false; }