public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
From: Deepesh Varatharajan <deepesh.varatharajan@windriver.com>
To: Richard Purdie <richard.purdie@linuxfoundation.org>,
	Khem Raj <raj.khem@gmail.com>, Ross Burton <ross.burton@arm.com>
Cc: openembedded-core@lists.openembedded.org, Sundeep.Kokkonda@windriver.com
Subject: Re: [OE-core] [PATCH V3 1/2] rust: Use clang instead of rust-llvm
Date: Fri, 10 Oct 2025 14:57:11 +0530	[thread overview]
Message-ID: <c92e491f-6348-4c73-b899-c28611a5f803@windriver.com> (raw)
In-Reply-To: <d9e3ca199410d01d4703bc5a07e16632e8a41272.camel@linuxfoundation.org>


On 08-10-2025 18:24, Richard Purdie wrote:
> CAUTION: This email comes from a non Wind River email account!
> Do not click links or open attachments unless you recognize the sender and know the content is safe.
>
> On Wed, 2025-10-08 at 18:19 +0530, Varatharajan, Deepesh via lists.openembedded.org wrote:
>> On 08-10-2025 01:47, Khem Raj wrote:
>>> CAUTION: This email comes from a non Wind River email account!
>>> Do not click links or open attachments unless you recognize the sender and know the content is safe.
>>>
>>> On Tue, Oct 7, 2025 at 4:10 AM Deepesh Varatharajan
>>> <deepesh.varatharajan@windriver.com> wrote:
>>>> On 02-10-2025 00:59, Khem Raj wrote:
>>>>> CAUTION: This email comes from a non Wind River email account!
>>>>> Do not click links or open attachments unless you recognize the sender and know the content is safe.
>>>>>
>>>>> On Mon, Sep 29, 2025 at 1:29 AM Deepesh Varatharajan
>>>>> <deepesh.varatharajan@windriver.com> wrote:
>>>>>> On 26-09-2025 23:00, Khem Raj wrote:
>>>>>>> CAUTION: This email comes from a non Wind River email account!
>>>>>>> Do not click links or open attachments unless you recognize the sender
>>>>>>> and know the content is safe.
>>>>>>>
>>>>>>> On 9/26/25 3:24 AM, Varatharajan, Deepesh via lists.openembedded.org
>>>>>>> wrote:
>>>>>>>> From: Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>
>>>>>>>>
>>>>>>>> Updated the Rust build to depend on Clang instead.
>>>>>>>>
>>>>>>>> *Summary of discussion with the rust upstream about using latest LLVM
>>>>>>>> instead of Rust maintained LLVM fork.
>>>>>>>> https://internals.rust-lang.org/t/can-we-use-proper-clang-instead-of-llvm-fork-what-rust-uses/23489
>>>>>>>>
>>>>>>>>
>>>>>>>> *Upstream LLVM is generally compatible:
>>>>>>>> - Rust does support building with upstream (vanilla) LLVM, especially
>>>>>>>> the latest
>>>>>>>> major release and the one or two preceding ones.
>>>>>>>> https://rustc-dev-guide.rust-lang.org/backend/updating-llvm.html#updating-llvm
>>>>>>>>
>>>>>>>>
>>>>>>>> *Impact on Yocto Rust upgrades:
>>>>>>>> - Rust upgrades shall always check for updates on rust forked llvm
>>>>>>>> and backport
>>>>>>>> the relevant patches to clang's llvm.
>>>>>>>>
>>>>>>>> *Regarding the rust forked llvm local patches:
>>>>>>>> - There are no local patches on rust forked llvm other than the
>>>>>>>> backported fixes
>>>>>>>> from llvm master.
>>>>>>>>
>>>>>>>> *We now add these flags "-Clink-arg=-lz -Clink-arg=-lzstd" because of
>>>>>>>> this following
>>>>>>>> diff otherwise we will get errors during link time.
>>>>>>>>
>>>>>>>> Setup in rust-llvm
>>>>>>>> -DLLVM_ENABLE_ZLIB=OFF \
>>>>>>>> -DLLVM_ENABLE_ZSTD=OFF \
>>>>>>>> -DLLVM_ENABLE_FFI=OFF \
>>>>>>>>
>>>>>>>> Setup in clang
>>>>>>>> -DLLVM_ENABLE_FFI=ON \
>>>>>>>> -DLLVM_ENABLE_ZSTD=ON \
>>>>>>>>
>>>>>>>> *When multilibs enabled:
>>>>>>>>
>>>>>>>> llvm-config expects static libraries to be located in the lib
>>>>>>>> directory rather than
>>>>>>>> lib64. However, since LLVM is built as a non-multilib component, the
>>>>>>>> lib directory
>>>>>>>> doesn't contain any library files. To accommodate this without
>>>>>>>> breaking multilib
>>>>>>>> behavior, we copy the required library files appropriately.
>>>>>>>>
>>>>>>>> Previously, when we depended on rust-llvm, this worked because we
>>>>>>>> specified:
>>>>>>>> -DCMAKE_INSTALL_PREFIX:PATH=${libdir}/llvm-rust
>>>>>>>>
>>>>>>>> With this setup, llvm-config was installed inside
>>>>>>>> ${libdir}/llvm-rust, which included
>>>>>>>> its own bin and lib directories. Thus, llvm-config located in bin
>>>>>>>> would correctly find
>>>>>>>> the libraries in the adjacent lib directory.
>>>>>>>>
>>>>>>>> Even when multilib was enabled or not, llvm-config would still look
>>>>>>>> for libraries under
>>>>>>>> lib in this structure, so everything functioned as expected.
>>>>>>>>
>>>>>>>> *Changes needs to be done when llvm splits from clang:
>>>>>>>> In rust recipe:
>>>>>>>> Update the dependency from:
>>>>>>>> DEPENDS += "ninja-native clang" to DEPENDS += "ninja-native llvm"
>>>>>>>>
>>>>>>>> In llvm recipe:
>>>>>>>> Apply the same changes that were made in the Clang recipe, as those
>>>>>>>> configurations have now been moved to the LLVM recipe after the split.
>>>>>>>>
>>>>>>>> Signed-off-by: Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>
>>>>>>>> ---
>>>>>>>>      meta/recipes-devtools/clang/clang_git.bb     |  4 ++--
>>>>>>>>      meta/recipes-devtools/clang/common-clang.inc |  6 +++---
>>>>>>>>      meta/recipes-devtools/rust/rust_1.90.0.bb    | 18 ++++++++++++++----
>>>>>>>>      3 files changed, 19 insertions(+), 9 deletions(-)
>>>>>>>>
>>>>>>>> diff --git a/meta/recipes-devtools/clang/clang_git.bb
>>>>>>>> b/meta/recipes-devtools/clang/clang_git.bb
>>>>>>>> index 53bca1c24f..3e117b308b 100644
>>>>>>>> --- a/meta/recipes-devtools/clang/clang_git.bb
>>>>>>>> +++ b/meta/recipes-devtools/clang/clang_git.bb
>>>>>>>> @@ -83,7 +83,6 @@ OECMAKE_SOURCEPATH = "${S}/llvm"
>>>>>>>>      # https://github.com/llvm/llvm-project/blob/main/llvm/CMakeLists.txt
>>>>>>>>      LLVM_TARGETS_GPU ?= "${@bb.utils.contains_any('DISTRO_FEATURES',
>>>>>>>> 'opencl opengl vulkan', 'AMDGPU;NVPTX;SPIRV', '', d)}"
>>>>>>>>      LLVM_TARGETS_TO_BUILD ?=
>>>>>>>> "AArch64;ARM;BPF;Mips;PowerPC;RISCV;X86;LoongArch;${LLVM_TARGETS_GPU}"
>>>>>>>> -LLVM_TARGETS_TO_BUILD:class-target ?= "${@get_clang_host_arch(bb,
>>>>>>>> d)};BPF;${LLVM_TARGETS_GPU}"
>>>>>>> compiler we build is building all architectures once because it then
>>>>>>> reuses same compiler for all cross compilers just by creating canonical
>>>>>>> symlinks, this change is not going to work.
>>>>>> We removed this line because, for the clang class-target build, LLVM was
>>>>>> only compiling
>>>>>> libraries for the target architecture and GPU targets and kept inside
>>>>>> the target
>>>>>> sysroot. Since we use the llvm-config built for the class-target during
>>>>>> the Rust target build,
>>>>>> it was failing due to the absence of static libraries for other
>>>>>> architectures in the target sysroot.
>>>>>> Here the target is x86 arch. So, it compiled libraries for x86 arch only
>>>>>> and we can see the error
>>>>>> for missing libraries for other archs as below:
>>>>>>
>>>>>>>    --- stderr
>>>>>>>    llvm-config: error: missing:
>>>>>> poky/build/tmp/work/x86-64-v3-poky-linux/rust/1.90.0/recipe-sysroot/usr/lib/libLLVMAArch64Info.a
>>>>>>>    llvm-config: error: missing:
>>>>>> poky/build/tmp/work/x86-64-v3-poky-linux/rust/1.90.0/recipe-sysroot/usr/lib/libLLVMLoongArchInfo.a
>>>>>>>    llvm-config: error: missing:
>>>>>> poky/build/tmp/work/x86-64-v3-poky-linux/rust/1.90.0/recipe-sysroot/usr/lib/libLLVMLoongArchDisassembler.a
>>>>>>>    llvm-config: error: missing:
>>>>>> poky/build/tmp/work/x86-64-v3-poky-linux/rust/1.90.0/recipe-sysroot/usr/lib/libLLVMMipsInfo.a
>>>>>>>    llvm-config: error: missing:
>>>>>> poky/build/tmp/work/x86-64-v3-poky-linux/rust/1.90.0/recipe-sysroot/usr/lib/libLLVMPowerPCInfo.a
>>>>>>>    llvm-config: error: missing:
>>>>>> poky/build/tmp/work/x86-64-v3-poky-linux/rust/1.90.0/recipe-sysroot/usr/lib/libLLVMRISCVTargetMCA.a
>>>>>> .
>>>>>> .
>>>>>> .
>>>>>>>    thread 'main' panicked at compiler/rustc_llvm/build.rs:277:16:
>>>>>>>    command did not execute successfully:
>>>>>> "poky/build/tmp/work/x86-64-v3-poky-linux/rust/1.90.0/recipe-sysroot/usr/lib/llvm-config"
>>>>>>
>>>>>> "--link-static" "--libs" "aarch64" "amdgpu" "arm" "asmparser"
>>>>>> "bitreader" "bitwriter" "bpf" "coverage" "instrumentation" "ipo" "linker"
>>>>>> "loongarch" "lto" "mips" "nvptx" "powerpc" "riscv" "x86"
>>>>>>>    expected success, got: exit status: 1
>>>>>> Maybe instead of removing. Can we change
>>>>>> -LLVM_TARGETS_TO_BUILD:class-target ?= "${@get_clang_host_arch(bb,
>>>>>> d)};BPF;${LLVM_TARGETS_GPU}"
>>>>>> to
>>>>>> -LLVM_TARGETS_TO_BUILD:class-target ?=
>>>>>> "AArch64;ARM;BPF;Mips;PowerPC;RISCV;X86;LoongArch;;BPF;${LLVM_TARGETS_GPU}"
>>>>>> ?
>>>>> I think we don't want to build all the general arches for target, only
>>>>> the target arch and gpu arches
>>>>> is what is needed.  If we build all the backends, that will slow down
>>>>> things. But if target rust needs
>>>>> to support all the architectures to generate code for, then we don't
>>>>> have much choice. Can you see
>>>>> if we are ok to just target one architecture ?
>>>> The issue doesn't originate from Rust directly, it stems from the
>>>> following logic
>>>> in the Rust recipe, where the natively built llvm-config is copied into
>>>> the target sysroot:
>>>>
>>>>        # Copy the natively built llvm-config into the target so we can run
>>>> it. Horrible,
>>>>        # but works!
>>>>        if [ ${RUST_ALTERNATE_EXE_PATH_NATIVE} !=
>>>> ${RUST_ALTERNATE_EXE_PATH} -a ! -f ${RUST_ALTERNATE_EXE_PATH} ]; then
>>>>            mkdir -p `dirname ${RUST_ALTERNATE_EXE_PATH}`
>>>>            cp ${RUST_ALTERNATE_EXE_PATH_NATIVE} ${RUST_ALTERNATE_EXE_PATH}
>>>>            if [ -e ${STAGING_LIBDIR_NATIVE}/libc++.so.1 ]; then
>>>>                patchelf --set-rpath \$ORIGIN/../../../../../`basename
>>>> ${STAGING_DIR_NATIVE}`${libdir_native} ${RUST_ALTERNATE_EXE_PATH}
>>>>            else
>>>>                patchelf --remove-rpath ${RUST_ALTERNATE_EXE_PATH}
>>>>            fi
>>>>        fi
>>>>
>>>> Since llvm-config is being copied from ${STAGING_BINDIR_NATIVE} to
>>>> ${STAGING_BINDIR},
>>>> and the native Clang was built with the following configuration:
>>>> LLVM_TARGETS_TO_BUILD ?=
>>>> "AArch64;ARM;BPF;Mips;PowerPC;RISCV;X86;LoongArch;${LLVM_TARGETS_GPU}"
>>>>
>>>> The copied llvm-config will expect the corresponding target libraries to
>>>> be present in the ${STAGING_LIBDIR}.
>>>>
>>>> To address this issue, as far as I can see we have three options.
>>>>
>>>> 1) Build clang-target also for all mentioned archs for clang-native.
>>>> 2) Copy all the required libraries from ${STAGING_LIBDIR_NATIVE} to
>>>> ${STAGING_LIBDIR}.
>>>> 3) Instead of copying llvm-config from ${STAGING_BINDIR_NATIVE} to
>>>> ${STAGING_BINDIR},
>>>>         directly make rust-target build dependent
>>>> on  ${STAGING_BINDIR_NATIVE}/llvm-config.
>>>>
>>>> Are there any better or cleaner alternatives to handle this situation?
>>>> Any suggestions would be greatly appreciated.
>>> I would prefer option 3 since these libs are inherently cross built,
>>> it perhaps does not matter if
>>> they come from native or cross built clang. But that would have been
>>> default before this copy dance
>>> was done. I might have forgotten now, if this was done specifically to address a
>>> case which we can testout now.
>> Making Rust depend directly on the native llvm-config is not feasible
>> because librustc_llvm*.rlib
>> is built for the host architecture(x86-64) . While this works if the
>> target is x86-64 or x86, for
>> other architectures we get the following error:
>> we encounter the following error:
>> ld: .../librustc_llvm-f50ec2a9934e24d2.rlib: error adding symbols: file
>> format not recognized
>> collect2: error: ld returned 1 exit status
>>
>> Therefore, copying the natively built llvm-config into the target
>> sysroot and unsetting the RPATH
>> is currently the best approach, and that’s what we are doing. However,
>> even after unsetting the
>> RPATH, the native llvm-config still references to static libraries for
>> other architectures during
>> compile time. To fix this, those libraries must be present in the target
>> sysroot.
>>
>>   From what I see, the only feasible solution is to build LLVM target
>> libraries for all supported
>> architectures. Copying these libraries from the native sysroot is not
>> feasible because the native
>> sysroot contains libs for all OE-core targets, while the target sysroot
>> contains libs only for its
>> specific target—copying would cause conflicts.
> Could it make sense to add in symlinks to the missing pieces between
> the two sysroots? We could make that part sysroot specific, i.e. not
> affect the target packages, just sysroot population?
>
> Thanks for the timings btw. Given that, I could be tempted to merge
> things, then look to improve things again in a follow up patch set.
>
> Curious on others thoughts?
>
> Cheers,
>
> Richard
>
As you suggested, I was able to resolve the missing library issue by 
creating symlinks from the native sysroot to the target sysroot.
However, I'm now encountering a linker error during the build:

