Add Clang Support for Legacy Arm Toolchain

less than 1 minute read

Download latest LTS buildroot and arm toolchain

wget -c http://buildroot.org/downloads/buildroot-2024.02.11.tar.xz

arm toolchain can be downloaded from its official website, for this case, I will be using gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf.tar.xz.

Create defconfig

# Target options
BR2_arm=y
BR2_cortex_a7=y
BR2_ARM_FPU_VFPV4=y
BR2_ARM_FPU_NEON_VFPV4=y

# Build options
BR2_SHARED_STATIC_LIBS=y

# Security Hardening Options
BR2_SSP_STRONG=y

BR2_PRIMARY_SITE="https://sources.buildroot.net"
BR2_BACKUP_SITE="https://sources.buildroot.net"
BR2_KERNEL_MIRROR="https://cdn.kernel.org/pub"
BR2_GNU_MIRROR="https://mirrors.aliyun.com/gnu"
BR2_LUAROCKS_MIRROR="https://luarocks.cn"
BR2_CPAN_MIRROR="https://mirrors.aliyun.com/CPAN"
BR2_CCACHE=y

#
# Toolchain
#
BR2_TOOLCHAIN=y
#BR2_TOOLCHAIN_USES_GLIBC=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="$(ARCH)-linux-gnueabihf"
BR2_TOOLCHAIN_EXTERNAL_URL="file://$(TOPDIR)/dl/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf.tar.xz"
BR2_TOOLCHAIN_EXTERNAL_GCC_10=y
BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_18=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC=y
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_TOOLCHAIN_EXTERNAL_FORTRAN=y
BR2_TOOLCHAIN_EXTERNAL_OPENMP=y

# Toolchain Buildroot Options
BR2_TOOLCHAIN_BUILDROOT_VENDOR="buildroot"
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y

# GCC Options
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_PACKAGE_GLIBC_KERNEL_COMPAT=y

#
# Host GDB Options
#
BR2_PACKAGE_HOST_GDB=y
BR2_PACKAGE_HOST_GDB_TUI=y

#
# System configuration
#
BR2_INIT_NONE=y
BR2_SYSTEM_BIN_SH_NONE=y

#
# Target packages
#
# BR2_PACKAGE_BUSYBOX is not set

BR2_PACKAGE_ELFUTILS=y
BR2_PACKAGE_LIBUNWIND=y
BR2_PACKAGE_ZSTD=y
# BR2_TARGET_ROOTFS_TAR is not set
BR2_PACKAGE_BINUTILS=y
BR2_PACKAGE_LIBCURL=y
BR2_PACKAGE_HOST_CMAKE=y
BR2_PACKAGE_CLANG=y
BR2_PACKAGE_COMPILER_RT=y
BR2_PACKAGE_LLVM_BPF=y

Generate SDK

make arm_defconfig
make source
make sdk

Check clang target

clang -v
clang version 15.0.3
Target: arm-buildroot-linux-gnueabihf
Thread model: posix
InstalledDir: /tmp/toolchain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin
clang-15: warning: argument unused during compilation: '-fstack-protector-strong' [-Wunused-command-line-argument]

clang++ -v
clang version 15.0.3
Target: arm-buildroot-linux-gnueabihf
Thread model: posix
InstalledDir: /tmp/toolchain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin
clang-15: warning: argument unused during compilation: '-fstack-protector-strong' [-Wunused-command-line-argument]