Skip to content

Commit 75ab08c

Browse files
aratajewpszymich
authored andcommitted
Guard ELF linking with mutex
LLD ELF linker is not assured to be thread-safe, so it's necessary to quard it with mutex to avoid unexpected behaviour
1 parent afea7f4 commit 75ab08c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

IGC/AdaptorOCL/OCL/sp/spp_g8.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,17 @@ bool CGen8OpenCLProgram::GetZEBinary(
669669
llvm::raw_string_ostream linkOut(linkOutStr);
670670

671671
constexpr bool canExitEarly = false;
672-
if (IGCLLD::elf::link(elfArrRef, canExitEarly, linkOut, linkErr))
672+
bool linked = false;
673+
{
674+
// LLD is not assured to be thread-safe.
675+
// Mutex can be removed as soon as thread-safety is implemented in future versions of LLVM.
676+
static std::mutex linkerMtx;
677+
std::lock_guard<std::mutex> lck(linkerMtx);
678+
linked =
679+
IGCLLD::elf::link(elfArrRef, canExitEarly, linkOut, linkErr);
680+
}
681+
682+
if(linked)
673683
{
674684
// Multiple ELF files linked.
675685
// Copy the data from the linked file to a memory, what will be a source location

0 commit comments

Comments
 (0)