diff options
author | Nicolas Boichat <drinkcat@chromium.org> | 2018-06-20 10:40:26 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-06-28 07:06:46 -0700 |
commit | dcfbe0be69d3445edfd45fb036bfae2581b6fdd5 (patch) | |
tree | de448bc3d41945e0bc0cf2f098e10ca14fc49419 | |
parent | 6f38ed23f3d467937f15cf0474b8f323564bcc0d (diff) | |
download | chrome-ec-dcfbe0be69d3445edfd45fb036bfae2581b6fdd5.tar.gz |
ec: Make it possible to build tests using clang
We might want to try out address sanitizer/fuzzer on some host
tests: make it possible to build host tests using clang.
Board builds are broken, and there is no intention to fix them,
at least for now.
BRANCH=none
BUG=chromium:854924
TEST=make buildall -j
TEST=make CC=clang runtests -j
Change-Id: Id49a1b8537bc403d53437a2245f4fab6ceae89ac
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1107522
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | Makefile.rules | 2 | ||||
-rw-r--r-- | Makefile.toolchain | 17 | ||||
-rw-r--r-- | common/charge_manager.c | 2 | ||||
-rw-r--r-- | common/lightbar.c | 23 | ||||
-rw-r--r-- | common/mkbp_event.c | 2 | ||||
-rw-r--r-- | common/usb_pd_policy.c | 4 | ||||
-rw-r--r-- | common/usb_pd_protocol.c | 2 | ||||
-rw-r--r-- | include/common.h | 13 | ||||
-rw-r--r-- | include/compile_time_macros.h | 2 |
9 files changed, 41 insertions, 26 deletions
diff --git a/Makefile.rules b/Makefile.rules index 9138b35ed9..9ca18284ea 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -56,7 +56,7 @@ cmd_lds = $(CPP) -P -C -MMD -MF $@.d -MT $@ $(CPPFLAGS) $< -o $@ cmd_lds_b = $(cmd_lds) -DRW_B_LDS # Allow obj_to_bin to be overridden by board or chip specific commands cmd_obj_to_bin ?= $(OBJCOPY) --gap-fill=0xff -O binary $^ $(out)/$*.bin.tmp -cmd_flat_to_obj = $(CC) -T $(out)/firmware_image.lds -nostdlib $(CPPFLAGS) \ +cmd_flat_to_obj = $(CC) -Wl,-T $(out)/firmware_image.lds -nostdlib $(CPPFLAGS) \ -Wl,--build-id=none -o $@ $< # Allow the .roshared section to overlap other sections (itself) cmd_ec_elf_to_flat ?= $(OBJCOPY) --set-section-flags .roshared=share \ diff --git a/Makefile.toolchain b/Makefile.toolchain index 093721eede..e0f796fae6 100644 --- a/Makefile.toolchain +++ b/Makefile.toolchain @@ -15,13 +15,16 @@ ifeq ($(make_version_ok),) $(error ERROR: GNU make version $(min_make_version) or higher required.) endif +# Extract cc-name +cc-name:=$(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc) + # Try not to assume too much about optional tools and prefixes CCACHE:=$(shell which ccache 2>/dev/null) ifeq ($(origin HOST_CROSS_COMPILE),undefined) HOST_CROSS_COMPILE:=$(if $(shell which x86_64-pc-linux-gnu-gcc 2>/dev/null),x86_64-pc-linux-gnu-,) endif -CC=$(CCACHE) $(CROSS_COMPILE)gcc +CC=$(CCACHE) $(CROSS_COMPILE)$(cc-name) CPP=$(CC) -E LD=$(CROSS_COMPILE)ld NM=$(CROSS_COMPILE)nm @@ -37,6 +40,10 @@ C_WARN = -Wstrict-prototypes -Wdeclaration-after-statement -Wno-pointer-sign COMMON_WARN = -Wall -Werror -Wundef -Wno-trigraphs -fno-strict-aliasing \ -fno-common -Werror-implicit-function-declaration \ -Wno-format-security -fno-strict-overflow +ifeq ($(cc-name),clang) +# clang is pickier when it comes to packed struct members alignment. +C_WARN+= -Wno-address-of-packed-member +endif CFLAGS_WARN = $(COMMON_WARN) $(C_WARN) CXXFLAGS_WARN = $(COMMON_WARN) CFLAGS_DEBUG= -g @@ -71,7 +78,11 @@ CPPFLAGS+=-Ibuiltin/ endif CFLAGS=$(CPPFLAGS) $(CFLAGS_CPU) $(CFLAGS_DEBUG) $(CFLAGS_WARN) $(CFLAGS_y) CFLAGS+= -ffunction-sections -fshort-wchar -CFLAGS+= -fno-delete-null-pointer-checks -fconserve-stack +ifneq ($(cc-name),clang) +# TODO(chromium:854924): LLVM support for this flag is coming soon. +CFLAGS+= -fno-delete-null-pointer-checks +CFLAGS+= -fconserve-stack +endif CFLAGS+= -DCHROMIUM_EC FTDIVERSION=$(shell $(PKG_CONFIG) --modversion libftdi1 2>/dev/null) @@ -89,7 +100,7 @@ HOST_CFLAGS=$(HOST_CPPFLAGS) -O3 $(CFLAGS_DEBUG) $(CFLAGS_WARN) -DHOST_TOOLS_BUI LDFLAGS=-nostdlib -g -Wl,-X -Wl,--gc-sections -Wl,--build-id=none \ $(LDFLAGS_EXTRA) $(CFLAGS_CPU) BUILD_LDFLAGS=$(LIBFTDI_LDLIBS) -HOST_TEST_LDFLAGS=-T core/host/host_exe.lds -lrt -pthread -rdynamic -lm\ +HOST_TEST_LDFLAGS=-Wl,-T core/host/host_exe.lds -lrt -pthread -rdynamic -lm\ $(if $(TEST_COVERAGE),-fprofile-arcs,) # utility function to provide overridable defaults diff --git a/common/charge_manager.c b/common/charge_manager.c index 81382b21da..2abb770667 100644 --- a/common/charge_manager.c +++ b/common/charge_manager.c @@ -81,9 +81,11 @@ static int override_port = OVERRIDE_OFF; static int delayed_override_port = OVERRIDE_OFF; static timestamp_t delayed_override_deadline; +#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT /* Bitmap of ports used as power source */ static volatile uint32_t source_port_bitmap; BUILD_ASSERT(sizeof(source_port_bitmap)*8 >= CONFIG_USB_PD_PORT_COUNT); +#endif static uint8_t source_port_last_rp[CONFIG_USB_PD_PORT_COUNT]; /* diff --git a/common/lightbar.c b/common/lightbar.c index 9a01e64ccd..c7fed67e7e 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -412,21 +412,6 @@ static inline int cycle_010(uint8_t i) ((_ramp_table[bucket + 1] - _ramp_table[bucket]) * index >> 2); } -/* This function provides a smooth oscillation between -0.5 and +0.5. - * Zero starts at 0x00. */ -static inline int cycle_0p0n0(uint8_t i) -{ - return cycle_010(i + 64) - FP_SCALE / 2; -} - -/* This function provides a pulsing oscillation between -0.5 and +0.5. */ -static inline int cycle_npn(uint16_t i) -{ - if ((i / 256) % 4) - return -FP_SCALE / 2; - return cycle_010(i) - FP_SCALE / 2; -} - /******************************************************************************/ /* Here's where we keep messages waiting to be delivered to the lightbar task. * If more than one is sent before the task responds, we only want to deliver @@ -524,6 +509,14 @@ static uint32_t sequence_S3S0(void) #ifdef BLUE_PULSING +/* This function provides a pulsing oscillation between -0.5 and +0.5. */ +static inline int cycle_npn(uint16_t i) +{ + if ((i / 256) % 4) + return -FP_SCALE / 2; + return cycle_010(i) - FP_SCALE / 2; +} + /* CPU is fully on */ static uint32_t sequence_S0(void) { diff --git a/common/mkbp_event.c b/common/mkbp_event.c index 160ae250c8..40a6e21066 100644 --- a/common/mkbp_event.c +++ b/common/mkbp_event.c @@ -57,6 +57,7 @@ static void set_host_interrupt(int active) interrupt_enable(); } +#ifdef CONFIG_MKBP_WAKEUP_MASK /** * Check if the host is sleeping. Check our power state in addition to the * self-reported sleep state of host (CONFIG_POWER_TRACK_HOST_SLEEP_STATE). @@ -73,6 +74,7 @@ static inline int host_is_sleeping(void) #endif return is_sleeping; } +#endif /* CONFIG_MKBP_WAKEUP_MASK */ int mkbp_send_event(uint8_t event_type) { diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c index 9f4b41b74d..9d2b374259 100644 --- a/common/usb_pd_policy.c +++ b/common/usb_pd_policy.c @@ -70,7 +70,7 @@ int pd_check_requested_voltage(uint32_t rdo, const int port) return EC_SUCCESS; } -static int stub_pd_board_check_request(uint32_t rdo, int pdo_cnt) +__attribute__((weak)) int pd_board_check_request(uint32_t rdo, int pdo_cnt) { int idx = RDO_POS(rdo); @@ -78,8 +78,6 @@ static int stub_pd_board_check_request(uint32_t rdo, int pdo_cnt) return (!idx || idx > pdo_cnt) ? EC_ERROR_INVAL : EC_SUCCESS; } -int pd_board_check_request(uint32_t, int) - __attribute__((weak, alias("stub_pd_board_check_request"))); #ifdef CONFIG_USB_PD_DUAL_ROLE /* Last received source cap */ diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 07268fc310..0cae3bde9e 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -4003,7 +4003,7 @@ static int command_pd(int argc, char **argv) for (i = 0; i < PD_RW_HASH_SIZE / 4; i++) ccprintf("%08x ", pd[port].dev_rw_hash[i]); ccprintf("\nImage %s\n", system_image_copy_t_to_string( - pd[port].current_image)); + (enum system_image_copy_t)pd[port].current_image)); } else if (!strncasecmp(argv[2], "soft", 4)) { set_state(port, PD_STATE_SOFT_RESET); task_wake(PD_PORT_TO_TASK_ID(port)); diff --git a/include/common.h b/include/common.h index d465180c56..555f91a953 100644 --- a/include/common.h +++ b/include/common.h @@ -66,13 +66,24 @@ #endif /* + * externally_visible is required by GCC to avoid kicking out memset. + */ +#ifndef __visible +#ifndef __clang__ +#define __visible __attribute__((externally_visible)) +#else +#define __visible __attribute__((used)) +#endif +#endif + +/* * Force the toolchain to keep a symbol even with Link Time Optimization * activated. * * Useful for C functions called only from assembly or through special sections. */ #ifndef __keep -#define __keep __attribute__((used)) __attribute__((externally_visible)) +#define __keep __attribute__((used)) __visible #endif /* diff --git a/include/compile_time_macros.h b/include/compile_time_macros.h index b1e627d617..1cc41f4d0e 100644 --- a/include/compile_time_macros.h +++ b/include/compile_time_macros.h @@ -29,6 +29,4 @@ #define member_size(type, member) sizeof(((type *)0)->member) -#define __visible __attribute__((externally_visible)) - #endif /* __CROS_EC_COMPILE_TIME_MACROS_H */ |