From 817f52764144ef1aae4a8d52ac87a8eeae3ee538 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 12:53:47 -0500 Subject: [PATCH] arch/xtensa: rearrange for standard use of extern "C" Consistently place C++ use of extern "C" after all include directives, within the negative branch of _ASMLANGUAGE if used. Background from issue #17997: Declarations that use C linkage should be placed within extern "C" so the language linkage is correct when the header is included by a C++ compiler. Similarly #include directives should be outside the extern "C" to ensure the language-specific default linkage is applied to any declarations provided by the included header. See: https://en.cppreference.com/w/cpp/language/language_linkage Signed-off-by: Peter Bigot --- arch/xtensa/include/kernel_arch_data.h | 21 ++++++++++----------- arch/xtensa/include/kernel_arch_func.h | 3 +-- arch/xtensa/include/xtensa_config.h | 9 --------- arch/xtensa/include/xtensa_context.h | 16 +++++++++++----- include/arch/xtensa/arch.h | 11 ++++++----- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/arch/xtensa/include/kernel_arch_data.h b/arch/xtensa/include/kernel_arch_data.h index b544602d54a..f96670892fb 100644 --- a/arch/xtensa/include/kernel_arch_data.h +++ b/arch/xtensa/include/kernel_arch_data.h @@ -20,15 +20,15 @@ #ifndef ZEPHYR_ARCH_XTENSA_INCLUDE_KERNEL_ARCH_DATA_H_ #define ZEPHYR_ARCH_XTENSA_INCLUDE_KERNEL_ARCH_DATA_H_ -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include #include +/* stacks */ +#define STACK_ROUND_UP(x) ROUND_UP(x, STACK_ALIGN_SIZE) +#define STACK_ROUND_DOWN(x) ROUND_DOWN(x, STACK_ALIGN_SIZE) + #if !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) #include /* public kernel API */ #include @@ -36,6 +36,10 @@ extern "C" { #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* Bitmask definitions for the struct k_thread->flags bit field */ /* executing context is interrupt handler */ @@ -47,20 +51,15 @@ extern "C" { typedef struct __esf __esf_t; -#endif /*! _ASMLANGUAGE && ! __ASSEMBLER__ */ - #ifdef CONFIG_USE_SWITCH void xtensa_switch(void *switch_to, void **switched_from); #define z_arch_switch xtensa_switch #endif -/* stacks */ -#define STACK_ROUND_UP(x) ROUND_UP(x, STACK_ALIGN_SIZE) -#define STACK_ROUND_DOWN(x) ROUND_DOWN(x, STACK_ALIGN_SIZE) - #ifdef __cplusplus } #endif -#endif /* ZEPHYR_ARCH_XTENSA_INCLUDE_KERNEL_ARCH_DATA_H_ */ +#endif /*! _ASMLANGUAGE && ! __ASSEMBLER__ */ +#endif /* ZEPHYR_ARCH_XTENSA_INCLUDE_KERNEL_ARCH_DATA_H_ */ diff --git a/arch/xtensa/include/kernel_arch_func.h b/arch/xtensa/include/kernel_arch_func.h index fc46a5199c4..36ab8adecf4 100644 --- a/arch/xtensa/include/kernel_arch_func.h +++ b/arch/xtensa/include/kernel_arch_func.h @@ -12,6 +12,7 @@ #ifndef _ASMLANGUAGE #include #include +#include /* For size_t */ #ifdef __cplusplus extern "C" { @@ -119,8 +120,6 @@ z_set_thread_return_value(struct k_thread *thread, unsigned int value) extern void k_cpu_atomic_idle(unsigned int key); -#include /* For size_t */ - #ifdef __cplusplus } #endif diff --git a/arch/xtensa/include/xtensa_config.h b/arch/xtensa/include/xtensa_config.h index b5600640dae..fdfb47220eb 100644 --- a/arch/xtensa/include/xtensa_config.h +++ b/arch/xtensa/include/xtensa_config.h @@ -6,10 +6,6 @@ #ifndef ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_CONFIG_H_ #define ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_CONFIG_H_ -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include /* required for XSHAL_CLIB */ @@ -133,9 +129,4 @@ extern "C" { #define XT_STACK_EXTRA_CLIB (XT_XTRA_SIZE + XT_CLIB_CONTEXT_AREA_SIZE) -#ifdef __cplusplus -} -#endif - #endif /* ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_CONFIG_H_ */ - diff --git a/arch/xtensa/include/xtensa_context.h b/arch/xtensa/include/xtensa_context.h index 7351bdd58a9..a2dcf5517d3 100644 --- a/arch/xtensa/include/xtensa_context.h +++ b/arch/xtensa/include/xtensa_context.h @@ -19,15 +19,18 @@ #ifndef ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_CONTEXT_H_ #define ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_CONTEXT_H_ -#ifdef __ASSEMBLER__ -#include -#endif - #include #include #include #include +#ifdef __ASSEMBLER__ +#include +#else /* __ASSEMBLER__ */ +#ifdef __cplusplus +extern "C" { +#endif +#endif /* __ASSEMBLER__ */ /* Align a value up to nearest n-byte boundary, where n is a power of 2. */ #define ALIGNUP(n, val) (((val) + (n)-1) & -(n)) @@ -310,8 +313,11 @@ ret #define RET(sz) retw #define RET0 retw #endif /* __XTENSA_CALL0_ABI__ */ +#else /* __ASSEMBLER__ */ +#ifdef __cplusplus +} +#endif #endif /* __ASSEMBLER__ */ #endif /* ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_CONTEXT_H_ */ - diff --git a/include/arch/xtensa/arch.h b/include/arch/xtensa/arch.h index f0008b3e750..68739c3a98d 100644 --- a/include/arch/xtensa/arch.h +++ b/include/arch/xtensa/arch.h @@ -15,10 +15,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #include #if !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) #include @@ -36,6 +32,10 @@ extern "C" { #include +#ifdef __cplusplus +extern "C" { +#endif + /* internal routine documented in C file, needed by IRQ_CONNECT() macro */ extern void z_irq_priority_set(u32_t irq, u32_t prio, u32_t flags); @@ -95,9 +95,10 @@ static ALWAYS_INLINE void arch_nop(void) __asm__ volatile("nop"); } -#endif /* !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) */ #ifdef __cplusplus } #endif +#endif /* !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) */ + #endif /* ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_H_ */