From 4d92a069ff93316aa7fb798ed8317476032c5e49 Mon Sep 17 00:00:00 2001 From: jiajia Qian Date: Thu, 11 Jun 2026 09:48:55 +0800 Subject: [PATCH] rusticl: validate input_programs binary type in clLinkProgram According to the OpenCL 3.0 specification (Section 5.8.7), clLinkProgram must return CL_INVALID_OPERATION if the rules for devices containing compiled binaries or libraries as described in the input_programs argument are not followed. For each device, either ALL or NONE of the input programs must contain a compiled binary or library. Mixed cases are invalid. Suggested-by: LingMan <18294-LingMan@users.noreply.gitlab.freedesktop.org> Signed-off-by: jiajia Qian Part-of: --- src/gallium/frontends/rusticl/api/program.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/gallium/frontends/rusticl/api/program.rs b/src/gallium/frontends/rusticl/api/program.rs index be22dc9894a..d68d7f24e88 100644 --- a/src/gallium/frontends/rusticl/api/program.rs +++ b/src/gallium/frontends/rusticl/api/program.rs @@ -474,6 +474,26 @@ pub fn link_program( return Err(CL_INVALID_OPERATION); } + // CL_INVALID_OPERATION if the rules for devices containing compiled binaries + // or libraries as described in input_programs argument above are not followed. + // For each device, either ALL or NONE of the input programs must contain a + // compiled binary or library. Mixed cases are invalid. + for device in &devices { + let mut has_binary = input_programs.iter().map(|program| { + matches!( + program.bin_type(device), + CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT | CL_PROGRAM_BINARY_TYPE_LIBRARY + ) + }); + let all_equal = match has_binary.next() { + Some(maybe_binary) => has_binary.all(|v| maybe_binary == v), + None => true, + }; + if !all_equal { + return Err(CL_INVALID_OPERATION); + } + } + // SAFETY: options is a valid C String or NULL. let options = unsafe { CStr::from_ptr_or_empty(&options) };