diff mbox series

[meta-oe] libjxl: Do not use -mrelax-all on RISCV with clang

Message ID 20240914221903.156933-1-raj.khem@gmail.com
State New
Headers show
Series [meta-oe] libjxl: Do not use -mrelax-all on RISCV with clang | expand

Commit Message

Khem Raj Sept. 14, 2024, 10:18 p.m. UTC
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 ...use-mrelax-all-with-clang-on-RISCV64.patch | 56 +++++++++++++++++++
 .../libjxl/libjxl_0.10.3.bb                   |  4 +-
 2 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 meta-oe/recipes-multimedia/libjxl/libjxl/0001-cmake-Do-not-use-mrelax-all-with-clang-on-RISCV64.patch
diff mbox series

Patch

diff --git a/meta-oe/recipes-multimedia/libjxl/libjxl/0001-cmake-Do-not-use-mrelax-all-with-clang-on-RISCV64.patch b/meta-oe/recipes-multimedia/libjxl/libjxl/0001-cmake-Do-not-use-mrelax-all-with-clang-on-RISCV64.patch
new file mode 100644
index 0000000000..287dfc8ca8
--- /dev/null
+++ b/meta-oe/recipes-multimedia/libjxl/libjxl/0001-cmake-Do-not-use-mrelax-all-with-clang-on-RISCV64.patch
@@ -0,0 +1,56 @@ 
+From 0cf439c243dfdb6eee6133ee87172235a42e59c9 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Sat, 14 Sep 2024 22:04:06 +0000
+Subject: [PATCH] cmake: Do not use -mrelax-all with clang on RISCV64
+
+This option causes clang 19+ to crash on riscv64
+
+For RISC-V -mrelax-all causes the assembler stage to convert
+all conditional branches into
+
+  bcc reg, reg, tmplabel
+  jmp target
+tmplabel:
+
+Unconditional jmp can reach targets a lot further than a conditional branch.
+Unfortunately, jmp also has a limited range so sometimes needs to be
+converted to an indirect jump which requires a scratch register.
+We do all branch relaxation early for RISC-V during the compilation
+stage so we can allocate the scratch register.
+
+If the assembler also does branch relaxation it will increase the size
+of the function and may cause unconditional jmps to go out of range.
+If this happens, linking will fail.
+
+Upstream-Status: Submitted [https://github.com/libjxl/libjxl/pull/3826]
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ CMakeLists.txt | 2 +-
+ CONTRIBUTORS   | 1 +
+ 2 files changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 8b2ccb57..39bee096 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -335,7 +335,7 @@ else ()
+ 
+   # Machine flags.
+   add_compile_options(-funwind-tables)
+-  if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
++  if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "riscv")
+     add_compile_options("SHELL:-Xclang -mrelax-all")
+   endif()
+   if (CXX_CONSTRUCTOR_ALIASES_SUPPORTED)
+diff --git a/CONTRIBUTORS b/CONTRIBUTORS
+index 848096f9..a88c6157 100644
+--- a/CONTRIBUTORS
++++ b/CONTRIBUTORS
+@@ -10,6 +10,7 @@ Iulia-Maria Comșa
+ Jan Wassenberg
+ Jon Sneyers
+ Jyrki Alakuijala
++Khem Raj
+ Krzysztof Potempa
+ Lode Vandevenne
+ Luca Versari
diff --git a/meta-oe/recipes-multimedia/libjxl/libjxl_0.10.3.bb b/meta-oe/recipes-multimedia/libjxl/libjxl_0.10.3.bb
index 3b694e0497..6e6e5edfd7 100644
--- a/meta-oe/recipes-multimedia/libjxl/libjxl_0.10.3.bb
+++ b/meta-oe/recipes-multimedia/libjxl/libjxl_0.10.3.bb
@@ -8,7 +8,9 @@  inherit cmake pkgconfig mime
 
 DEPENDS = "highway brotli"
 
-SRC_URI = "gitsm://github.com/libjxl/libjxl.git;protocol=https;nobranch=1"
+SRC_URI = "gitsm://github.com/libjxl/libjxl.git;protocol=https;nobranch=1 \
+           file://0001-cmake-Do-not-use-mrelax-all-with-clang-on-RISCV64.patch \
+           "
 
 SRCREV = "4a3b22d2600f92d8706fb72d85d52bfee2acbd54"
 S = "${WORKDIR}/git"