From 1cfdbd429fee66af9d3cbbf72d449e931296d0cf Mon Sep 17 00:00:00 2001 From: Nick Connolly Date: Fri, 24 Sep 2021 11:41:47 +0100 Subject: [PATCH] include/mock.h: prevent expension of syscall name If a platform defines a syscall using a macro (e.g. #define open _open) then wrapping it fails because DEFINE_RETURN_MOCK and MOCK_GET will use the definition to name the ut_ variables, but DEFINE_WRAPPER will use the original name. This result in an undefined reference when linking. Prevent macro expansion of the syscall name by avoiding nested macro calls in DEFINE_WRAPPER. Include the contents of DEFINE_RETURN_MOCK and MOCK_GET directly in DEFINE_WRAPPER. Signed-off-by: Nick Connolly Change-Id: I452857ec7df43f7a1a5f093439c7d5cf4683f8ee Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9618 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris --- include/spdk_internal/mock.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/spdk_internal/mock.h b/include/spdk_internal/mock.h index 8de44ae55..18b1b9327 100644 --- a/include/spdk_internal/mock.h +++ b/include/spdk_internal/mock.h @@ -72,15 +72,19 @@ extern ret ut_ ## fn; \ ret __wrap_ ## fn args; ret __real_ ## fn args -/* for defining the implmentation of wrappers for syscalls */ +/* + * For defining the implementation of wrappers for syscalls. + * Avoid nested macro calls to prevent macro expansion of fn. + */ #define DEFINE_WRAPPER(fn, ret, dargs, pargs) \ - DEFINE_RETURN_MOCK(fn, ret); \ + bool ut_ ## fn ## _mocked = false; \ + ret ut_ ## fn; \ __attribute__((used)) ret __wrap_ ## fn dargs \ { \ if (!ut_ ## fn ## _mocked) { \ return __real_ ## fn pargs; \ } else { \ - return MOCK_GET(fn); \ + return ut_ ## fn; \ } \ }