Merge changes from topic "jc/clang_support"
* changes:
docs: add note on building TFA-Tests using clang
build(clang): introduce clang toolchain support
diff --git a/Makefile b/Makefile
index 97afc34..4896ba9 100644
--- a/Makefile
+++ b/Makefile
@@ -55,6 +55,19 @@
endif
export Q
+################################################################################
+# Toolchain configs
+################################################################################
+CC := ${CROSS_COMPILE}gcc
+CPP := ${CROSS_COMPILE}cpp
+AS := ${CROSS_COMPILE}gcc
+AR := ${CROSS_COMPILE}ar
+LD := ${CROSS_COMPILE}ld
+OC := ${CROSS_COMPILE}objcopy
+OD := ${CROSS_COMPILE}objdump
+NM := ${CROSS_COMPILE}nm
+PP := ${CROSS_COMPILE}gcc
+
ifneq (${DEBUG}, 0)
BUILD_TYPE := debug
# Use LOG_LEVEL_INFO by default for debug builds
@@ -182,7 +195,9 @@
################################################################################
+################################################################################
# Assembler, compiler and linker flags shared across all test images.
+################################################################################
COMMON_ASFLAGS :=
COMMON_CFLAGS :=
COMMON_LDFLAGS :=
@@ -215,44 +230,69 @@
$(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
endif # arch-features
-COMMON_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
-COMMON_CFLAGS_aarch64 := -mgeneral-regs-only -mstrict-align ${march64-directive}
+################################################################################
+# Compiler settings
+################################################################################
+ifneq ($(findstring clang,$(notdir $(CC))),)
+CLANG_CFLAGS_aarch64 := -target aarch64-elf
-COMMON_ASFLAGS_aarch32 := ${march32-directive}
-COMMON_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
+CPP := $(CC) -E $(COMMON_CFLAGS_$(ARCH))
+PP := $(CC) -E $(COMMON_CFLAGS_$(ARCH))
-COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
- -Werror -Wmissing-include-dirs \
- -D__ASSEMBLY__ $(COMMON_ASFLAGS_$(ARCH)) \
- ${INCLUDES}
-COMMON_CFLAGS += -nostdinc -ffreestanding -Wall -Werror \
- -Wmissing-include-dirs $(COMMON_CFLAGS_$(ARCH)) \
+CLANG_WARNINGS += -nostdinc -ffreestanding -Wall \
+ -Wmissing-include-dirs $(CLANG_CFLAGS_$(ARCH)) \
+ -Wlogical-op-parentheses \
+ -Wno-initializer-overrides \
+ -Wno-sometimes-uninitialized \
+ -Wno-unused-function \
+ -Wno-unused-variable \
+ -Wno-unused-parameter \
+ -Wno-tautological-compare \
+ -Wno-memset-transposed-args \
+ -Wno-parentheses
+
+CLANG_CFLAGS += -Wno-error=deprecated-declarations \
+ -Wno-error=cpp \
+ $(CLANG_WARNINGS)
+endif #(clang)
+
+ifneq ($(findstring gcc,$(notdir $(CC))),)
+GCC_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
+GCC_CFLAGS_aarch64 := -mgeneral-regs-only
+
+GCC_ASFLAGS_aarch32 := ${march32-directive}
+GCC_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
+
+GCC_WARNINGS += -nostdinc -ffreestanding -Wall -Werror \
+ -Wmissing-include-dirs $(GCC_CFLAGS_$(ARCH)) \
-std=gnu99 -Os
+
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
+GCC_CFLAGS += $(call cc_option, --param=min-pagesize=0)
+GCC_CFLAGS += $(GCC_WARNINGS)
+endif #(gcc)
+
+COMMON_CFLAGS_aarch64 += ${march64-directive} -mstrict-align \
+ $(CLANG_CFLAGS_$(ARCH)) $(GCC_CFLAGS_$(ARCH))
+
+COMMON_CFLAGS += $(COMMON_CFLAGS_$(ARCH))
COMMON_CFLAGS += -ffunction-sections -fdata-sections
# Get the content of CFLAGS user defined value last so they are appended after
# the options defined in the Makefile
-COMMON_CFLAGS += ${CFLAGS} ${INCLUDES}
+COMMON_CFLAGS += ${CLANG_CFLAGS} ${GCC_CFLAGS} ${INCLUDES}
+
+COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
+ -Werror -Wmissing-include-dirs \
+ -D__ASSEMBLY__ $(GCC_ASFLAGS_$(ARCH)) \
+ ${INCLUDES}
COMMON_LDFLAGS += ${LDFLAGS} --fatal-warnings -O1 --gc-sections --build-id=none
-CC := ${CROSS_COMPILE}gcc
-CPP := ${CROSS_COMPILE}cpp
-AS := ${CROSS_COMPILE}gcc
-AR := ${CROSS_COMPILE}ar
-LD := ${CROSS_COMPILE}ld
-OC := ${CROSS_COMPILE}objcopy
-OD := ${CROSS_COMPILE}objdump
-NM := ${CROSS_COMPILE}nm
-PP := ${CROSS_COMPILE}gcc
-
# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
# are not loaded by a elf loader.
COMMON_LDFLAGS += $(call ld_option, --no-warn-rwx-segments)
-# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
-COMMON_CFLAGS += $(call cc_option, --param=min-pagesize=0)
-
################################################################################
TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS} ${LIBFDT_SRCS}
@@ -590,6 +630,9 @@
# The EL3 test payload is only supported in AArch64. It has an independent build
# system.
.PHONY: el3_payload
+# TODO: EL3 test payload currently is supported for GCC only. It has an independent
+# build system and support for Clang to be added.
+ifneq ($(findstring gcc,$(notdir $(CC))),)
ifneq (${ARCH},aarch32)
ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
el3_payload: $(BUILD_DIR)
@@ -599,6 +642,7 @@
all: el3_payload
endif
endif
+endif
doc:
@echo " BUILD DOCUMENTATION"
diff --git a/docs/getting_started/build.rst b/docs/getting_started/build.rst
index 70b7edc..111306d 100644
--- a/docs/getting_started/build.rst
+++ b/docs/getting_started/build.rst
@@ -16,6 +16,25 @@
export CROSS_COMPILE=<path-to-aarch32-gcc>/bin/arm-eabi-
+- It is possible to build TF-A Tests using clang (currently AArch64 only). To
+ do so ``CC`` needs to point to the clang binary. Only the compiler is switched;
+ the assembler and linker need to be provided by the GNU toolchain, thus
+ ``CROSS_COMPILE`` should be set as described above.
+
+ clang will be selected when the base name of the path assigned to ``CC``
+ contains the string 'clang'.
+
+- For AArch64 using clang:
+
+ .. code:: shell
+
+ export CROSS_COMPILE=<path-to-aarch64-gcc>/bin/aarch64-none-elf-
+ make CC=<path-to-clang>/bin/clang PLAT=<platform> tftf
+
+- Currently, the following TF-A Tests targets are supported for clang build:
+
+ ``tftf, ivy, realm, cactus, cactus_mm, ns_bl1u``
+
- Change to the root directory of the TF-A Tests source tree and build.
For AArch64:
diff --git a/spm/common/sp_tests/sp_test_ffa.c b/spm/common/sp_tests/sp_test_ffa.c
index 614770e..73db187 100644
--- a/spm/common/sp_tests/sp_test_ffa.c
+++ b/spm/common/sp_tests/sp_test_ffa.c
@@ -34,7 +34,7 @@
FFA_PARTITION_DIRECT_REQ_RECV |
FFA_PARTITION_DIRECT_REQ_SEND |
FFA_PARTITION_NOTIFICATION),
- .uuid = sp_uuids[0]
+ .uuid = {PRIMARY_UUID}
},
/* Secondary partition info */
{
@@ -44,7 +44,7 @@
FFA_PARTITION_DIRECT_REQ_RECV |
FFA_PARTITION_DIRECT_REQ_SEND |
FFA_PARTITION_NOTIFICATION),
- .uuid = sp_uuids[1]
+ .uuid = {SECONDARY_UUID}
},
/* Tertiary partition info */
{
@@ -54,7 +54,7 @@
FFA_PARTITION_DIRECT_REQ_RECV |
FFA_PARTITION_DIRECT_REQ_SEND |
FFA_PARTITION_NOTIFICATION),
- .uuid = sp_uuids[2]
+ .uuid = {TERTIARY_UUID}
},
/* Ivy partition info */
{
@@ -63,7 +63,7 @@
.properties = (FFA_PARTITION_AARCH64_EXEC |
FFA_PARTITION_DIRECT_REQ_RECV |
FFA_PARTITION_DIRECT_REQ_SEND),
- .uuid = sp_uuids[3]
+ .uuid = {IVY_UUID}
},
/* EL3 SPMD logical partition */
{
@@ -71,7 +71,7 @@
.exec_context = EL3_SPMD_LP_EXEC_CTX_COUNT,
.properties = (FFA_PARTITION_AARCH64_EXEC |
FFA_PARTITION_DIRECT_REQ_SEND),
- .uuid = sp_uuids[4]
+ .uuid = {EL3_SPMD_LP_UUID}
},
};
diff --git a/tftf/tests/runtime_services/secure_service/test_ffa_setup_and_discovery.c b/tftf/tests/runtime_services/secure_service/test_ffa_setup_and_discovery.c
index 4b0df1c..80a3015 100644
--- a/tftf/tests/runtime_services/secure_service/test_ffa_setup_and_discovery.c
+++ b/tftf/tests/runtime_services/secure_service/test_ffa_setup_and_discovery.c
@@ -31,7 +31,7 @@
.properties = FFA_PARTITION_AARCH64_EXEC |
FFA_PARTITION_DIRECT_REQ_RECV |
FFA_PARTITION_NOTIFICATION,
- .uuid = sp_uuids[0]
+ .uuid = {PRIMARY_UUID}
},
/* Secondary partition info */
{
@@ -40,7 +40,7 @@
.properties = FFA_PARTITION_AARCH64_EXEC |
FFA_PARTITION_DIRECT_REQ_RECV |
FFA_PARTITION_NOTIFICATION,
- .uuid = sp_uuids[1]
+ .uuid = {SECONDARY_UUID}
},
/* Tertiary partition info */
{
@@ -49,7 +49,7 @@
.properties = FFA_PARTITION_AARCH64_EXEC |
FFA_PARTITION_DIRECT_REQ_RECV |
FFA_PARTITION_NOTIFICATION,
- .uuid = sp_uuids[2]
+ .uuid = {TERTIARY_UUID}
},
/* Ivy partition info */
{
@@ -57,7 +57,7 @@
.exec_context = IVY_EXEC_CTX_COUNT,
.properties = FFA_PARTITION_AARCH64_EXEC |
FFA_PARTITION_DIRECT_REQ_RECV,
- .uuid = sp_uuids[3]
+ .uuid = {IVY_UUID}
}
};