Skip to content

Commit e174d73

Browse files
W-M-Rxiaoxiang781216
authored andcommitted
clang:libclang_rt.builtins-xxx.a supports builtin
1. enable CONFIG_BUILTIN_COMPILER_RT to built libclang_rt.builtins-xxx.a and no longer use the compiler's built-in 2. Modify clang version acquisition to get two decimal points 3. It has been ported to support four architectures: ARM, ARM64, RISCV, and x86_64, among which ARM has been validated Signed-off-by: wangmingrong1 <[email protected]>
1 parent 69100ef commit e174d73

File tree

17 files changed

+907
-18
lines changed

17 files changed

+907
-18
lines changed

Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,6 +2774,7 @@ source "libs/libc/Kconfig"
27742774
source "libs/libm/Kconfig"
27752775
source "libs/libxx/Kconfig"
27762776
source "libs/libdsp/Kconfig"
2777+
source "libs/libbuiltin/Kconfig"
27772778
endmenu
27782779

27792780
menu "Open Asymmetric Multi Processing"

arch/arm/src/cmake/clang.cmake

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ if(TOOLCHAIN_CLANG_CONFIG)
4545
execute_process(COMMAND clang --version
4646
OUTPUT_VARIABLE clang_full_version_string)
4747

48-
string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANGVER
49-
${clang_full_version_string})
48+
string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+\.[0-9]+).*" "\\1"
49+
CLANGVER ${clang_full_version_string})
5050

5151
if(CLANGVER STREQUAL "14.0")
5252
set(TOOLCHAIN_CLANG_CONFIG ${TOOLCHAIN_CLANG_CONFIG}_nosys)
@@ -237,11 +237,24 @@ set(PREPROCESS ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} -E -P -x c)
237237

238238
set(NUTTX_FIND_TOOLCHAIN_LIB_DEFINED true)
239239

240-
function(nuttx_find_toolchain_lib)
241-
execute_process(
242-
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS}
243-
--print-file-name
244-
OUTPUT_STRIP_TRAILING_WHITESPACE
245-
OUTPUT_VARIABLE extra_lib_path)
246-
nuttx_add_extra_library(${extra_lib_path})
247-
endfunction()
240+
if(CONFIG_BUILTIN_TOOLCHAIN)
241+
function(nuttx_find_toolchain_lib)
242+
execute_process(
243+
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS}
244+
--print-file-name
245+
OUTPUT_STRIP_TRAILING_WHITESPACE
246+
OUTPUT_VARIABLE extra_lib_path)
247+
nuttx_add_extra_library(${extra_lib_path})
248+
endfunction()
249+
else()
250+
function(nuttx_find_toolchain_lib)
251+
if(ARGN)
252+
execute_process(
253+
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS}
254+
--print-file-name=${ARGN}
255+
OUTPUT_STRIP_TRAILING_WHITESPACE
256+
OUTPUT_VARIABLE extra_lib_path)
257+
endif()
258+
nuttx_add_extra_library(${extra_lib_path})
259+
endfunction()
260+
endif()

arch/arm/src/common/Toolchain.defs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ ifeq ($(CONFIG_ARM_TOOLCHAIN_CLANG),y)
206206

207207
ifneq ($(TOOLCHAIN_CLANG_CONFIG),)
208208
ifeq ($(CLANGVER),)
209-
export CLANGVER := $(shell $(CC) --version | grep "clang version" | sed -E "s/.* ([0-9]+\.[0-9]+).*/\1/")
209+
export CLANGVER := $(shell $(CC) --version | grep "clang version" | sed -E "s/.* ([0-9]+\.[0-9]+\.[0-9]+).*/\1/")
210210
endif
211211

212212
ifeq ($(CLANGVER),14.0)
@@ -448,14 +448,18 @@ endif
448448

449449
# Add the builtin library
450450

451-
COMPILER_RT_LIB = $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name)
452-
ifeq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y)
453-
ifeq ($(wildcard $(COMPILER_RT_LIB)),)
454-
# if "--print-libgcc-file-name" unable to find the correct libgcc PATH
455-
# then go ahead and try "--print-file-name"
456-
COMPILER_RT_LIB := $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name $(notdir $(COMPILER_RT_LIB))))
451+
ifeq ($(CONFIG_BUILTIN_TOOLCHAIN),y)
452+
COMPILER_RT_LIB = $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name)
453+
ifeq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y)
454+
ifeq ($(wildcard $(COMPILER_RT_LIB)),)
455+
# if "--print-libgcc-file-name" unable to find the correct libgcc PATH
456+
# then go ahead and try "--print-file-name"
457+
COMPILER_RT_LIB := $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name $(notdir $(COMPILER_RT_LIB))))
458+
endif
457459
endif
458-
else ifeq ($(CONFIG_ARCH_TOOLCHAIN_GHS),y)
460+
endif
461+
462+
ifeq ($(CONFIG_ARCH_TOOLCHAIN_GHS),y)
459463
GHS_ROOT_PATH = $(shell which $(CC) | awk -F '/[^/]*$$' '{print $$1}')
460464
COMPILER_RT_LIB := -l$(GHS_ROOT_PATH)/lib/thumb2/libarch
461465
ifeq ($(CONFIG_ARCH_FPU),y)

libs/libbuiltin/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
compiler-rt-*.src.tar.xz
2+
*.o
3+
.depend

