diff options
author | Stefan Reinauer <stefan.reinauer@coreboot.org> | 2016-01-20 18:36:20 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-02-03 15:00:50 -0800 |
commit | bc404c94b4ab1e6a62e607fd7ef034aa31d6388e (patch) | |
tree | 559e85fa8eca3ee7156f9f5333707755c43905c6 | |
parent | fc9ed52397f232bfc9f9d2b448e8bc253c87379f (diff) | |
download | chrome-ec-bc404c94b4ab1e6a62e607fd7ef034aa31d6388e.tar.gz |
Enforce compilation without system headers
This patch introduces HOST_CPPFLAGS to be used for all
objects being compiled with HOSTCC rather then the target
compiler.
Since glibc is not linked into the EC, no glibc include files
should be included in the EC code base. Hence, create local
definitions for clock_t and wchar_t that match what the glibc
include would have done, and remove some unneeded includes.
Due to very eager optimization, we have to give gcc a little
notch to not kick out memset.
Signed-off-by: Stefan Reinauer <reinauer@chromium.org>
BUG=chrome-os-partner:43025
BUG=chrome-os-partner:49517
BRANCH=none
TEST=compile tested
Change-Id: Idf3a2881fa8352756b0927b09c6a97473358f239
Reviewed-on: https://chromium-review.googlesource.com/322435
Commit-Ready: Patrick Georgi <pgeorgi@chromium.org>
Tested-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
-rw-r--r-- | Makefile.toolchain | 14 | ||||
-rw-r--r-- | board/cr50/build.mk | 7 | ||||
-rw-r--r-- | builtin/assert.h | 12 | ||||
-rw-r--r-- | builtin/stdarg.h | 24 | ||||
-rw-r--r-- | builtin/stddef.h | 30 | ||||
-rw-r--r-- | builtin/stdint.h | 38 | ||||
-rw-r--r-- | builtin/string.h | 16 | ||||
-rw-r--r-- | builtin/time.h | 13 | ||||
-rw-r--r-- | chip/g/dcrypto/internal.h | 2 | ||||
-rw-r--r-- | chip/g/loader/key_ladder.h | 2 | ||||
-rw-r--r-- | common/test_util.c | 2 | ||||
-rw-r--r-- | driver/als_si114x.c | 2 | ||||
-rw-r--r-- | driver/pi3usb30532.h | 2 | ||||
-rw-r--r-- | include/compile_time_macros.h | 2 | ||||
-rw-r--r-- | include/timer.h | 5 | ||||
-rw-r--r-- | include/trng.h | 2 | ||||
-rw-r--r-- | include/util.h | 2 |
17 files changed, 164 insertions, 11 deletions
diff --git a/Makefile.toolchain b/Makefile.toolchain index a204df9e25..c4531ded3f 100644 --- a/Makefile.toolchain +++ b/Makefile.toolchain @@ -44,6 +44,16 @@ CFLAGS_DEFINE=-DOUTDIR=$(out)/$(BLD) -DCHIP=$(CHIP) -DBOARD_TASKFILE=$(_tsk_lst_ CPPFLAGS=$(CFLAGS_DEFINE) $(CFLAGS_INCLUDE) $(CFLAGS_TEST) \ $(EXTRA_CFLAGS) $(CFLAGS_COVERAGE) $(LATE_CFLAGS_DEFINE) \ -DSECTION_IS_$(BLD) -DSECTION=$(BLD) +BUILD_CPPFLAGS=$(CFLAGS_DEFINE) $(CFLAGS_INCLUDE) $(CFLAGS_TEST) \ + $(EXTRA_CFLAGS) $(CFLAGS_COVERAGE) $(LATE_CFLAGS_DEFINE) \ + -DSECTION_IS_$(BLD) -DSECTION=$(BLD) +HOST_CPPFLAGS=$(CFLAGS_DEFINE) $(CFLAGS_INCLUDE) $(CFLAGS_TEST) \ + $(EXTRA_CFLAGS) $(CFLAGS_COVERAGE) $(LATE_CFLAGS_DEFINE) \ + -DSECTION_IS_$(BLD) -DSECTION=$(BLD) +ifneq ($(BOARD),host) +CPPFLAGS+=-ffreestanding -fno-builtin -nostdinc -nostdlib +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 @@ -58,8 +68,8 @@ endif LIBFTDI_CFLAGS=$(shell $(PKG_CONFIG) --cflags lib${LIBFTDI_NAME}) LIBFTDI_LDLIBS=$(shell $(PKG_CONFIG) --libs lib${LIBFTDI_NAME}) -BUILD_CFLAGS= $(LIBFTDI_CFLAGS) $(CPPFLAGS) -O3 $(CFLAGS_DEBUG) $(CFLAGS_WARN) -HOST_CFLAGS=$(CPPFLAGS) -O3 $(CFLAGS_DEBUG) $(CFLAGS_WARN) -DHOST_TOOLS_BUILD +BUILD_CFLAGS= $(LIBFTDI_CFLAGS) $(BUILD_CPPFLAGS) -O3 $(CFLAGS_DEBUG) $(CFLAGS_WARN) +HOST_CFLAGS=$(HOST_CPPFLAGS) -O3 $(CFLAGS_DEBUG) $(CFLAGS_WARN) -DHOST_TOOLS_BUILD LDFLAGS=-nostdlib -Wl,-X -Wl,--gc-sections -Wl,--build-id=none $(LDFLAGS_EXTRA) BUILD_LDFLAGS=$(LIBFTDI_LDLIBS) HOST_TEST_LDFLAGS=-T core/host/host_exe.lds -lrt -pthread -rdynamic -lm\ diff --git a/board/cr50/build.mk b/board/cr50/build.mk index cf5735acb0..b8f15919d6 100644 --- a/board/cr50/build.mk +++ b/board/cr50/build.mk @@ -46,6 +46,13 @@ LDFLAGS_EXTRA += -L$(out)/tpm2 -ltpm2 # For the benefit of the tpm2 library. INCLUDE_ROOT := $(abspath ./include) CFLAGS += -I$(INCLUDE_ROOT) +CPPFLAGS += -I$(abspath ./builtin) +CPPFLAGS += -I$(abspath ./chip/$(CHIP)) +# For core includes +CPPFLAGS += -I$(abspath .) +CPPFLAGS += -I$(abspath $(BDIR)) +CPPFLAGS += -I$(abspath ./test) + # Make sure the context of the software sha256 implementation fits. If it ever # increases, a compile time assert will fire in tpm2/hash.c. CFLAGS += -DUSER_MIN_HASH_STATE_SIZE=210 diff --git a/builtin/assert.h b/builtin/assert.h new file mode 100644 index 0000000000..7e5f04b375 --- /dev/null +++ b/builtin/assert.h @@ -0,0 +1,12 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_ASSERT_H__ +#define __CROS_EC_ASSERT_H__ + +#include "util.h" +#define assert(x...) ASSERT(x) + +#endif /* __CROS_EC_ASSERT_H__ */ diff --git a/builtin/stdarg.h b/builtin/stdarg.h new file mode 100644 index 0000000000..66ab940b16 --- /dev/null +++ b/builtin/stdarg.h @@ -0,0 +1,24 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_STDARG_H__ +#define __CROS_EC_STDARG_H__ + +/* We use -nostdinc -ffreestanding to keep host system include files + * from contaminating our build. + * Unfortunately this also gets us rid of the _compiler_ includes, like + * stdarg.h. To work around the issue, we define varargs directly here. + */ + +#ifdef __GNUC__ +#define va_start(v, l) __builtin_va_start(v, l) +#define va_end(v) __builtin_va_end(v) +#define va_arg(v, l) __builtin_va_arg(v, l) +typedef __builtin_va_list va_list; +#else +#include_next <stdarg.h> +#endif + +#endif /* __CROS_EC_STDARG_H__ */ diff --git a/builtin/stddef.h b/builtin/stddef.h new file mode 100644 index 0000000000..505dd9f515 --- /dev/null +++ b/builtin/stddef.h @@ -0,0 +1,30 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_STDDEF_H__ +#define __CROS_EC_STDDEF_H__ + +#ifndef __SIZE_TYPE__ +#define __SIZE_TYPE__ unsigned long +#endif + +typedef __SIZE_TYPE__ size_t; +/* There is a GCC macro for a size_t type, but not for a ssize_t type. + * The following construct convinces GCC to make __SIZE_TYPE__ signed. + */ +#define unsigned signed +typedef __SIZE_TYPE__ ssize_t; +#undef unsigned + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#ifndef __WCHAR_TYPE__ +#define __WCHAR_TYPE__ int +#endif +typedef __WCHAR_TYPE__ wchar_t; + +#endif /* __CROS_EC_STDDEF_H__ */ diff --git a/builtin/stdint.h b/builtin/stdint.h new file mode 100644 index 0000000000..75cf8d8ebf --- /dev/null +++ b/builtin/stdint.h @@ -0,0 +1,38 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_STDINT_H__ +#define __CROS_EC_STDINT_H__ + +typedef unsigned char uint8_t; +typedef signed char int8_t; + +typedef unsigned short uint16_t; +typedef signed short int16_t; + +typedef unsigned int uint32_t; +typedef signed int int32_t; + +typedef unsigned long long uint64_t; +typedef signed long long int64_t; + +typedef int intptr_t; +typedef unsigned int uintptr_t; + +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767U) +#endif + +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647U) +#endif + +#endif /* __CROS_EC_STDINT_H__ */ diff --git a/builtin/string.h b/builtin/string.h new file mode 100644 index 0000000000..d30dda8324 --- /dev/null +++ b/builtin/string.h @@ -0,0 +1,16 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* This header is only needed for CR50 compatibility */ + +#ifndef __CROS_EC_STRINGS_H__ +#define __CROS_EC_STRINGS_H__ + +#include <stddef.h> + +void *memcpy(void *dest, const void *src, size_t len); +void *memset(void *dest, int c, size_t len); + +#endif /* __CROS_EC_STRINGS_H__ */ diff --git a/builtin/time.h b/builtin/time.h new file mode 100644 index 0000000000..a069ae18c9 --- /dev/null +++ b/builtin/time.h @@ -0,0 +1,13 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* This header is only needed for CR50 compatibility */ + +#ifndef __CROS_EC_TIME_H__ +#define __CROS_EC_TIME_H__ + +#include <timer.h> + +#endif /* __CROS_EC_TIME_H__ */ diff --git a/chip/g/dcrypto/internal.h b/chip/g/dcrypto/internal.h index 8757ab5e86..61db833a53 100644 --- a/chip/g/dcrypto/internal.h +++ b/chip/g/dcrypto/internal.h @@ -6,7 +6,7 @@ #ifndef __EC_CHIP_G_DCRYPTO_INTERNAL_H #define __EC_CHIP_G_DCRYPTO_INTERNAL_H -#include <inttypes.h> +#include <stdint.h> #include "common.h" #include "sha1.h" diff --git a/chip/g/loader/key_ladder.h b/chip/g/loader/key_ladder.h index 778dc04aea..094dcf8940 100644 --- a/chip/g/loader/key_ladder.h +++ b/chip/g/loader/key_ladder.h @@ -6,7 +6,7 @@ #ifndef __EC_CHIP_G_LOADER_KEY_LADDER_H #define __EC_CHIP_G_LOADER_KEY_LADDER_H -#include <inttypes.h> +#include <stdint.h> #include <stddef.h> void key_ladder_step(uint32_t certificate, const uint32_t *input); diff --git a/common/test_util.c b/common/test_util.c index c5c238d42d..fc9ce64a60 100644 --- a/common/test_util.c +++ b/common/test_util.c @@ -5,8 +5,10 @@ * Test utilities. */ +#ifdef TEST_COVERAGE #include <signal.h> #include <stdlib.h> +#endif #include "console.h" #include "hooks.h" diff --git a/driver/als_si114x.c b/driver/als_si114x.c index bdd39fa5b0..5a64be92cd 100644 --- a/driver/als_si114x.c +++ b/driver/als_si114x.c @@ -219,7 +219,7 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event) /* Just trigger a measurement */ static int read(const struct motion_sensor_t *s, vector_3_t v) { - int ret; + int ret = 0; uint8_t cmd; struct si114x_drv_data_t *data = SI114X_GET_DATA(s); diff --git a/driver/pi3usb30532.h b/driver/pi3usb30532.h index 96c963204b..15a9241239 100644 --- a/driver/pi3usb30532.h +++ b/driver/pi3usb30532.h @@ -8,8 +8,6 @@ #ifndef __CROS_EC_PI3USB30532_H #define __CROS_EC_PI3USB30532_H -#include <inttypes.h> - #include "usb_pd.h" /* USB switch registers */ diff --git a/include/compile_time_macros.h b/include/compile_time_macros.h index 074fb4b256..9b543f9493 100644 --- a/include/compile_time_macros.h +++ b/include/compile_time_macros.h @@ -23,4 +23,6 @@ #define offsetof(type, member) __builtin_offsetof(type, member) #endif +#define __visible __attribute__((externally_visible)) + #endif /* __CROS_EC_COMPILE_TIME_MACROS_H */ diff --git a/include/timer.h b/include/timer.h index 5f92207252..0e7fd7d7ea 100644 --- a/include/timer.h +++ b/include/timer.h @@ -8,8 +8,6 @@ #ifndef __CROS_EC_TIMER_H #define __CROS_EC_TIMER_H -#include <sys/types.h> - #include "common.h" #include "task_id.h" @@ -28,6 +26,9 @@ typedef union { } le /* little endian words */; } timestamp_t; +/* Data type for POSIX style clock() implementation */ +typedef long clock_t; + /** * Initialize the timer module. */ diff --git a/include/trng.h b/include/trng.h index a35496c3fd..e6dcba644c 100644 --- a/include/trng.h +++ b/include/trng.h @@ -5,7 +5,7 @@ #ifndef __EC_INCLUDE_TRNG_H #define __EC_INCLUDE_TRNG_H -#include <sys/types.h> +#include <stddef.h> /** * Initialize the true random number generator. diff --git a/include/util.h b/include/util.h index 8fec4a14e8..d8967ec0c0 100644 --- a/include/util.h +++ b/include/util.h @@ -95,7 +95,7 @@ int isalpha(int c); int isprint(int c); int memcmp(const void *s1, const void *s2, size_t len); void *memcpy(void *dest, const void *src, size_t len); -void *memset(void *dest, int c, size_t len); +__visible void *memset(void *dest, int c, size_t len); void *memmove(void *dest, const void *src, size_t len); int strcasecmp(const char *s1, const char *s2); int strncasecmp(const char *s1, const char *s2, size_t size); |