Bug 282316 - graphics/mesa-dri: fix build with clang 19
Summary: graphics/mesa-dri: fix build with clang 19
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-x11 (Nobody)
URL: https://gitlab.freedesktop.org/mesa/m...
Keywords:
Depends on: 281729
Blocks:
  Show dependency treegraph
 
Reported: 2024-10-25 05:24 UTC by Jung-uk Kim
Modified: 2024-11-02 00:40 UTC (History)
2 users (show)

See Also:
manu: maintainer-feedback+


Attachments
Fix build with clang 19 (1.34 KB, patch)
2024-10-25 05:24 UTC, Jung-uk Kim
no flags Details | Diff
Fix build with clang 19 and correct TLS model (3.04 KB, patch)
2024-10-25 17:46 UTC, Jung-uk Kim
no flags Details | Diff
Fix build with clang 19 and correct TLS model (1.65 KB, patch)
2024-10-29 23:28 UTC, Jung-uk Kim
no flags Details | Diff
Fix build with clang 19 (1.59 KB, patch)
2024-11-01 06:54 UTC, Jung-uk Kim
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jung-uk Kim freebsd_committer freebsd_triage 2024-10-25 05:24:28 UTC
Created attachment 254502 [details]
Fix build with clang 19

Build with llvm19 fails.  It seems the following upstream patch is enough to fix it.

https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29993
Comment 1 Jung-uk Kim freebsd_committer freebsd_triage 2024-10-25 17:46:23 UTC
Created attachment 254511 [details]
Fix build with clang 19 and correct TLS model

I just realized it builds with the previous patch but it does not work because it causes errors like this:

% vulkaninfo
ERROR: [Loader Message] Code 0 : /usr/local/lib/libvulkan_intel.so: Unsupported relocation type 36 in non-PLT relocations

ERROR: [Loader Message] Code 0 : loader_icd_scan: Failed loading library associated with ICD JSON /usr/local/lib/libvulkan_intel.so. Ignoring this JSON
ERROR: [Loader Message] Code 0 : /usr/local/lib/libvulkan_radeon.so: Unsupported relocation type 36 in non-PLT relocations

ERROR: [Loader Message] Code 0 : loader_icd_scan: Failed loading library associated with ICD JSON /usr/local/lib/libvulkan_radeon.so. Ignoring this JSON
ERROR: [Loader Message] Code 0 : /usr/local/lib/libvulkan_lvp.so: Unsupported relocation type 36 in non-PLT relocations

ERROR: [Loader Message] Code 0 : loader_icd_scan: Failed loading library associated with ICD JSON /usr/local/lib/libvulkan_lvp.so. Ignoring this JSON
ERROR: [Loader Message] Code 0 : vkCreateInstance: Found no drivers!
Cannot create Vulkan instance.
This problem is often caused by a faulty installation of the Vulkan driver or attempting to use a GPU that does not support Vulkan.
ERROR at /data/usr/obj/usr/ports/graphics/vulkan-tools/work/Vulkan-Tools-1.3.299/vulkaninfo/./vulkaninfo.h:456:vkCreateInstance failed with ERROR_INCOMPATIBLE_DRIVER

