mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 10:14:57 +00:00
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>
This commit is contained in:
committed by
chrome-bot
parent
fc9ed52397
commit
bc404c94b4
@@ -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\
|
||||
|
||||
@@ -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
|
||||
|
||||
12
builtin/assert.h
Normal file
12
builtin/assert.h
Normal file
@@ -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__ */
|
||||
24
builtin/stdarg.h
Normal file
24
builtin/stdarg.h
Normal file
@@ -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__ */
|
||||
30
builtin/stddef.h
Normal file
30
builtin/stddef.h
Normal file
@@ -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__ */
|
||||
38
builtin/stdint.h
Normal file
38
builtin/stdint.h
Normal file
@@ -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__ */
|
||||
16
builtin/string.h
Normal file
16
builtin/string.h
Normal file
@@ -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__ */
|
||||
13
builtin/time.h
Normal file
13
builtin/time.h
Normal file
@@ -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__ */
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
* Test utilities.
|
||||
*/
|
||||
|
||||
#ifdef TEST_COVERAGE
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "console.h"
|
||||
#include "hooks.h"
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#ifndef __CROS_EC_PI3USB30532_H
|
||||
#define __CROS_EC_PI3USB30532_H
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "usb_pd.h"
|
||||
|
||||
/* USB switch registers */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user