../poky/build/tmp/work/cortexa15t2hf-neon-poky-linux-gnueabi/rust/1.90.0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/../../libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/15.2.0/ld: 
../poky/build/tmp/work/cortexa15t2hf-neon-poky-linux-gnueabi/rust/1.90.0/sources/rustc-1.90.0-src/build/x86_64-unknown-linux-gnu/stage1-rustc/armv7-poky-linux-gnueabihf/release/deps/librustc_llvm-3e591ab97f1ae683.rlib: 

error adding symbols: file format not recognized
|           collect2: error: ld returned 1 exit status

Upon investigation, I found that the issue stems from architecture 
mismatches within "librustc_llvm-3e591ab97f1ae683.rlib". I extracted
the object files from this archive and ran the file command to inspect 
them. Most object files were correctly built for the ARM 32-bit (target):
ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), with 
debug_info, not stripped

However, some of the object files (originating from the symlinked native 
sysroot libraries) were built for the host architecture (x86_64):
ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

This mixture of architectures in a single .rlib is causing the linker to 
fail, and confirms that symlinking missing libraries
from the native sysroot won't work. So to resolve the issue we've left 
with only one option to build llvm target also for all
the architectures as we build for native llvm build.

Please let me know if you’re okay with this approach, and I can proceed 
with sending the patch.

