All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] llvm: fix native llvm-config RUNPATH
@ 2022-11-13  8:44 Vincent Davis Jr
  2022-11-13 17:44 ` [OE-core] " Alexander Kanavin
  0 siblings, 1 reply; 10+ messages in thread
From: Vincent Davis Jr @ 2022-11-13  8:44 UTC (permalink / raw)
  To: openembedded-core; +Cc: Vincent Davis Jr

Problem occurs when native llvm-config binary is
required by another recipe. RUNPATH is hardcoded
to $ORIGIN/../lib:$ORIGIN/../../lib which depending
upon architecture 'lib' directory name may vary
(i.e 'lib64').

Commit fixes issue by updating rpath on binary to include
architecture dependent directory name.

Commit also fixes issue with llvm-config --libdir command
by setting LLVM_LIBDIR_SUFFIX. Command will return proper
architecture dependent directory name.

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
---
 meta/recipes-devtools/llvm/llvm_git.bb | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/meta/recipes-devtools/llvm/llvm_git.bb b/meta/recipes-devtools/llvm/llvm_git.bb
index 1f47e5d0fb..29eb119be5 100644
--- a/meta/recipes-devtools/llvm/llvm_git.bb
+++ b/meta/recipes-devtools/llvm/llvm_git.bb
@@ -56,6 +56,14 @@ def get_llvm_arch(bb, d, arch_var):
 def get_llvm_host_arch(bb, d):
     return get_llvm_arch(bb, d, 'HOST_ARCH')
 
+def get_llvm_libdir_suffix(bb, d):
+    import re
+    arch = d.getVar('HOST_ARCH')
+    if re.match(r'(x86.64)$', arch):
+        return 64
+    else:
+        return ""
+
 PACKAGECONFIG ??= ""
 # if optviewer OFF, force the modules to be not found or the ones on the host would be found
 PACKAGECONFIG[optviewer] = ",-DPY_PYGMENTS_FOUND=OFF -DPY_PYGMENTS_LEXERS_C_CPP_FOUND=OFF -DPY_YAML_FOUND=OFF,python3-pygments python3-pyyaml,python3-pygments python3-pyyaml"
@@ -64,6 +72,7 @@ PACKAGECONFIG[optviewer] = ",-DPY_PYGMENTS_FOUND=OFF -DPY_PYGMENTS_LEXERS_C_CPP_
 # Default to build all OE-Core supported target arches (user overridable).
 #
 LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}"
+LLVM_TARGET_LIBDIR_SUFFIX ?= "${@get_llvm_libdir_suffix(bb, d)}"
 
 ARM_INSTRUCTION_SET:armv5 = "arm"
 ARM_INSTRUCTION_SET:armv4t = "arm"
@@ -83,6 +92,10 @@ EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \
                   -DCMAKE_BUILD_TYPE=Release \
                   -G Ninja"
 
+EXTRA_OECMAKE:append:class-native = "\
+                  -DLLVM_LIBDIR_SUFFIX=${LLVM_TARGET_LIBDIR_SUFFIX} \
+                  "
+
 EXTRA_OECMAKE:append:class-target = "\
                   -DCMAKE_CROSSCOMPILING:BOOL=ON \
                   -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
@@ -129,6 +142,7 @@ do_install:class-native() {
 }
 
 SYSROOT_PREPROCESS_FUNCS:append:class-target = " llvm_sysroot_preprocess"
+SYSROOT_PREPROCESS_FUNCS:append:class-native = " llvm_sysroot_preprocess_native"
 
 llvm_sysroot_preprocess() {
 	install -d ${SYSROOT_DESTDIR}${bindir_crossscripts}/
@@ -136,6 +150,18 @@ llvm_sysroot_preprocess() {
 	ln -sf llvm-config ${SYSROOT_DESTDIR}${bindir_crossscripts}/llvm-config${PV}
 }
 
+# All of LLVM's shipping binaries have an rpath pointing at ``$ORIGIN/../lib``.
+# Recipe llvm requires llvm-native to compile. When compiling llvm build libraries
+# are located in $ORIGIN/../lib directory. When the llvm-config binary required
+# in another recipe depending upon HOST_ARCH variable libraries may be located
+# in a different directory. Account for both situations here.
+llvm_sysroot_preprocess_native() {
+	chrpath --replace '$ORIGIN'/../lib${LLVM_TARGET_LIBDIR_SUFFIX}:'$ORIGIN'/../../lib${LLVM_TARGET_LIBDIR_SUFFIX}:'$ORIGIN'/../lib:'$ORIGIN'/../../lib \
+                          ${SYSROOT_DESTDIR}${bindir}/llvm-tblgen${PV}
+	chrpath --replace '$ORIGIN'/../lib${LLVM_TARGET_LIBDIR_SUFFIX}:'$ORIGIN'/../../lib${LLVM_TARGET_LIBDIR_SUFFIX}:'$ORIGIN'/../lib:'$ORIGIN'/../../lib \
+                          ${SYSROOT_DESTDIR}${bindir}/llvm-config${PV}
+}
+
 PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto"
 
 RRECOMMENDS:${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liboptremarks"
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-11-14 14:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-13  8:44 [PATCH] llvm: fix native llvm-config RUNPATH Vincent Davis Jr
2022-11-13 17:44 ` [OE-core] " Alexander Kanavin
2022-11-13 19:17   ` Vincent Davis Jr
2022-11-13 21:54     ` [OE-core] " Alexander Kanavin
2022-11-13 21:55       ` Alexander Kanavin
2022-11-14  0:09         ` Vincent Davis Jr
2022-11-14  0:40           ` Vincent Davis Jr
2022-11-14 12:17             ` [OE-core] " Alexander Kanavin
     [not found]             ` <172772A94B18DE42.10474@lists.openembedded.org>
2022-11-14 13:36               ` Alexander Kanavin
2022-11-14 14:46                 ` Vincent Davis Jr

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.