[coreboot-gerrit] Patch set updated for coreboot: 99bdae9 build system: collect compiler configuration in xcompile
Patrick Georgi (pgeorgi@google.com)
gerrit at coreboot.org
Tue Mar 24 08:57:29 CET 2015
Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/7612
-gerrit
commit 99bdae911223ac38d4d7497696c27de43e753a3c
Author: Patrick Georgi <pgeorgi at 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 and out of the main build paths.
Change-Id: I0f12f755420f315127e6d9adc00b1246c6e7131b
Signed-off-by: Patrick Georgi <pgeorgi at google.com>
Signed-off-by: Edward O'Callaghan <eocallaghan at alterapraxis.com>
---
Makefile | 25 +---------------
src/arch/x86/Makefile.inc | 4 ++-
toolchain.inc | 15 +++-------
util/xcompile/xcompile | 72 +++++++++++++++++++++++++++++++++++------------
4 files changed, 62 insertions(+), 54 deletions(-)
diff --git a/Makefile b/Makefile
index 8b5d61b..1372be0 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,33 +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
-# Tone down some clang warnings
-CFLAGS_x86_32 += -Wno-unused-variable -Wno-unused-function -Wno-tautological-compare -Wno-shift-overflow
-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 5d49abc..bab8dae 100644
--- a/src/arch/x86/Makefile.inc
+++ b/src/arch/x86/Makefile.inc
@@ -27,7 +27,9 @@ subdirs-y += boot
subdirs-y += lib
subdirs-y += smp
-DISASSEMBLY=-Wa,--divide
+ifeq ($(CONFIG_COMPILER_GCC),y)
+DISASSEMBLY=-Wa,-acdlns
+endif
OPTION_TABLE_H:=
ifeq ($(CONFIG_HAVE_OPTION_TABLE),y)
diff --git a/toolchain.inc b/toolchain.inc
index d69fe26..e9d2b3b 100644
--- a/toolchain.inc
+++ b/toolchain.inc
@@ -60,9 +60,9 @@ ARCHDIR-arm64 := arm64
ARCHDIR-riscv := riscv
ARCHDIR-mipsel := mips
-CFLAGS_arm := -mno-unaligned-access -ffunction-sections -fdata-sections
+CFLAGS_arm += -mno-unaligned-access -ffunction-sections -fdata-sections
-CFLAGS_arm64 := -ffunction-sections -fdata-sections
+CFLAGS_arm64 += -ffunction-sections -fdata-sections
CFLAGS_mipsel := -mips32r2 -G 0 -ffunction-sections -fdata-sections
CFLAGS_mipsel += -mno-abicalls -fno-pic
@@ -101,15 +101,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 fc221b1..73eb9db 100755
--- a/util/xcompile/xcompile
+++ b/util/xcompile/xcompile
@@ -59,6 +59,7 @@ elif program_exists cc; then
else
die "no host compiler found"
fi
+CLANG=clang
cat <<EOF
# platform agnostic and host tools
@@ -98,11 +99,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 +112,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_GCC -Wl,-b,elf32-i386 -Wl,-melf_i386"
;;
esac
@@ -122,27 +123,31 @@ 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 -no-integrated-as" &&
+ CFLAGS_CLANG="$CFLAGS_CLANG -no-integrated-as"
+ 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"
;;
mipsel)
testcc "$CC" "$CFLAGS -mno-abicalls -fno-pic" && \
@@ -151,13 +156,27 @@ detect_special_flags() {
esac
}
+detect_compiler_runtime() {
+ CC_RT_CLANG="`${CLANG} ${CFLAGS_CLANG} -print-librt-file-name 2>/dev/null`"
+ CC_RT_GCC="`${GCCPREFIX}gcc ${CFLAGS_GCC} -print-libgcc-file-name 2>/dev/null`"
+}
+
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,10 +196,12 @@ SUPPORTED_ARCHITECTURE="x86 arm arm64 riscv mipsel"
arch_config_arm() {
TARCH="arm"
TBFDARCHS="littlearm"
+ # N.B. clang expects armv7-a to come first else clang can not find prefixed binutils.
TCLIST="armv7a armv7-a"
TWIDTH="32"
TSUPP="arm armv4 armv7"
TABI="eabi"
+ CC_RT_EXTRA_GCC=
}
arch_config_arm64() {
@@ -190,6 +211,7 @@ arch_config_arm64() {
TWIDTH="64"
TSUPP="arm64 armv8_64"
TABI="elf"
+ CC_RT_EXTRA_GCC=
}
arch_config_riscv() {
@@ -198,6 +220,7 @@ arch_config_riscv() {
TCLIST="riscv"
TWIDTH="64"
TABI="elf"
+ CC_RT_EXTRA_GCC=
}
arch_config_x86() {
@@ -206,6 +229,7 @@ arch_config_x86() {
TCLIST="i386 x86_64"
TWIDTH="32"
TABI="elf"
+ CC_RT_EXTRA_GCC="--wrap __divdi3 --wrap __udivdi3 --wrap __moddi3 --wrap __umoddi3"
}
arch_config_mipsel() {
@@ -220,7 +244,7 @@ test_architecture() {
architecture=$1
GCCPREFIX="invalid"
- unset TARCH TBFDARCH TCLIST TWIDTH TSUPP TABI
+ unset TARCH TBFDARCH TCLIST TWIDTH TSUPP TABI CC_RT_EXTRA_GCC
if type arch_config_$architecture > /dev/null; then
arch_config_$architecture
else
@@ -251,13 +275,25 @@ test_architecture() {
[ "$GCCPREFIX" = "invalid" ] || 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
+ CFLAGS_GCC=
+ CFLAGS_CLANG="-target ${clang_arch}-linux-${TABI} -Qunused-arguments -ccc-gcc-name ${CC} -m${TWIDTH}"
+ # tone down some warnings
+ CFLAGS_CLANG="${CFLAGS_CLANG} -Wno-unused-variable -Wno-unused-function -Wno-tautological-compare -Wno-shift-overflow"
detect_special_flags "$architecture"
+ detect_compiler_runtime "$architecture"
report_arch_toolchain
}
More information about the coreboot-gerrit
mailing list