Regards,
Deepesh


  reply	other threads:[~2025-10-10  9:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-26 10:24 [PATCH V3 1/2] rust: Use clang instead of rust-llvm Deepesh.Varatharajan
2025-09-26 10:24 ` [PATCH V3 2/2] rust: Drop rust-llvm Deepesh.Varatharajan
2025-09-26 16:50 ` [OE-core] [PATCH V3 1/2] rust: Use clang instead of rust-llvm Khem Raj
2025-09-29 10:17   ` Deepesh Varatharajan
2025-09-26 17:30 ` Khem Raj
2025-09-29  8:29   ` Deepesh Varatharajan
2025-10-01 19:29     ` Khem Raj
2025-10-07 11:10       ` Deepesh Varatharajan
2025-10-07 20:17         ` Khem Raj
2025-10-08 12:49           ` Deepesh Varatharajan
2025-10-08 12:54             ` Richard Purdie
2025-10-10  9:27               ` Deepesh Varatharajan [this message]
2025-10-10  9:36                 ` Richard Purdie
2025-09-29  8:11 ` Mathieu Dubois-Briand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c92e491f-6348-4c73-b899-c28611a5f803@windriver.com \
    --to=deepesh.varatharajan@windriver.com \
    --cc=Sundeep.Kokkonda@windriver.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=raj.khem@gmail.com \
    --cc=richard.purdie@linuxfoundation.org \
    --cc=ross.burton@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox