使用 LLVM-for-Arm 工具链编译 RT-Thread 源码

Posted RT-Thread物联网操作系统

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用 LLVM-for-Arm 工具链编译 RT-Thread 源码相关的知识,希望对你有一定的参考价值。

使用 LLVM 编译 RT-Thread

硬件测试环境

pdd 不久前搞活动, 99 块买了两块阿里出的 L469 的开发板,最高主频为 80Mhz。所以本次测试硬件就使用该开发板进行测试。

工具准备

1、使用 git 工具下载 llvm 工具链:

git clone https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm.git

2、下载 make 工具:

git clone https://github.com/xpack-dev-tools/windows-build-tools-xpack.git


编译

1、在 rt-thread\\bsp\\stm32\\stm32l496-ali-developer 目录下打开 env 工具:

2、使用命令 scons --target=cmake 生成 CMakelists.txt 文件:

3、这里的命令生成的 CMake 文件使用的是 gcc 的工具链,需要修改一下使用 llvm 的工具链:

1SET(CMAKE_C_COMPILER "D:/download/idm/LLVMEmbeddedToolchainForArm-13.0.0-windows/LLVMEmbeddedToolchainForArm-13.0.0/bin/clang.exe")
 2SET(CMAKE_ASM_COMPILER "D:/download/idm/LLVMEmbeddedToolchainForArm-13.0.0-windows/LLVMEmbeddedToolchainForArm-13.0.0/bin/clang.exe")
 3SET(CMAKE_C_FLAGS "--config armv7em_hard_fpv4_sp_d16_nosys -Os")
 4SET(CMAKE_ASM_FLAGS " -c --config armv7em_hard_fpv4_sp_d16_nosys -Wa,-mimplicit-it=thumb")
 5SET(CMAKE_C_COMPILER_WORKS TRUE)
 6
 7SET(CMAKE_CXX_COMPILER "D:/download/idm/LLVMEmbeddedToolchainForArm-13.0.0-windows/LLVMEmbeddedToolchainForArm-13.0.0/bin/clang++.exe")
 8SET(CMAKE_CXX_FLAGS "--config armv7em_hard_fpv4_sp_d16_nosys -Os")
 9SET(CMAKE_CXX_COMPILER_WORKS TRUE)
10
11SET(CMAKE_OBJCOPY "D:/download/idm/LLVMEmbeddedToolchainForArm-13.0.0-windows/LLVMEmbeddedToolchainForArm-13.0.0/bin/llvm-objcopy.exe")
12SET(CMAKE_SIZE "D:/download/idm/LLVMEmbeddedToolchainForArm-13.0.0-windows/LLVMEmbeddedToolchainForArm-13.0.0/bin/llvm-size.exe")
13
14SET(CMAKE_EXE_LINKER_FLAGS "--config armv7em_hard_fpv4_sp_d16_nosys ,--gc-sections,-Map=rtthread.map,-u,Reset_Handler -T $CMAKE_SOURCE_DIR/board/linker_scripts/link.lds")

4、输入命令 cd build & cmake -G "MinGW Makefiles" .. & D:\\software\\tools\\xpack-windows-build-tools-2.12.2\\bin\\make.exe 编译工程:

1LiuKang@DESKTOP-538H6DE D:\\repo\\github\\rt-thread\\bsp\\stm32\\stm32l496-ali-developer
 2$ cd build
 3
 4LiuKang@DESKTOP-538H6DE D:\\repo\\github\\rt-thread\\bsp\\stm32\\stm32l496-ali-developer\\build
 5$ cmake -G "MinGW Makefiles" ..
 6-- Configuring done
 7-- Generating done
 8-- Build files have been written to: D:/repo/github/rt-thread/bsp/stm32/stm32l496-ali-developer/build
 9
