From 713045974620ec3f3757fa37865edf9b25da8cc3 Mon Sep 17 00:00:00 2001 From: Vadim Sukhomlinov Date: Thu, 7 Oct 2021 12:14:42 -0700 Subject: cr50: fix fuzzing make runfuzztests started to fail once both: https://crrev.com/c/3162473 and https://crrev.com/c/3208916 landed. Clang seems to incorrectly discarding sections it generated for profiling, resulting in: __profc_DCRYPTO_hw_sha256_init' referenced in section .text.compute_hash[compute_hash]' of build/host/cr50_fuzz/libec.a(libec.a.2.o): defined in discarded section `__llvm_prf_cnts[__profd_DCRYPTO_hw_sha256_init]' of build/host/cr50_fuzz/libec.a(libec.a.2.o) __profc_DCRYPTO_hw_sha256_init' referenced in section .text.create_merkle_tree[create_merkle_tree]' of build/host/cr50_fuzz/libec.a(libec.a.2.o): defined in discarded section `__llvm_prf_cnts[__profd_DCRYPTO_hw_sha256_init]' of build/host/cr50_fuzz/libec.a(libec.a.2.o) clang-13: error: linker command failed with exit code 1 (use -v to see invocation) This definition of __always_inline should be useful in other cases, so moving it into common.h. Note, we have to #undef it first, as it is previously defined in system headers. BUG=none TEST=make buildall -j Signed-off-by: Vadim Sukhomlinov Change-Id: I073b38a68fd43a14dbe92063011c95758030b225 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3213113 Reviewed-by: Vadim Sukhomlinov Reviewed-by: Andrey Pronin Tested-by: Vadim Sukhomlinov Commit-Queue: Vadim Sukhomlinov --- board/cr50/dcrypto/dcrypto.h | 8 -------- include/common.h | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/board/cr50/dcrypto/dcrypto.h b/board/cr50/dcrypto/dcrypto.h index 561a1df7a9..3712f56fc4 100644 --- a/board/cr50/dcrypto/dcrypto.h +++ b/board/cr50/dcrypto/dcrypto.h @@ -46,14 +46,6 @@ enum hashing_mode { HASH_NULL = 0x0010 /* = TPM_ALG_NULL, Only supported for PKCS#1 */ }; -#ifndef __warn_unused_result -#define __warn_unused_result __attribute__((warn_unused_result)) -#endif - -#ifndef __always_inline -#define __always_inline __inline __attribute__((always_inline)) -#endif - /** * SHA1/SHA2, HMAC API */ diff --git a/include/common.h b/include/common.h index 485cbcbe5c..2bbc24d684 100644 --- a/include/common.h +++ b/include/common.h @@ -130,6 +130,23 @@ #endif #endif +#ifndef __warn_unused_result +#define __warn_unused_result __attribute__((warn_unused_result)) +#endif + +#ifdef TEST_CR50_FUZZ +/** + * Workaround: Clang incorrectly handles profiling information + * used for fuzzing with __attribute__((always_inline)). + */ +#undef __always_inline +#define __always_inline static inline +#else +#ifndef __always_inline +#define __always_inline __inline __attribute__((always_inline)) +#endif +#endif + /* * Macros for combining bytes into larger integers. _LE and _BE signify little * and big endian versions respectively. -- cgit v1.2.1