From d6271635b6a8cdc875626433cef4faed4d068fcc Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 28 Sep 2021 00:12:34 +0000 Subject: core/cortex-m0: Use builtins from compiler-rt when using clang When compiling with clang, use the builtins from compiler-rt rather than our own hand-rolled versions. When trying to compile with our versions, clang fails to link: ld.lld: error: core/cortex-m0/div.S:52:(.text.__aeabi_idiv+0x10): unrecognized relocation R_ARM_THM_JUMP8 ld.lld: error: core/cortex-m0/div.S:97:(.text.__aeabi_idivmod+0x24): unrecognized relocation R_ARM_THM_JUMP8 BRANCH=none BUG=b:172020503 TEST=CC=clang make BOARD=servo_v4 TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes Change-Id: I33db397c13bcdcb63bd931d0d8425f9f02a76327 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3188640 Reviewed-by: Abe Levkoy --- core/cortex-m0/build.mk | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/cortex-m0/build.mk b/core/cortex-m0/build.mk index 40764f53c6..8d2002bad5 100644 --- a/core/cortex-m0/build.mk +++ b/core/cortex-m0/build.mk @@ -15,6 +15,8 @@ $(call set-option,CROSS_COMPILE,\ CFLAGS_CPU+=-mthumb ifeq ($(cc-name),clang) CFLAGS_CPU+=-Oz # Like -Os (and thus -O2), but reduces code size further. +# Link compiler-rt when using clang, so clang finds the builtins it provides. +LDFLAGS_EXTRA+=-lclang_rt.builtins-arm else CFLAGS_CPU+=-Os CFLAGS_CPU+=-mno-sched-prolog @@ -26,8 +28,17 @@ CFLAGS_CPU+=-flto LDFLAGS_EXTRA+=-flto endif -core-y=cpu.o debug.o init.o thumb_case.o div.o lmul.o ldivmod.o mula.o uldivmod.o -core-y+=vecttable.o __builtin.o +core-y=cpu.o debug.o init.o thumb_case.o mula.o +# When using clang, we get these as builtins from compiler-rt. +ifneq ($(cc-name),clang) +core-y+=div.o lmul.o ldivmod.o uldivmod.o +endif + +core-y+=vecttable.o +# When using clang, we get these as builtins from compiler-rt. +ifneq ($(cc-name),clang) +core-y+=__builtin.o +endif core-$(CONFIG_COMMON_PANIC_OUTPUT)+=panic.o core-$(CONFIG_COMMON_RUNTIME)+=switch.o task.o -- cgit v1.2.1