Hi Jerome, On Fri, 6 Jun 2025 at 02:58, Jerome Forissier <jerome.foriss...@linaro.org> wrote: > > > > On 6/6/25 00:10, Raymond Mao wrote: > > Hi Tom, > > > > On Thu, 5 Jun 2025 at 17:46, Tom Rini <tr...@konsulko.com> wrote: > >> > >> On Thu, Jun 05, 2025 at 04:52:20PM -0400, Raymond Mao wrote: > >>> Hi Tom, > >>> > >>> On Thu, 5 Jun 2025 at 16:01, Tom Rini <tr...@konsulko.com> wrote: > >>>> > >>>> On Thu, Jun 05, 2025 at 03:45:00PM -0400, Raymond Mao wrote: > >>>>> Hi Tom, > >>>>> > >>>>> On Thu, 5 Jun 2025 at 13:15, Tom Rini <tr...@konsulko.com> wrote: > >>>>>> > >>>>>> On Tue, Jun 03, 2025 at 07:42:55AM -0700, Raymond Mao wrote: > >>>>>> > >>>>>>> MbedTLS bignum module needs '__udivti3' which is a 128-bit division > >>>>>>> function provided by the compiler runtime, typically libgcc for GCC or > >>>>>>> clang_rt.builtins for Clang. > >>>>>>> Thus 'clang_rt.builtins' library is required when building using > >>>>>>> Clang. > >>>>>>> > >>>>>>> This patch supports the location layout of clang_rt.builtins libraries > >>>>>>> from both LLVM pre-15 pattern [1] and post-15(up to 20) pattern [2]. > >>>>>>> > >>>>>>> As a fact that starts from LLVM 20, no official prebuilt multi-targets > >>>>>>> are included and users might need to cross-built it from source. [3] > >>>>>>> is > >>>>>>> an example of instructions for building. > >>>>>>> > >>>>>>> [1] <INST_DIR>/lib/clang/<REV>/lib/linux/libclang_rt.builtins-<ARCH>.a > >>>>>>> E.g. > >>>>>>> lib/clang/14.0.0/lib/linux/libclang_rt.builtins-aarch64.a > >>>>>>> lib/clang/14.0.0/lib/linux/libclang_rt.builtins-x86_64.a > >>>>>>> > >>>>>>> [2] > >>>>>>> <INST_DIR>/lib/clang/<REV_MAJOR>/lib/<CROSSTOOL>/libclang_rt.builtins.a > >>>>>>> E.g. > >>>>>>> lib/clang/20/lib/aarch64-none-linux-gnu/libclang_rt.builtins.a > >>>>>>> lib/clang/20/lib/x86_64-unknown-linux-gnu/libclang_rt.builtins.a > >>>>>>> > >>>>>>> [3] > >>>>>>> git clone https://github.com/llvm/llvm-project.git > >>>>>>> cd llvm-project > >>>>>>> git checkout -b llvmorg-20.1.6 llvmorg-20.1.6 > >>>>>>> mkdir build-builtin && cd build-builtin > >>>>>>> cmake -G Ninja ../llvm \ > >>>>>>> -DCMAKE_BUILD_TYPE=Release \ > >>>>>>> -DCMAKE_C_COMPILER=clang \ > >>>>>>> -DLLVM_ENABLE_PROJECTS="clang" \ > >>>>>>> -DLLVM_ENABLE_RUNTIMES="compiler-rt" \ > >>>>>>> -DLLVM_TARGETS_TO_BUILD="X86;AArch64" \ > >>>>>>> -DLLVM_BUILTIN_TARGETS=\ > >>>>>>> "x86_64-unknown-linux-gnu;aarch64-none-linux-gnu" \ > >>>>>>> -DBUILTINS_aarch64-none-linux-gnu_CMAKE_SYSTEM_NAME=Linux \ > >>>>>>> -DBUILTINS_aarch64-none-linux-gnu_CMAKE_C_COMPILER=\ > >>>>>>> <YOUR_TOOLCHAIN_GCC> \ > >>>>>>> -DBUILTINS_aarch64-none-linux-gnu_CMAKE_ASM_COMPILER=\ > >>>>>>> <YOUR_TOOLCHAIN_GCC> \ > >>>>>>> -DBUILTINS_aarch64-none-linux-gnu_CMAKE_SYSROOT=\ > >>>>>>> <YOUR_TOOLCHAIN_LIBC_DIR> \ > >>>>>>> -DCOMPILER_RT_BUILD_BUILTINS=ON \ > >>>>>>> -DCOMPILER_RT_BUILD_SANITIZERS=OFF \ > >>>>>>> -DCOMPILER_RT_BUILD_XRAY=OFF \ > >>>>>>> -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \ > >>>>>>> -DCOMPILER_RT_BUILD_PROFILE=OFF \ > >>>>>>> -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> \ > >>>>>>> -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF > >>>>>>> ninja builtins > >>>>>>> sudo ninja install > >>>>>>> > >>>>>>> Fixes: 13de8483388c ("mbedtls: add mbedtls into the build system") > >>>>>>> Signed-off-by: Raymond Mao <raymond....@linaro.org> > >>>>>> > >>>>>> I think that newer versions don't even ship this moves us further away > >>>>>> from a solution here as all of the logic. I think we need to look at > >>>>>> the > >>>>>> suggestion of just importing the assembly version of the function. > >>>>> > >>>>> But, the assembly versions are architecture-specific, do you want a > >>>>> portable C code for it? > >>>> > >>>> Is it easily done in C? If not, we can just try and make it clear what > >>>> needs to be pulled out of LLVM sources if/when another platform > >>>> encounters the problem. > >>>> > >>> But maybe we can ask the LLVM project owner why they removed the > >>> prebuilt multi-targets since 20.0.0. > >>> May current patch can support multiple target layouts of pre-15 and > >>> post-15 patterns (I believe they will keep the one of post-15 for the > >>> future), if they can provide the prebuilt multi-targets via package > >>> managers or release tarballs then it is the best solution. > >>> In the future we might need other functions from those libraries and > >>> implementing it in U-Boot is not a good choice IMO. > >> > >> I think adding all of that logic to the Makefile is taking us down the > >> wrong path. Looking at the kernel, they're working with LLVM to be able > >> to disable these 128bit intrinsics currently (as part of rust support). > > Good to know. > > >> So hopefully we just need some temporary workaround until things get > >> fixed upstream. > >> > > I will try to implement a C code function as a temporary solution and > > be back shortly. > > To solve a similar issue in OP-TEE we decided to import a few files > unmodified from the LLVM compiler-rt tree, and that's plain C [1]. OTOH if > it's only a temporary solution, maybe a single C file can be put together. > Sounds good. I can put the same stuff under '<u-boot>/lib/mbedtls/port/compiler-rt'. Thanks for sharing.
Raymond > [1] > https://github.com/OP-TEE/optee_os/commit/48952fd403d867dbf13675e062cd8a7d2e5260a9 > > HTH, > -- > Jerome