mesa: Fix header search paths

mesa build currently emits CLANG_RESOURCE_DIR into compiled objects and
meson calculates it from llvm cmake files from sysroot and it points to
absolute paths in target sysroot. To fix this backport a patch that does
not rely on CLANG_RESOURCE_DIR, however, this patch still leaves it in
code as fallback via FALLBACK_CLANG_RESOURCE_DIR, we are on LLVM 20.x
which will not use this variable, lets just remove detection so it does
not encode hardcoded paths.

Fixes

ERROR: mesa-2_25.0.2-r0 do_package_qa: QA Issue: File /usr/lib/libMesaOpenCL.so.1.0.0 in package libopencl-mesa contains reference to TMPDIR [buildpaths]
ERROR: mesa-2_25.0.2-r0 do_package_qa: Fatal QA errors were found, failing task.

(From OE-Core rev: afcde8eb575684fb514e1012b31bc0da04f4cb28)

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Cc: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Khem Raj 2025-05-02 09:55:18 -07:00 committed by Richard Purdie
parent 5c996938de
commit 601b05a298
3 changed files with 179 additions and 0 deletions

View File

@ -0,0 +1,143 @@
From e94da9ccbc099468df752227716880efef66411b Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov@redhat.com>
Date: Thu, 27 Feb 2025 15:44:27 +0100
Subject: [PATCH] clover: Don't include libclc headers
Per https://github.com/llvm/llvm-project/issues/119967 these
headers are internal implementation details of libclc and were
never supposed to be installed. They are not available anymore
since LLVM 20. Instead opencl-c.h should be used.
There already ise a code path for including opencl-c.h, so always
use it.
This didn't work for me out of the box, because the build system
currently hardcodes the clang resource directory, which is incorrect
for Fedora at least. Fix this by using GetResourcePath +
CLANG_RESOURCE_DIR provided by clang instead. This is basically
the same as what is done in clc_helper.c
I've still retained the old behavior as a fallback just in case
(e.g. if clang is linked statically?)
Upstream-Status: Submitted [https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33805/]
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33805>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
.../frontends/clover/llvm/invocation.cpp | 53 +++++++++++++------
src/gallium/frontends/clover/meson.build | 5 +-
2 files changed, 39 insertions(+), 19 deletions(-)
diff --git a/src/gallium/frontends/clover/llvm/invocation.cpp b/src/gallium/frontends/clover/llvm/invocation.cpp
index 3cbb05b..ca030b4 100644
--- a/src/gallium/frontends/clover/llvm/invocation.cpp
+++ b/src/gallium/frontends/clover/llvm/invocation.cpp
@@ -24,6 +24,8 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+#include <dlfcn.h>
+
#include <llvm/IR/DiagnosticPrinter.h>
#include <llvm/IR/DiagnosticInfo.h>
#include <llvm/IR/LLVMContext.h>
@@ -39,6 +41,8 @@
#include <clang/Frontend/TextDiagnosticBuffer.h>
#include <clang/Frontend/TextDiagnosticPrinter.h>
#include <clang/Basic/TargetInfo.h>
+#include <clang/Config/config.h>
+#include <clang/Driver/Driver.h>
#if LLVM_VERSION_MAJOR >= 20
#include <llvm/Support/VirtualFileSystem.h>
@@ -323,6 +327,30 @@ namespace {
return c;
}
+ std::string getResourceDirectory() {
+ Dl_info info;
+ if (dladdr((void *)clang::CompilerInvocation::CreateFromArgs, &info) == 0) {
+ return FALLBACK_CLANG_RESOURCE_DIR;
+ }
+
+ char *libclang_path = realpath(info.dli_fname, NULL);
+ if (libclang_path == nullptr) {
+ return FALLBACK_CLANG_RESOURCE_DIR;
+ }
+
+ // GetResourcePath is a way to retrieve the actual libclang resource dir based on a given
+ // binary or library.
+ std::string clang_resource_dir =
+#if LLVM_VERSION_MAJOR >= 20
+ clang::driver::Driver::GetResourcesPath(std::string(libclang_path));
+#else
+ clang::driver::Driver::GetResourcesPath(std::string(libclang_path), CLANG_RESOURCE_DIR);
+#endif
+ free(libclang_path);
+
+ return clang_resource_dir;
+ }
+
std::unique_ptr<Module>
compile(LLVMContext &ctx, clang::CompilerInstance &c,
const std::string &name, const std::string &source,
@@ -331,25 +359,18 @@ namespace {
c.getFrontendOpts().ProgramAction = clang::frontend::EmitLLVMOnly;
c.getHeaderSearchOpts().UseBuiltinIncludes = true;
c.getHeaderSearchOpts().UseStandardSystemIncludes = true;
- c.getHeaderSearchOpts().ResourceDir = CLANG_RESOURCE_DIR;
- if (use_libclc) {
- // Add libclc generic search path
- c.getHeaderSearchOpts().AddPath(LIBCLC_INCLUDEDIR,
- clang::frontend::Angled,
- false, false);
+ std::string clang_resource_dir = getResourceDirectory();
+ c.getHeaderSearchOpts().ResourceDir = clang_resource_dir;
- // Add libclc include
- c.getPreprocessorOpts().Includes.push_back("clc/clc.h");
- } else {
- // Add opencl-c generic search path
- c.getHeaderSearchOpts().AddPath(CLANG_RESOURCE_DIR,
- clang::frontend::Angled,
- false, false);
+ // Add opencl-c generic search path
+ std::string clang_include_path = clang_resource_dir + "/include";
+ c.getHeaderSearchOpts().AddPath(clang_include_path,
+ clang::frontend::Angled,
+ false, false);
- // Add opencl include
- c.getPreprocessorOpts().Includes.push_back("opencl-c.h");
- }
+ // Add opencl include
+ c.getPreprocessorOpts().Includes.push_back("opencl-c.h");
// Add definition for the OpenCL version
const auto dev_version = dev.device_version();
diff --git a/src/gallium/frontends/clover/meson.build b/src/gallium/frontends/clover/meson.build
index e569b86..56a9894 100644
--- a/src/gallium/frontends/clover/meson.build
+++ b/src/gallium/frontends/clover/meson.build
@@ -10,7 +10,6 @@ clover_opencl_cpp_args = [
'-DCL_USE_DEPRECATED_OPENCL_2_0_APIS',
'-DCL_USE_DEPRECATED_OPENCL_2_1_APIS',
'-DCL_USE_DEPRECATED_OPENCL_2_2_APIS',
- '-DLIBCLC_INCLUDEDIR="@0@/"'.format(dep_clc.get_variable(pkgconfig : 'includedir')),
'-DLIBCLC_LIBEXECDIR="@0@/"'.format(dep_clc.get_variable(pkgconfig : 'libexecdir'))
]
clover_incs = [inc_include, inc_src, inc_gallium, inc_gallium_aux]
@@ -43,9 +42,9 @@ libclllvm = static_library(
cpp_args : [
clover_cpp_args,
clover_opencl_cpp_args,
- '-DCLANG_RESOURCE_DIR="@0@"'.format(join_paths(
+ '-DFALLBACK_CLANG_RESOURCE_DIR="@0@"'.format(join_paths(
dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir'), 'clang',
- dep_llvm.version(), 'include',
+ dep_llvm.version()
)),
],
gnu_symbol_visibility : 'hidden',

View File

@ -0,0 +1,34 @@
From 5ea5c5d48e049d7b10b7ffb814e84e3ddef7fff9 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Fri, 25 Apr 2025 19:00:14 -0700
Subject: [PATCH] gallium/clover: Do not use LLVM_LIBRARY_DIR for
FALLBACK_CLANG_RESOURCE_DIR
This option -DFALLBACK_CLANG_RESOURCE_DIR is synthesized by meson from
LLVM_LIBRARY_DIR which is resolved to absolute path under <recipe_sysroot>
and its used in clover front-end as string in .c files, which encodes it
into binary as string and shows up in yocto QA error.
ERROR: mesa-2_25.0.2-r0 do_package_qa: QA Issue: File /usr/lib/libMesaOpenCL.so.1.0.0 in package libopencl-mesa contains reference to TMPDIR [buildpaths]
ERROR: mesa-2_25.0.2-r0 do_package_qa: Fatal QA errors were found, failing task.
ERROR: Logfile of failure stored in: /mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux/mesa/25.0.2/temp/log.do_package_qa.974870
Upstream-Status: Inappropriate [OE-Specific]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
src/gallium/frontends/clover/meson.build | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/gallium/frontends/clover/meson.build b/src/gallium/frontends/clover/meson.build
index 56a9894..32c21d6 100644
--- a/src/gallium/frontends/clover/meson.build
+++ b/src/gallium/frontends/clover/meson.build
@@ -43,7 +43,7 @@ libclllvm = static_library(
clover_cpp_args,
clover_opencl_cpp_args,
'-DFALLBACK_CLANG_RESOURCE_DIR="@0@"'.format(join_paths(
- dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir'), 'clang',
+ '/usr/lib/clang',
dep_llvm.version()
)),
],

View File

@ -18,6 +18,8 @@ SRC_URI = "https://archive.mesa3d.org/mesa-${PV}.tar.xz \
file://0001-meson-misdetects-64bit-atomics-on-mips-clang.patch \ file://0001-meson-misdetects-64bit-atomics-on-mips-clang.patch \
file://0001-freedreno-don-t-encode-build-path-into-binaries.patch \ file://0001-freedreno-don-t-encode-build-path-into-binaries.patch \
file://0001-mesa-clc-add-an-option-to-force-inclusion-of-OpenCL-.patch \ file://0001-mesa-clc-add-an-option-to-force-inclusion-of-OpenCL-.patch \
file://0001-clover-Don-t-include-libclc-headers.patch \
file://0001-gallium-clover-Do-not-use-LLVM_LIBRARY_DIR-for-FALLB.patch \
" "
SRC_URI[sha256sum] = "c0d245dea0aa4b49f74b3d474b16542e4a8799791cd33d676c69f650ad4378d0" SRC_URI[sha256sum] = "c0d245dea0aa4b49f74b3d474b16542e4a8799791cd33d676c69f650ad4378d0"