Patrick Georgi (pgeorgi@google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/7612
-gerrit
commit 6d161b3b9134266e0f6e5a49cd77e12f45b24e3e Author: Patrick Georgi pgeorgi@google.com Date: Sat Nov 29 14:16:07 2014 +0100
build system: collect compiler configuration in xcompile
Move clang specifics and compiler runtime handling to xcompile.
Change-Id: I0f12f755420f315127e6d9adc00b1246c6e7131b Signed-off-by: Patrick Georgi pgeorgi@google.com --- Makefile | 23 +---------------- src/arch/x86/Makefile.inc | 2 -- toolchain.inc | 11 ++------- util/xcompile/xcompile | 63 ++++++++++++++++++++++++++++++++++------------- 4 files changed, 49 insertions(+), 50 deletions(-)
diff --git a/Makefile b/Makefile index eaba3e4..19d65f4 100644 --- a/Makefile +++ b/Makefile @@ -37,8 +37,6 @@ $(if $(wildcard .xcompile),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile: util/xcompile/xcompile A=`mktemp $@.XXXXXX`; $< $(XGCCPATH) > $$A && mv $$A $@ 2> /dev/null
-include .xcompile - export top := $(CURDIR) export src := src export srck := $(top)/util/kconfig @@ -112,31 +110,12 @@ real-all: config else
include $(HAVE_DOTCONFIG) - -ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y) -# FIXME: armv7/aarch64 won't build right now -# NOTE: clang puts compiler-rt under lib/linux/libclang_rt.builtins-i386.a -# this means the triple is i386-linux-elf instead of i386-none-elf -CFLAGS_x86_32 = -no-integrated-as -Qunused-arguments -target i386-linux-elf -m32 -CC_x86_32:=clang -HOSTCC := clang +include .xcompile
ifneq ($(CONFIG_MMX),y) CFLAGS_x86_32 += -mno-mmx endif
-# FIXME: we end up with conflicting flags with this, not clear on this part. -#ifneq ($(CONFIG_SSE),y) -#CFLAGS_x86_32 += -mno-sse -#endif - -CFLAGS_arm = -no-integrated-as -Qunused-arguments -target arm-eabi -ccc-gcc-name $(CC_arm) -CC_arm:=clang - -CFLAGS_aarch64 = -no-integrated-as -Qunused-arguments -target aarch64-eabi -ccc-gcc-name $(CC_aarch64) -CC_aarch64:=clang -endif - include toolchain.inc
strip_quotes = $(subst ",,$(subst ",,$(1))) diff --git a/src/arch/x86/Makefile.inc b/src/arch/x86/Makefile.inc index 9e67459..4d23e67 100644 --- a/src/arch/x86/Makefile.inc +++ b/src/arch/x86/Makefile.inc @@ -29,8 +29,6 @@ subdirs-y += smp
ifeq ($(CONFIG_COMPILER_GCC),y) DISASSEMBLY=-Wa,-acdlns -else -DISASSEMBLY=-Wa,--divide endif
OPTION_TABLE_H:= diff --git a/toolchain.inc b/toolchain.inc index e6f530a..ffc197d 100644 --- a/toolchain.inc +++ b/toolchain.inc @@ -93,15 +93,8 @@ STRIP_$(1) := $(STRIP_$(2)) READELF_$(1) := $(READELF_$(2)) CFLAGS_$(1) = $$(CFLAGS_common) $$(CFLAGS_$(2)) CPPFLAGS_$(1) = $$(CPPFLAGS_common) $$(CPPFLAGS_$(2)) -COMPILER_RT_FLAGS_$(1) := -ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y) -COMPILER_RT_$(1) = $(shell $(CC_$(2)) $(CFLAGS_$(2)) -print-librt-file-name 2>/dev/null) -else -COMPILER_RT_$(1) = $(wildcard $(shell $(CC_$(2)) $(CFLAGS_$(2)) -print-libgcc-file-name)) -ifeq ($(2),x86_32) -COMPILER_RT_FLAGS_$(1) := --wrap __divdi3 --wrap __udivdi3 --wrap __moddi3 --wrap __umoddi3 -endif -endif +COMPILER_RT_$(1) := $$(COMPILER_RT_$(2)) +COMPILER_RT_FLAGS_$(1) := $$(COMPILER_RT_FLAGS_$(2)) endef
# define_class: Allows defining any program as dynamic class and compiler tool diff --git a/util/xcompile/xcompile b/util/xcompile/xcompile index 45dae8c..1a72763 100755 --- a/util/xcompile/xcompile +++ b/util/xcompile/xcompile @@ -98,11 +98,11 @@ testas() {
if [ -z "$use_dash_twidth" ]; then ASFLAGS="" - CFLAGS="" + CFLAGS_GCC="" LDFLAGS="" else ASFLAGS="--$twidth" - CFLAGS="-m$twidth" + CFLAGS_GCC="-m$twidth" LDFLAGS="-b $full_arch"
fi @@ -111,7 +111,7 @@ testas() { [ -n "$use_dash_twidth" ] && case "$full_arch" in "elf32-i386" ) LDFLAGS="$LDFLAGS -melf_i386" - CFLAGS="$CFLAGS -Wl,-b,elf32-i386 -Wl,-melf_i386" + CFLAGS_GCC="$CFLAGS -Wl,-b,elf32-i386 -Wl,-melf_i386" ;; esac
@@ -122,38 +122,54 @@ detect_special_flags() { local architecture="$1" # GCC 4.6 is much more picky about unused variables. # Turn off it's warnings for now: - testcc "$CC" "$CFLAGS -Wno-unused-but-set-variable " && - CFLAGS="$CFLAGS -Wno-unused-but-set-variable " + testcc "$CC" "$CFLAGS_GCC -Wno-unused-but-set-variable " && + CFLAGS_GCC="$CFLAGS_GCC -Wno-unused-but-set-variable "
# Use bfd linker instead of gold if available: - testcc "$CC" "$CFLAGS -fuse-ld=bfd" && - CFLAGS="$CFLAGS -fuse-ld=bfd" && LINKER_SUFFIX='.bfd' + testcc "$CC" "$CFLAGS_GCC -fuse-ld=bfd" && + CFLAGS_GCC="$CFLAGS_GCC -fuse-ld=bfd" && LINKER_SUFFIX='.bfd'
- testcc "$CC" "$CFLAGS -fno-stack-protector"&& - CFLAGS="$CFLAGS -fno-stack-protector" - testcc "$CC" "$CFLAGS -Wl,--build-id=none" && - CFLAGS="$CFLAGS -Wl,--build-id=none" + testcc "$CC" "$CFLAGS_GCC -fno-stack-protector"&& + CFLAGS_GCC="$CFLAGS_GCC -fno-stack-protector" + testcc "$CC" "$CFLAGS_GCC -Wl,--build-id=none" && + CFLAGS_GCC="$CFLAGS_GCC -Wl,--build-id=none"
case "$architecture" in x86) - testcc "$CC" "$CFLAGS -Wa,--divide" && - CFLAGS="$CFLAGS -Wa,--divide" + testcc "$CC" "$CFLAGS_GCC -Wa,--divide" && + CFLAGS_GCC="$CFLAGS_GCC -Wa,--divide" + testcc "$CLANG" "$CFLAGS_CLANG -Wa,--divide" && + CFLAGS_CLANG="$CFLAGS_CLANG -Wa,--divide" # Always build for i686 -- no sse/mmx instructions since SMM # modules are compiled using these flags. Note that this # doesn't prevent a project using xcompile to explicitly # specify -mmsse, etc flags. - CFLAGS="$CFLAGS -march=i686" + CFLAGS_GCC="$CFLAGS_GCC -march=i686" ;; esac }
+detect_compiler_runtime() { + CC_RT_CLANG="`${CLANG} ${CFLAGS} -print-librt-file-name`" + CC_RT_GCC="`${GCCPREFIX}gcc ${CFLAGS} -print-libgcc-file-name`" +} + report_arch_toolchain() { cat <<EOF # elf${TWIDTH}-${TBFDARCH} toolchain (${GCCPREFIX}gcc) ARCH_SUPPORTED+=${TARCH} SUBARCH_SUPPORTED+=${TSUPP-${TARCH}} +ifeq ($(CONFIG_COMPILER_GCC),y) CC_${TARCH}:=${GCCPREFIX}gcc -CFLAGS_${TARCH}:=${CFLAGS} +CFLAGS_${TARCH}:=${CFLAGS_GCC} +COMPILER_RT_${TARCH}:=${CC_RT_GCC} +COMPILER_RT_FLAGS_${TARCH}:=${CC_RT_EXTRA_GCC} +else +CC_${TARCH}:=${CLANG} +CFLAGS_${TARCH}:=${CFLAGS_CLANG} +COMPILER_RT_${TARCH}:=${CC_RT_CLANG} +COMPILER_RT_FLAGS_${TARCH}:=${CC_RT_EXTRA_CLANG} +endif CPP_${TARCH}:=${GCCPREFIX}cpp AS_${TARCH}:=${GCCPREFIX}as ${ASFLAGS} LD_${TARCH}:=${GCCPREFIX}ld${LINKER_SUFFIX} ${LDFLAGS} @@ -177,6 +193,7 @@ arch_config_arm() { TWIDTH="32" TSUPP="arm armv4 armv7" TABI="eabi" + CC_RT_EXTRA_GCC= }
arch_config_aarch64() { @@ -185,6 +202,7 @@ arch_config_aarch64() { TCLIST="aarch64" TWIDTH="64" TABI="elf" + CC_RT_EXTRA_GCC= }
arch_config_riscv() { @@ -193,6 +211,7 @@ arch_config_riscv() { TCLIST="riscv" TWIDTH="64" TABI="elf" + CC_RT_EXTRA_GCC= }
arch_config_x86() { @@ -201,6 +220,7 @@ arch_config_x86() { TCLIST="i386 x86_64" TWIDTH="32" TABI="elf" + CC_RT_EXTRA_GCC="--wrap __divdi3 --wrap __udivdi3 --wrap __moddi3 --wrap __umoddi3" }
test_architecture() { @@ -234,13 +254,22 @@ test_architecture() { testas "$gccprefixes" "$TWIDTH" "$TBFDARCH" "TRUE" && break done
- if [ "$GCCPREFIX" = "invalid" ]; then - echo "Warning: no suitable GCC for $architecture." >&2 + for clang_arch in $TCLIST invalid; do + # NOTE: clang puts compiler-rt under lib/linux/libclang_rt.builtins-i386.a + # this means the triple is i386-linux-elf instead of i386-none-elf + # See: http://llvm.org/bugs/show_bug.cgi?id=21538 + testcc "clang" "-target ${clang_arch}-linux-$TABI -c" && break + done + + if [ "$GCCPREFIX" = "invalid" -a "$clang_arch" = "invalid" ]; then + echo "Warning: no suitable compiler for $architecture." >&2 continue fi CC="${GCCPREFIX}"gcc + CLANG="clang -target ${clang_arch}-linux-${TABI} -no-integrated-as -Qunused-arguments -ccc-gcc-name ${CC} -m${TWIDTH}"
detect_special_flags "$architecture" + detect_compiler_runtime "$architecture" report_arch_toolchain }