libs/libbuiltin/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# ##############################################################################
2+
# libs/libbuiltin/CMakeLists.txt
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
5+
# license agreements. See the NOTICE file distributed with this work for
6+
# additional information regarding copyright ownership. The ASF licenses this
7+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
8+
# use this file except in compliance with the License. You may obtain a copy of
9+
# the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations under
17+
# the License.
18+
#
19+
# ##############################################################################
20+
21+
# Include the uClibc++ Make.defs file if selected. If it is included, the
22+
# uClibc++/Make.defs file will add its files to the source file list, add its
23+
# DEPPATH info, and will add the appropriate paths to the VPATH variable
24+
#
25+
# Note that an error will occur if you select CONFIG_LIBXX_UCLIBCXX without
26+
# installing the uClibc++ package. This is intentional to let you know about
27+
# the configuration problem. Refer to the README.txt file in the NuttX uClibc++
28+
# GIT repository for more information
29+
30+
nuttx_add_subdirectory()

libs/libbuiltin/Kconfig

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
comment "Toolchain Library Support"
7+
8+
choice
9+
prompt "Builtin toolchain support"
10+
default BUILTIN_TOOLCHAIN
11+
---help---
12+
Choose to compile libraries related to toolchain into the OS
13+
14+
config BUILTIN_COMPILER_RT
15+
bool "Builtin LLVM Compiler-rt"
16+
---help---
17+
Compile the LLVM Compiler-rt library into the OS.
18+
19+
config BUILTIN_TOOLCHAIN
20+
bool "Link the toolchain library"
21+
---help---
22+
Use the toolchain library that comes with the compiler
23+
24+
endchoice
25+
26+
if BUILTIN_COMPILER_RT
27+
28+
config COMPILER_RT_VERSION
29+
string "Select LLVM Compiler-rt version"
30+
default "17.0.1"
31+
32+
config COMPILER_RT_HAS_BFLOAT16
33+
bool "Enable support for bfloat16 in Compiler-rt"
34+
default n
35+
36+
endif # BUILTIN_COMPILER_RT

libs/libbuiltin/Makefile

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
############################################################################
2+
# libs/libbuiltin/Makefile
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
###########################################################################
20+
21+
include $(TOPDIR)/Make.defs
22+
23+
ifeq ($(CONFIG_BUILTIN_COMPILER_RT),y)
24+
include compiler-rt/Make.defs
25+
endif
26+
27+
BIN ?= libbuiltin$(LIBEXT)
28+
BINDIR ?= bin
29+
30+
KBIN = libkbuiltin$(LIBEXT)
31+
KBINDIR = kbin
32+
33+
AOBJS = $(addprefix $(BINDIR)$(DELIM), $(ASRCS:.S=$(OBJEXT)))
34+
COBJS = $(addprefix $(BINDIR)$(DELIM), $(CSRCS:.c=$(OBJEXT)))
35+
CXXOBJS = $(addprefix $(BINDIR)$(DELIM), $(CXXSRCS:.cxx=$(OBJEXT)))
36+
CPPOBJS = $(addprefix $(BINDIR)$(DELIM), $(CPPSRCS:.cpp=$(OBJEXT)))
37+
38+
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(CPPSRCS)
39+
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS) $(CPPOBJS)
40+
41+
all: $(OBJS)
42+
$(call ARCHIVE, $(BIN), $(OBJS))
43+
44+
.PHONY: depend clean distclean context $(LIBBUILTIN)
45+
46+
$(AOBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.S
47+
$(call ASSEMBLE, $<, $@)
48+
49+
$(COBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.c
50+
$(call COMPILE, $<, $@)
51+
52+
$(CXXOBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.cxx
53+
$(call COMPILEXX, $<, $@)
54+
55+
$(CPPOBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.cpp
56+
$(call COMPILEXX, $<, $@)
57+
58+
context::
59+
60+
.depend: $(LIBBUILTIN)
61+
$(Q) touch $@
62+
63+
depend: .depend
64+
65+
$(BIN): depend
66+
$(Q) $(MAKE) all EXTRAFLAGS="$(EXTRAFLAGS)"
67+
68+
# C library for the kernel phase of the two-pass kernel build
69+
70+
ifneq ($(BIN),$(KBIN))
71+
$(KBIN): $(OBJS)
72+
$(Q) $(MAKE) $(KBIN) BIN=$(KBIN) BINDIR=$(KBINDIR) EXTRAFLAGS="$(EXTRAFLAGS)"
73+
endif
74+
75+
clean:
76+
$(call DELFILE, $(BIN))
77+
$(Q) $(MAKE) -C bin clean
78+
$(Q) $(MAKE) -C kbin clean
79+
80+
distclean: clean
81+
$(Q) $(MAKE) -C bin distclean
82+
$(Q) $(MAKE) -C kbin distclean
83+
$(call DELFILE, .depend)

libs/libbuiltin/bin/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
############################################################################
2+
# libs/libbuiltin/bin/Makefile
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
###########################################################################
20+
21+
include $(TOPDIR)/Make.defs
22+
23+
all:
24+
.PHONY: clean distclean
25+
26+
# Clean Targets:
27+
28+
clean:
29+
$(call DELFILE, *.o)
30+
31+
# Deep clean -- removes all traces of the configuration
32+
33+
distclean: clean
34+
$(call DELFILE, *.dep)
35+
$(call DELFILE, .depend)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/compiler-rt

0 commit comments

Comments
 (0)