The reason is because clang 19 now supports "-mtls-dialect=gnu2" but our rtld does not support this model (yet?).  Instead, we have been using "-ftls-model=initial-exec" for a while.  This patch adds our TLS implementation.
Comment 2 Emmanuel Vadot freebsd_committer freebsd_triage 2024-10-25 17:58:26 UTC
Can you open some MR upstream for this please ?
Comment 3 Jung-uk Kim freebsd_committer freebsd_triage 2024-10-25 19:57:32 UTC
(In reply to Emmanuel Vadot from comment #2)
https://gitlab.freedesktop.org/mesa/mesa/-/issues/12072
Comment 4 Emmanuel Vadot freebsd_committer freebsd_triage 2024-10-29 07:30:24 UTC
(In reply to Jung-uk Kim from comment #3)

You should open an MR with the patch, then we can add it as PATCHFILES for both mesa-dri and mesa-devel.
Comment 5 Jung-uk Kim freebsd_committer freebsd_triage 2024-10-29 19:13:06 UTC
(In reply to Emmanuel Vadot from comment #4)
I will.  However, it seems GitLab access request will some time.  Please stay tuned.
Comment 6 Jung-uk Kim freebsd_committer freebsd_triage 2024-10-29 19:16:17 UTC
(In reply to Jung-uk Kim from comment #5)
> However, it seems GitLab access request will some time.
                                              ^
                                             take
Comment 7 Jung-uk Kim freebsd_committer freebsd_triage 2024-10-29 23:10:58 UTC
(In reply to Emmanuel Vadot from comment #4)
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31897
Comment 8 Jung-uk Kim freebsd_committer freebsd_triage 2024-10-29 23:28:32 UTC
Created attachment 254627 [details]
Fix build with clang 19 and correct TLS model

Updated with the upstream merge request.
Comment 9 Emmanuel Vadot freebsd_committer freebsd_triage 2024-10-30 06:33:46 UTC
Thanks, you need to bump portrevision too as I guess even with llvm !19 it will change the resulting binaries ? If not go ahead and commit.
Comment 10 Jan Beich freebsd_committer freebsd_triage 2024-10-30 16:17:29 UTC
Likely MFH-unsafe but -CURRENT isn't supported on /quarterly, anyway. Mesa with Clang < 19 defaults to -ftls-model=global-dynamic. Even if -ftls-model=initial-exec is correct for FreeBSD it was broken in the past, see https://gitlab.freedesktop.org/mesa/mesa/-/issues/966

I've reported some regressions in the upstream MR. Only affects mesa-devel but this bug is about mesa-dri, so not a real MFH blocker.
Comment 11 Jung-uk Kim freebsd_committer freebsd_triage 2024-11-01 06:54:40 UTC
Created attachment 254838 [details]
Fix build with clang 19

I disabled support for TLS model because I failed to fix regressions reported by jbeich@.
Comment 12 Jung-uk Kim freebsd_committer freebsd_triage 2024-11-01 07:00:57 UTC
Sorry, it was a wrong PR.
Comment 13 Emmanuel Vadot freebsd_committer freebsd_triage 2024-11-01 07:40:24 UTC
LGTM
Comment 14 Jan Beich freebsd_committer freebsd_triage 2024-11-01 10:39:53 UTC
v2 (attachment 254838 [details]) looks safe for MFH (matches Clang < 19 behavior) but not very useful without bug 281729 on -RELEASEs.

Like comment 9 suggested do bump PORTREVISION to unbreak Vulkan runtime on -CURRENT per comment 1 in the default case (built with clang19 but linked against llvm15). While poudriere often rebuilds all packages on -CURRENT "pkg upgrade" skips those unless shared libs or ABI version change (not sure about OSVERSION bumps).
Comment 15 commit-hook freebsd_committer freebsd_triage 2024-11-01 18:11:34 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=13d55b0eaa133e37a6834fa335d7cf02dc09080d

commit 13d55b0eaa133e37a6834fa335d7cf02dc09080d
Author:     Jung-uk Kim <jkim@FreeBSD.org>
AuthorDate: 2024-11-01 18:09:57 +0000
Commit:     Jung-uk Kim <jkim@FreeBSD.org>
CommitDate: 2024-11-01 18:09:57 +0000

    graphics/mesa-dri: fix build with clang 19

    Reviewed by:    manu
    Tested by:      jbeich
    PR:             282316

 graphics/mesa-dri/Makefile        | 1 +
 graphics/mesa-dri/Makefile.common | 2 ++
 graphics/mesa-dri/distinfo        | 4 ++++
 3 files changed, 7 insertions(+)
Comment 16 commit-hook freebsd_committer freebsd_triage 2024-11-02 00:40:19 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=f093abad37cb6de91f71a72302b6591793ae5f52

commit f093abad37cb6de91f71a72302b6591793ae5f52
Author:     Jan Beich <jbeich@FreeBSD.org>
AuthorDate: 2024-11-01 23:40:32 +0000
Commit:     Jan Beich <jbeich@FreeBSD.org>
CommitDate: 2024-11-01 23:52:43 +0000

    graphics/mesa-libs: force rebuild on -CURRENT after 13d55b0eaa13

    $ glxgears
    Error: couldn't get an RGB, Double-buffered visual

    $ glmark2-wayland
    Error: eglGetDisplay() failed with error: 0x3000
    Error: main: Could not initialize canvas

    $ kmscube
    MESA-LOADER: failed to open iris: /usr/local/lib/libglapi.so.0: Unsupported relocation type 36 in non-PLT relocations
     (search paths /usr/local/lib/dri, suffix _dri)
    MESA-LOADER: failed to open kms_swrast: /usr/local/lib/libglapi.so.0: Unsupported relocation type 36 in non-PLT relocations
     (search paths /usr/local/lib/dri, suffix _dri)
    MESA-LOADER: failed to open swrast: /usr/local/lib/libglapi.so.0: Unsupported relocation type 36 in non-PLT relocations
     (search paths /usr/local/lib/dri, suffix _dri)
    failed to initialize GBM

    PR:             282316

 graphics/mesa-libs/Makefile | 1 +
 1 file changed, 1 insertion(+)