10LiuKang@DESKTOP-538H6DE D:\\repo\\github\\rt-thread\\bsp\\stm32\\stm32l496-ali-developer\\build
11$ D:\\software\\tools\\xpack-windows-build-tools-2.12.2\\bin\\make.exe
12[  1%] Building C object CMakeFiles/rtthread.elf.dir/applications/main.c.obj
13[  2%] Building C object CMakeFiles/rtthread.elf.dir/packages/CoreMark-latest/core_main.c.obj
14[  4%] Building C object CMakeFiles/rtthread.elf.dir/packages/CoreMark-latest/core_util.c.obj
15[  5%] Building C object CMakeFiles/rtthread.elf.dir/packages/CoreMark-latest/core_portme.c.obj
16[  7%] Building C object CMakeFiles/rtthread.elf.dir/packages/CoreMark-latest/core_list_join.c.obj
17[  8%] Building C object CMakeFiles/rtthread.elf.dir/packages/CoreMark-latest/core_state.c.obj
18[ 10%] Building C object CMakeFiles/rtthread.elf.dir/packages/CoreMark-latest/core_matrix.c.obj
19[ 11%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/libcpu/arm/common/showmem.c.obj
20[ 13%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/libcpu/arm/common/div0.c.obj
21[ 14%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/libcpu/arm/common/backtrace.c.obj
22[ 15%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/libcpu/arm/cortex-m4/cpuport.c.obj
23[ 17%] Building ASM object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/libcpu/arm/cortex-m4/context_gcc.S.obj
24[ 18%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/misc/pin.c.obj
25[ 20%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/serial/serial.c.obj
26[ 21%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/dataqueue.c.obj
27[ 23%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/ringblk_buf.c.obj
28[ 24%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/ringbuffer.c.obj
29[ 26%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/waitqueue.c.obj
30[ 27%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/completion.c.obj
31[ 28%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/pipe.c.obj
32[ 30%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/workqueue.c.obj
33[ 31%] Building ASM object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/CMSIS/Device/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l496xx.s.obj
34clang: warning: argument unused during compilation: '-D HAVE_CCONFIG_H' [-Wunused-command-line-argument]
35clang: warning: argument unused during compilation: '-D RT_USING_NEWLIB' [-Wunused-command-line-argument]
36clang: warning: argument unused during compilation: '-D STM32L496xx' [-Wunused-command-line-argument]
37clang: warning: argument unused during compilation: '-D USE_HAL_DRIVER' [-Wunused-command-line-argument]
38clang: warning: argument unused during compilation: '-D __RTTHREAD__' [-Wunused-command-line-argument]
39[ 33%] Building C object CMakeFiles/rtthread.elf.dir/board/CubeMX_Config/Src/stm32l4xx_hal_msp.c.obj
40[ 34%] Building C object CMakeFiles/rtthread.elf.dir/board/board.c.obj
41[ 36%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c.obj
42[ 37%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/HAL_Drivers/drv_usart.c.obj
43[ 39%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/HAL_Drivers/drv_common.c.obj
44[ 40%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/finsh/shell.c.obj
45[ 42%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/finsh/msh.c.obj
46[ 43%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/finsh/cmd.c.obj
47[ 44%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/idle.c.obj
48[ 46%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/kservice.c.obj
49[ 47%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/scheduler.c.obj
50[ 49%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/irq.c.obj
51[ 50%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/timer.c.obj
52[ 52%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/mempool.c.obj
53[ 53%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/ipc.c.obj
54[ 55%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/device.c.obj
55[ 56%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/clock.c.obj
56[ 57%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/thread.c.obj
57[ 59%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/mem.c.obj
58[ 60%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/components.c.obj
59[ 62%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/object.c.obj
60[ 63%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/libc/compilers/common/stdlib.c.obj
61[ 65%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/libc/compilers/common/time.c.obj
62[ 66%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/libc/compilers/gcc/newlib/syscalls.c.obj
63[ 68%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/libc/compilers/gcc/newlib/libc_syms.c.obj
64[ 69%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cryp.c.obj
65[ 71%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c.obj
66[ 72%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_usart.c.obj
67[ 73%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c.obj
68[ 75%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c.obj
69[ 76%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c.obj
70[ 78%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c.obj
71[ 79%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c.obj
72[ 81%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c.obj
73[ 82%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c.obj
74[ 84%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c.obj
75[ 85%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc.c.obj
76[ 86%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c.obj
77[ 88%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_usart_ex.c.obj
78[ 89%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c.obj
79[ 91%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc_ex.c.obj
80[ 92%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_comp.c.obj
81[ 94%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c.obj
82[ 95%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rng.c.obj
83[ 97%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/CMSIS/Device/ST/STM32L4xx/Source/Templates/system_stm32l4xx.c.obj
84[ 98%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cryp_ex.c.obj
85[100%] Linking C executable rtthread.elf
86clang: warning: argument unused during compilation: '-Wa,-mimplicit-it=thumb' [-Wunused-command-line-argument]
87   text    data     bss     dec     hex filename
88 117152    2864    1844  121860   1dc04 rtthread.elf
89[100%] Built target rtthread.elf

5、下载 bin 文件到开发板:

6、llvm 的编译下载就完成啦。


跑分测试

使用 LLVM、GCC、IAR 三种工具链编译出来的可执行文件,测试一下跑分情况:

GCC 5.4.1

优化等级:-Os

GCC 10.3.1

优化等级:-Os

LLVM

优化等级:-Os

IAR

优化等级:

IAR 跑分情况

MDK

优化等级:

MDK AC6 跑分情况

跑分排名

IAR (199.94) > MDK AC6 (160.74) > LLVM (159.24) > GCC 5.4.1 (143.1.8) > GCC 10.3.1 (136.48)

点个在看你最好看

以上是关于使用 LLVM-for-Arm 工具链编译 RT-Thread 源码的主要内容,如果未能解决你的问题,请参考以下文章

NDK交叉编译之自定义工具链

编译工具链和交叉编译工具链简易说明

QtCreator配置交叉编译工具链

arm交叉编译工具链下载

安装交叉编译工具链

LINUX交叉编译工具链和GCC是啥关系啊