From d9e155fcb1e96f2e391c69cf0d4491cc4e0a01d5 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 15:54:24 -0500 Subject: [PATCH 01/11] arch/x86: 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/x86/include/ia32/kernel_arch_func.h | 4 ++-- include/arch/x86/ia32/arch.h | 23 ++++++++++------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/arch/x86/include/ia32/kernel_arch_func.h b/arch/x86/include/ia32/kernel_arch_func.h index 574c441fdb9db..c9580d352b216 100644 --- a/arch/x86/include/ia32/kernel_arch_func.h +++ b/arch/x86/include/ia32/kernel_arch_func.h @@ -12,6 +12,8 @@ #ifndef _ASMLANGUAGE +#include /* For size_t */ + #ifdef __cplusplus extern "C" { #endif @@ -92,8 +94,6 @@ static inline struct x86_mmu_pdpt *z_x86_pdpt_get(struct k_thread *thread) /* ASM code to fiddle with registers to enable the MMU with PAE paging */ void z_x86_enable_paging(void); -#include /* For size_t */ - #ifdef __cplusplus } #endif diff --git a/include/arch/x86/ia32/arch.h b/include/arch/x86/ia32/arch.h index 1c0f1a2476715..6c2848716d3f0 100644 --- a/include/arch/x86/ia32/arch.h +++ b/include/arch/x86/ia32/arch.h @@ -25,13 +25,12 @@ #include #ifndef _ASMLANGUAGE +#include /* for size_t */ + #include #include -#endif -#ifdef __cplusplus -extern "C" { -#endif +#endif /* _ASMLANGUAGE */ /* GDT layout */ #define CODE_SEG 0x08 @@ -53,8 +52,12 @@ extern "C" { #ifndef _ASMLANGUAGE -/* interrupt/exception/error related definitions */ +#ifdef __cplusplus +extern "C" { +#endif + +/* interrupt/exception/error related definitions */ /* * The TCS must be aligned to the same boundary as that used by the floating @@ -315,10 +318,6 @@ struct _x86_syscall_stack_frame { u32_t ss; }; -#endif /* !_ASMLANGUAGE */ - -#ifndef _ASMLANGUAGE - /** * * @internal @@ -561,8 +560,6 @@ extern void k_float_enable(struct k_thread *thread, unsigned int options); * @} */ -#include /* for size_t */ - extern void k_cpu_idle(void); extern u32_t z_timer_cycle_get_32(void); @@ -809,10 +806,10 @@ int z_x86_mmu_validate(struct x86_mmu_pdpt *pdpt, void *addr, size_t size, int write); #endif /* CONFIG_X86_MMU */ -#endif /* !_ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* !_ASMLANGUAGE */ + #endif /* ZEPHYR_INCLUDE_ARCH_X86_IA32_ARCH_H_ */ From 7f9f10f46940795bc1b7252b97f259da6a14db86 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 12:55:54 -0500 Subject: [PATCH 02/11] soc/arm/xilinx_zynqmp: clean up use of extern "C" Remove extern "C" support from files that don't declare symbols subject to language linkage effects. 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 --- soc/arm/xilinx_zynqmp/soc.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/soc/arm/xilinx_zynqmp/soc.h b/soc/arm/xilinx_zynqmp/soc.h index 6c212d1c99d1a..6df6784123343 100644 --- a/soc/arm/xilinx_zynqmp/soc.h +++ b/soc/arm/xilinx_zynqmp/soc.h @@ -10,10 +10,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include @@ -21,8 +17,4 @@ extern "C" { #endif /* !_ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _BOARD__H_ */ From 9a4890b16ad7cf97ecd880afbacbace4d1c62ae1 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 16:51:31 -0500 Subject: [PATCH 03/11] soc/arm/arm: rearrange for standard use of extern "C" Move the tail include file outside the extern "C" block. 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 --- soc/arm/arm/beetle/CMSDK_BEETLE.h | 4 ++-- soc/arm/arm/musca_a/system_cmsdk_musca.h | 5 ++--- soc/arm/arm/musca_b1/system_cmsdk_musca_b1.h | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/soc/arm/arm/beetle/CMSDK_BEETLE.h b/soc/arm/arm/beetle/CMSDK_BEETLE.h index 043e8ec011ac2..3a5e8b7f39ea7 100644 --- a/soc/arm/arm/beetle/CMSDK_BEETLE.h +++ b/soc/arm/arm/beetle/CMSDK_BEETLE.h @@ -92,10 +92,10 @@ typedef enum IRQn #define __NVIC_PRIO_BITS 3 /* Number of Bits used for Priority Levels */ #define __Vendor_SysTickConfig 0 /* Set to 1 if different SysTick Config is used */ -#include /* Processor and core peripherals */ - #ifdef __cplusplus } #endif +#include /* Processor and core peripherals */ + #endif /* CMSDK_BEETLE_H */ diff --git a/soc/arm/arm/musca_a/system_cmsdk_musca.h b/soc/arm/arm/musca_a/system_cmsdk_musca.h index d9d5ac77c28ff..ceb07e0ecf880 100644 --- a/soc/arm/arm/musca_a/system_cmsdk_musca.h +++ b/soc/arm/arm/musca_a/system_cmsdk_musca.h @@ -131,11 +131,10 @@ typedef enum IRQn { #define __FPU_PRESENT 0U /* no FPU present */ #define __DSP_PRESENT 0U /* no DSP extension present */ - -#include /*!< ARM Cortex-M33 processor and core peripherals */ - #ifdef __cplusplus } #endif +#include /*!< ARM Cortex-M33 processor and core peripherals */ + #endif /* SYSTEM_CMSDK_MUSCA_H */ diff --git a/soc/arm/arm/musca_b1/system_cmsdk_musca_b1.h b/soc/arm/arm/musca_b1/system_cmsdk_musca_b1.h index 91d4a14805a3f..4a102d713a3dd 100644 --- a/soc/arm/arm/musca_b1/system_cmsdk_musca_b1.h +++ b/soc/arm/arm/musca_b1/system_cmsdk_musca_b1.h @@ -131,11 +131,10 @@ typedef enum IRQn { #define __FPU_PRESENT 0U /* no FPU present */ #define __DSP_PRESENT 0U /* no DSP extension present */ - -#include /*!< ARM Cortex-M33 processor and core peripherals */ - #ifdef __cplusplus } #endif +#include /*!< ARM Cortex-M33 processor and core peripherals */ + #endif /* SYSTEM_CMSDK_MUSCA_B1_H */ From d944e7baaf2bcf46ef8aa9b78de1bf1575ed124a Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 16:53:37 -0500 Subject: [PATCH 04/11] soc/arm/ti_lm3s6965: remove unnecessary extern C block This header doesn't define any symbols with linkage. Signed-off-by: Peter Bigot --- soc/arm/ti_lm3s6965/soc.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/soc/arm/ti_lm3s6965/soc.h b/soc/arm/ti_lm3s6965/soc.h index fe880535ceb2c..aa335c0023906 100644 --- a/soc/arm/ti_lm3s6965/soc.h +++ b/soc/arm/ti_lm3s6965/soc.h @@ -17,10 +17,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - /* default system clock */ #define SYSCLK_DEFAULT_IOSC_HZ MHZ(12) @@ -77,8 +73,4 @@ extern "C" { #endif /* !_ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _BOARD__H_ */ From d1a4d441440b34d5bb13a7109543462d24d13d28 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 12:52:55 -0500 Subject: [PATCH 05/11] arch/arm: 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. In arch.h the extern "C" in the including context is left active during include of target-specific mpu headers to avoid more complex restructuring. 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/arm/core/cortex_m/vector_table.h | 14 ++++++------ arch/arm/core/cortex_r/vector_table.h | 10 +++++++- arch/arm/include/cortex_m/cmse.h | 11 ++++----- arch/arm/include/cortex_m/exc.h | 11 ++++----- arch/arm/include/cortex_m/stack.h | 12 +++++----- arch/arm/include/cortex_m/tz.h | 12 +++++----- arch/arm/include/cortex_r/exc.h | 11 ++++----- arch/arm/include/kernel_arch_data.h | 33 +++++++++++---------------- include/arch/arm/arch.h | 1 + include/arch/arm/asm_inline_gcc.h | 12 +++++----- include/arch/arm/cortex_m/cmsis.h | 8 +++---- include/arch/arm/cortex_r/sys_io.h | 12 +++++----- include/arch/arm/exc.h | 12 +++++----- 13 files changed, 79 insertions(+), 80 deletions(-) diff --git a/arch/arm/core/cortex_m/vector_table.h b/arch/arm/core/cortex_m/vector_table.h index 850d5c4cb1c15..98ebf81a49ee9 100644 --- a/arch/arm/core/cortex_m/vector_table.h +++ b/arch/arm/core/cortex_m/vector_table.h @@ -21,10 +21,6 @@ #ifndef ZEPHYR_ARCH_ARM_CORE_CORTEX_M_VECTOR_TABLE_H_ #define ZEPHYR_ARCH_ARM_CORE_CORTEX_M_VECTOR_TABLE_H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifdef _ASMLANGUAGE #include @@ -57,14 +53,18 @@ GTEXT(__reserved) GTEXT(_PrepC) GTEXT(_isr_wrapper) -#else +#else /* _ASMLANGUAGE */ -extern void *_vector_table[]; +#ifdef __cplusplus +extern "C" { +#endif -#endif /* _ASMLANGUAGE */ +extern void *_vector_table[]; #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_ARCH_ARM_CORE_CORTEX_M_VECTOR_TABLE_H_ */ diff --git a/arch/arm/core/cortex_r/vector_table.h b/arch/arm/core/cortex_r/vector_table.h index f10e0f82dd982..5b7bea8dc491e 100644 --- a/arch/arm/core/cortex_r/vector_table.h +++ b/arch/arm/core/cortex_r/vector_table.h @@ -43,10 +43,18 @@ GTEXT(__reserved) GTEXT(_PrepC) GTEXT(_isr_wrapper) -#else +#else /* _ASMLANGUAGE */ + +#ifdef __cplusplus +extern "C" { +#endif extern void *_vector_table[]; +#ifdef __cplusplus +} +#endif + #endif /* _ASMLANGUAGE */ #endif /* _VECTOR_TABLE__H_ */ diff --git a/arch/arm/include/cortex_m/cmse.h b/arch/arm/include/cortex_m/cmse.h index 6327df77f6902..d55bdd481b336 100644 --- a/arch/arm/include/cortex_m/cmse.h +++ b/arch/arm/include/cortex_m/cmse.h @@ -14,10 +14,6 @@ #ifndef ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_M_CMSE_H_ #define ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_M_CMSE_H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifdef _ASMLANGUAGE /* nothing */ @@ -27,6 +23,9 @@ extern "C" { #include #include +#ifdef __cplusplus +extern "C" { +#endif /* * Address information retrieval based on the TT instructions. @@ -438,10 +437,10 @@ int arm_cmse_addr_range_nonsecure_readwrite_ok(u32_t addr, u32_t size, #endif /* CONFIG_ARM_SECURE_FIRMWARE */ -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_M_CMSE_H_ */ diff --git a/arch/arm/include/cortex_m/exc.h b/arch/arm/include/cortex_m/exc.h index 0581612234b4f..db970c942bd3a 100644 --- a/arch/arm/include/cortex_m/exc.h +++ b/arch/arm/include/cortex_m/exc.h @@ -16,10 +16,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #ifdef _ASMLANGUAGE /* nothing */ @@ -30,6 +26,10 @@ extern "C" { #include #include +#ifdef __cplusplus +extern "C" { +#endif + #ifdef CONFIG_IRQ_OFFLOAD extern volatile irq_offload_routine_t offload_routine; #endif @@ -153,11 +153,10 @@ static ALWAYS_INLINE void z_clearfaults(void) #endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */ } -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ #endif /* ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_M_EXC_H_ */ diff --git a/arch/arm/include/cortex_m/stack.h b/arch/arm/include/cortex_m/stack.h index addf458cab4b2..119c35cc8d3b3 100644 --- a/arch/arm/include/cortex_m/stack.h +++ b/arch/arm/include/cortex_m/stack.h @@ -14,10 +14,6 @@ #ifndef ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_M_STACK_H_ #define ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_M_STACK_H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifdef _ASMLANGUAGE /* nothing */ @@ -26,6 +22,10 @@ extern "C" { #include +#ifdef __cplusplus +extern "C" { +#endif + extern K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE); /** @@ -63,10 +63,10 @@ static ALWAYS_INLINE void z_InterruptStackSetup(void) #endif /* CONFIG_STACK_ALIGN_DOUBLE_WORD */ } -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_M_STACK_H_ */ diff --git a/arch/arm/include/cortex_m/tz.h b/arch/arm/include/cortex_m/tz.h index e84a33bb69364..425347d093bc4 100644 --- a/arch/arm/include/cortex_m/tz.h +++ b/arch/arm/include/cortex_m/tz.h @@ -14,10 +14,6 @@ #ifndef ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_M_TZ_H_ #define ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_M_TZ_H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifdef _ASMLANGUAGE /* nothing */ @@ -27,6 +23,10 @@ extern "C" { #include #include +#ifdef __cplusplus +extern "C" { +#endif + /** * * @brief Initial Non-Secure state configuration @@ -334,10 +334,10 @@ typedef void __attribute__((cmse_nonsecure_call)) (*tz_ns_func_ptr_t) (void); #define TZ_NONSECURE_FUNC_PTR_IS_NS(fptr) \ cmse_is_nsfptr(fptr) -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_M_TZ_H_ */ diff --git a/arch/arm/include/cortex_r/exc.h b/arch/arm/include/cortex_r/exc.h index be1a06e061a5e..37c84c405b507 100644 --- a/arch/arm/include/cortex_r/exc.h +++ b/arch/arm/include/cortex_r/exc.h @@ -16,10 +16,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #ifdef _ASMLANGUAGE /* nothing */ @@ -28,6 +24,10 @@ extern "C" { #include +#ifdef __cplusplus +extern "C" { +#endif + #ifdef CONFIG_IRQ_OFFLOAD extern volatile irq_offload_routine_t offload_routine; #endif @@ -76,11 +76,10 @@ static ALWAYS_INLINE void z_clearfaults(void) extern void cortex_r_svc(void); -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ #endif /* _ARM_CORTEXRM_ISR__H_ */ diff --git a/arch/arm/include/kernel_arch_data.h b/arch/arm/include/kernel_arch_data.h index 37d822fa37cd7..9932dc910110a 100644 --- a/arch/arm/include/kernel_arch_data.h +++ b/arch/arm/include/kernel_arch_data.h @@ -20,30 +20,11 @@ #ifndef ZEPHYR_ARCH_ARM_INCLUDE_KERNEL_ARCH_DATA_H_ #define ZEPHYR_ARCH_ARM_INCLUDE_KERNEL_ARCH_DATA_H_ -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include #include -#ifndef _ASMLANGUAGE -#include -#include -#include -#include -#include -#endif - -#ifndef _ASMLANGUAGE - -typedef struct __esf _esf_t; -typedef struct __basic_sf _basic_sf_t; - -#endif /* _ASMLANGUAGE */ - /* stacks */ #define STACK_ROUND_UP(x) ROUND_UP(x, STACK_ALIGN_SIZE) @@ -58,11 +39,23 @@ typedef struct __basic_sf _basic_sf_t; #endif #ifndef _ASMLANGUAGE +#include +#include +#include +#include +#include -#endif /* _ASMLANGUAGE */ +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct __esf _esf_t; +typedef struct __basic_sf _basic_sf_t; #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_ARCH_ARM_INCLUDE_KERNEL_ARCH_DATA_H_ */ diff --git a/include/arch/arm/arch.h b/include/arch/arm/arch.h index 322136f3ef4df..8e19fe8524e23 100644 --- a/include/arch/arm/arch.h +++ b/include/arch/arm/arch.h @@ -240,6 +240,7 @@ extern "C" { #define Z_ARCH_THREAD_STACK_BUFFER(sym) \ ((char *)(sym) + MPU_GUARD_ALIGN_AND_SIZE) +/* Legacy case: retain containing extern "C" with C++ */ #ifdef CONFIG_ARM_MPU #ifdef CONFIG_CPU_HAS_ARM_MPU #include diff --git a/include/arch/arm/asm_inline_gcc.h b/include/arch/arm/asm_inline_gcc.h index 122104e29bca8..085bd5e9f8d1c 100644 --- a/include/arch/arm/asm_inline_gcc.h +++ b/include/arch/arm/asm_inline_gcc.h @@ -11,10 +11,6 @@ #ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ASM_INLINE_GCC_H_ #define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ASM_INLINE_GCC_H_ -#ifdef __cplusplus -extern "C" { -#endif - /* * The file must not be included directly * Include arch/cpu.h instead @@ -26,6 +22,10 @@ extern "C" { #include #include +#ifdef __cplusplus +extern "C" { +#endif + /** * * @brief Disable all interrupts on the CPU @@ -158,10 +158,10 @@ static ALWAYS_INLINE bool z_arch_irq_unlocked(unsigned int key) return key == 0; } -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ASM_INLINE_GCC_H_ */ diff --git a/include/arch/arm/cortex_m/cmsis.h b/include/arch/arm/cortex_m/cmsis.h index 672529864494f..768d51222c5ed 100644 --- a/include/arch/arm/cortex_m/cmsis.h +++ b/include/arch/arm/cortex_m/cmsis.h @@ -92,6 +92,10 @@ typedef enum { #error "DT_NUM_IRQ_PRIO_BITS and __NVIC_PRIO_BITS are not set to the same value" #endif +#ifdef __cplusplus +} +#endif + #if defined(CONFIG_CPU_CORTEX_M0) #include #elif defined(CONFIG_CPU_CORTEX_M0PLUS) @@ -110,8 +114,4 @@ typedef enum { #error "Unknown Cortex-M device" #endif -#ifdef __cplusplus -} -#endif - #endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_CMSIS_H_ */ diff --git a/include/arch/arm/cortex_r/sys_io.h b/include/arch/arm/cortex_r/sys_io.h index 918002ca99b0c..197d289d3f9f5 100644 --- a/include/arch/arm/cortex_r/sys_io.h +++ b/include/arch/arm/cortex_r/sys_io.h @@ -12,15 +12,15 @@ #ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_R_SYS_IO_H_ #define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_R_SYS_IO_H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* Memory mapped registers I/O functions */ static ALWAYS_INLINE u8_t sys_read8(mem_addr_t addr) @@ -153,10 +153,10 @@ static ALWAYS_INLINE return ret; } -#endif - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_R_SYS_IO_H_ */ diff --git a/include/arch/arm/exc.h b/include/arch/arm/exc.h index 1d94a14ccdf7b..dfa1ad8e4a8a9 100644 --- a/include/arch/arm/exc.h +++ b/include/arch/arm/exc.h @@ -14,10 +14,6 @@ #ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_EXC_H_ #define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_EXC_H_ -#ifdef __cplusplus -extern "C" { -#endif - /* for assembler, only works with constants */ #define Z_EXC_PRIO(pri) (((pri) << (8 - DT_NUM_IRQ_PRIO_BITS)) & 0xff) @@ -44,6 +40,10 @@ GTEXT(z_ExcExit); #else #include +#ifdef __cplusplus +extern "C" { +#endif + struct __esf { struct __basic_sf { sys_define_gpr_with_alias(a1, r0); @@ -66,10 +66,10 @@ typedef struct __esf z_arch_esf_t; extern void z_ExcExit(void); -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_EXC_H_ */ From e18634e6dac343429d75975c042af344a503c3a7 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 12:55:44 -0500 Subject: [PATCH 06/11] soc/arm/silabs_exx32: clean up use of extern "C" Remove extern "C" support from files that don't declare symbols subject to language linkage effects. 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 --- soc/arm/silabs_exx32/common/soc_gpio.h | 8 ++++++++ soc/arm/silabs_exx32/efm32hg/soc.h | 8 -------- soc/arm/silabs_exx32/efm32pg12b/soc.h | 8 -------- soc/arm/silabs_exx32/efm32wg/soc.h | 8 -------- soc/arm/silabs_exx32/efr32fg1p/soc.h | 8 -------- soc/arm/silabs_exx32/efr32mg12p/soc.h | 8 -------- 6 files changed, 8 insertions(+), 40 deletions(-) diff --git a/soc/arm/silabs_exx32/common/soc_gpio.h b/soc/arm/silabs_exx32/common/soc_gpio.h index 406be31df188b..3519a0533f4ea 100644 --- a/soc/arm/silabs_exx32/common/soc_gpio.h +++ b/soc/arm/silabs_exx32/common/soc_gpio.h @@ -14,6 +14,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct soc_gpio_pin { GPIO_Port_TypeDef port; /** GPIO port */ unsigned int pin; /** GPIO pin on the port */ @@ -27,4 +31,8 @@ struct soc_gpio_pin { */ void soc_gpio_configure(const struct soc_gpio_pin *pin); +#ifdef __cplusplus +} +#endif + #endif /* _SILABS_EXX32_SOC_GPIO_H_ */ diff --git a/soc/arm/silabs_exx32/efm32hg/soc.h b/soc/arm/silabs_exx32/efm32hg/soc.h index 3c8992c2880ea..2c525d324375d 100644 --- a/soc/arm/silabs_exx32/efm32hg/soc.h +++ b/soc/arm/silabs_exx32/efm32hg/soc.h @@ -15,10 +15,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include @@ -29,8 +25,4 @@ extern "C" { #endif /* !_ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _SOC__H_ */ diff --git a/soc/arm/silabs_exx32/efm32pg12b/soc.h b/soc/arm/silabs_exx32/efm32pg12b/soc.h index b63e9a14a90eb..5a05892a1abd9 100644 --- a/soc/arm/silabs_exx32/efm32pg12b/soc.h +++ b/soc/arm/silabs_exx32/efm32pg12b/soc.h @@ -15,10 +15,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include @@ -30,8 +26,4 @@ extern "C" { #endif /* !_ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _SOC__H_ */ diff --git a/soc/arm/silabs_exx32/efm32wg/soc.h b/soc/arm/silabs_exx32/efm32wg/soc.h index b195c84cd173a..761a50da9f2f4 100644 --- a/soc/arm/silabs_exx32/efm32wg/soc.h +++ b/soc/arm/silabs_exx32/efm32wg/soc.h @@ -15,10 +15,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include @@ -30,8 +26,4 @@ extern "C" { #endif /* !_ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _SOC__H_ */ diff --git a/soc/arm/silabs_exx32/efr32fg1p/soc.h b/soc/arm/silabs_exx32/efr32fg1p/soc.h index 4b00ac5f19967..e39b8f48deeea 100644 --- a/soc/arm/silabs_exx32/efr32fg1p/soc.h +++ b/soc/arm/silabs_exx32/efr32fg1p/soc.h @@ -15,10 +15,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include @@ -30,8 +26,4 @@ extern "C" { #endif /* !_ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _SOC__H_ */ diff --git a/soc/arm/silabs_exx32/efr32mg12p/soc.h b/soc/arm/silabs_exx32/efr32mg12p/soc.h index 1345ea56d6aca..4bd11b85096eb 100644 --- a/soc/arm/silabs_exx32/efr32mg12p/soc.h +++ b/soc/arm/silabs_exx32/efr32mg12p/soc.h @@ -15,10 +15,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include @@ -29,8 +25,4 @@ extern "C" { #endif /* !_ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _SOC__H_ */ From f0da8076c0a16189d98bee4dfb84c9a9a4fa9c8c Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 12:55:33 -0500 Subject: [PATCH 07/11] soc/arm/nxp*: 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. Remove extern "C" support from files that don't declare objects or functions. 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 --- soc/arm/nxp_imx/mcimx6x_m4/soc.h | 8 -------- soc/arm/nxp_imx/mcimx7_m4/soc.h | 8 -------- soc/arm/nxp_imx/rt/soc.h | 12 ++++++------ soc/arm/nxp_kinetis/k6x/soc.h | 8 -------- soc/arm/nxp_kinetis/kl2x/soc.h | 8 -------- soc/arm/nxp_kinetis/kwx/soc.h | 8 -------- soc/arm/nxp_lpc/lpc54xxx/soc.h | 8 -------- soc/arm/nxp_lpc/lpc55xxx/soc.h | 8 -------- 8 files changed, 6 insertions(+), 62 deletions(-) diff --git a/soc/arm/nxp_imx/mcimx6x_m4/soc.h b/soc/arm/nxp_imx/mcimx6x_m4/soc.h index 92bba5fe3252e..33679cb184279 100644 --- a/soc/arm/nxp_imx/mcimx6x_m4/soc.h +++ b/soc/arm/nxp_imx/mcimx6x_m4/soc.h @@ -7,10 +7,6 @@ #ifndef _SOC__H_ #define _SOC__H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include "rdc.h" @@ -20,8 +16,4 @@ extern "C" { #endif /* !_ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _SOC__H_ */ diff --git a/soc/arm/nxp_imx/mcimx7_m4/soc.h b/soc/arm/nxp_imx/mcimx7_m4/soc.h index 43c870752681a..5f9540084b679 100644 --- a/soc/arm/nxp_imx/mcimx7_m4/soc.h +++ b/soc/arm/nxp_imx/mcimx7_m4/soc.h @@ -7,10 +7,6 @@ #ifndef _SOC__H_ #define _SOC__H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include "rdc.h" @@ -21,8 +17,4 @@ extern "C" { #endif /* !_ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _SOC__H_ */ diff --git a/soc/arm/nxp_imx/rt/soc.h b/soc/arm/nxp_imx/rt/soc.h index 9206c215aada4..2960732ae58e2 100644 --- a/soc/arm/nxp_imx/rt/soc.h +++ b/soc/arm/nxp_imx/rt/soc.h @@ -9,10 +9,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include @@ -23,6 +19,10 @@ extern "C" { */ #include +#ifdef __cplusplus +extern "C" { +#endif + #if defined(CONFIG_DISK_ACCESS_USDHC1) || \ defined(CONFIG_DISK_ACCESS_USDHC2) @@ -36,10 +36,10 @@ void imxrt_usdhc_pinmux_cb_register(usdhc_pin_cfg_cb cb); #endif -#endif /* !_ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* !_ASMLANGUAGE */ + #endif /* _SOC__H_ */ diff --git a/soc/arm/nxp_kinetis/k6x/soc.h b/soc/arm/nxp_kinetis/k6x/soc.h index 37e299208a1ad..d3fc56077f9b3 100644 --- a/soc/arm/nxp_kinetis/k6x/soc.h +++ b/soc/arm/nxp_kinetis/k6x/soc.h @@ -17,10 +17,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - /* default system clock */ #define SYSCLK_DEFAULT_IOSC_HZ MHZ(120) @@ -40,8 +36,4 @@ extern "C" { #endif /* !_ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _SOC__H_ */ diff --git a/soc/arm/nxp_kinetis/kl2x/soc.h b/soc/arm/nxp_kinetis/kl2x/soc.h index f772368657eb9..de7fe6149238c 100644 --- a/soc/arm/nxp_kinetis/kl2x/soc.h +++ b/soc/arm/nxp_kinetis/kl2x/soc.h @@ -9,10 +9,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #define UART0_CLK_SRC kCLOCK_CoreSysClk #ifndef _ASMLANGUAGE @@ -24,8 +20,4 @@ extern "C" { #endif /* !_ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _SOC__H_ */ diff --git a/soc/arm/nxp_kinetis/kwx/soc.h b/soc/arm/nxp_kinetis/kwx/soc.h index 4181eb94a46a5..e9d3ca540a926 100644 --- a/soc/arm/nxp_kinetis/kwx/soc.h +++ b/soc/arm/nxp_kinetis/kwx/soc.h @@ -10,10 +10,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #if defined(CONFIG_SOC_MKW40Z4) || defined(CONFIG_SOC_MKW41Z4) #define LPUART0_CLK_SRC kCLOCK_CoreSysClk @@ -35,8 +31,4 @@ extern "C" { #endif /* !_ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _SOC__H_ */ diff --git a/soc/arm/nxp_lpc/lpc54xxx/soc.h b/soc/arm/nxp_lpc/lpc54xxx/soc.h index 7d5d626f406ec..1979248801082 100644 --- a/soc/arm/nxp_lpc/lpc54xxx/soc.h +++ b/soc/arm/nxp_lpc/lpc54xxx/soc.h @@ -15,10 +15,6 @@ #ifndef _SOC__H_ #define _SOC__H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include #include @@ -36,8 +32,4 @@ extern "C" { #define IOCON_PIO_SLEW_STANDARD 0x00u #define IOCON_PIO_MODE_PULLUP 0x10u -#ifdef __cplusplus -} -#endif - #endif /* _SOC__H_ */ diff --git a/soc/arm/nxp_lpc/lpc55xxx/soc.h b/soc/arm/nxp_lpc/lpc55xxx/soc.h index 02bf6b08e1531..d1fd4e406246c 100644 --- a/soc/arm/nxp_lpc/lpc55xxx/soc.h +++ b/soc/arm/nxp_lpc/lpc55xxx/soc.h @@ -15,10 +15,6 @@ #ifndef _SOC__H_ #define _SOC__H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include #include @@ -37,8 +33,4 @@ extern "C" { #define IOCON_PIO_MODE_PULLUP 0x20u /*!<@brief Selects pull-up function */ #define IOCON_PIO_INPFILT_OFF 0x1000u /*!<@brief Input filter disabled */ -#ifdef __cplusplus -} -#endif - #endif /* _SOC__H_ */ From 85efdb6f05e053873d968f644bf19d69c32fa4bf Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 12:54:01 -0500 Subject: [PATCH 08/11] arch/common: 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 --- include/arch/common/ffs.h | 11 +++++------ include/arch/common/sys_io.h | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/arch/common/ffs.h b/include/arch/common/ffs.h index 57ea6dc302b15..627f0df7c5a6e 100644 --- a/include/arch/common/ffs.h +++ b/include/arch/common/ffs.h @@ -8,13 +8,14 @@ #ifndef ZEPHYR_INCLUDE_ARCH_COMMON_FFS_H_ #define ZEPHYR_INCLUDE_ARCH_COMMON_FFS_H_ +#ifndef _ASMLANGUAGE + +#include + #ifdef __cplusplus extern "C" { #endif -#ifndef _ASMLANGUAGE - -#include /** * * @brief find most significant bit set in a 32-bit word @@ -54,12 +55,10 @@ static ALWAYS_INLINE unsigned int find_lsb_set(u32_t op) return __builtin_ffs(op); } -#endif /* _ASMLANGUAGE */ - - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ #endif /* ZEPHYR_INCLUDE_ARCH_COMMON_FFS_H_ */ diff --git a/include/arch/common/sys_io.h b/include/arch/common/sys_io.h index e1e976726e67d..4ac806b7c1a4e 100644 --- a/include/arch/common/sys_io.h +++ b/include/arch/common/sys_io.h @@ -12,15 +12,14 @@ #ifndef ZEPHYR_INCLUDE_ARCH_COMMON_SYS_IO_H_ #define ZEPHYR_INCLUDE_ARCH_COMMON_SYS_IO_H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include #include +#ifdef __cplusplus +extern "C" { +#endif static ALWAYS_INLINE u8_t sys_read8(mem_addr_t addr) { @@ -140,10 +139,10 @@ static ALWAYS_INLINE return ret; } -#endif - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_INCLUDE_ARCH_COMMON_SYS_IO_H_ */ From eb8af3b24e28c3643589d0ebcf184d6ea813c5db Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 12:53:47 -0500 Subject: [PATCH 09/11] 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 b544602d54adb..f96670892fb80 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 fc46a5199c4a4..36ab8adecf4a0 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 b5600640dae47..fdfb47220eb99 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 7351bdd58a9d2..a2dcf5517d3d1 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 f0008b3e750b8..68739c3a98d3d 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_ */ From f0e44d5ab21a987df7262859d97ff207d9161f22 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 12:53:19 -0500 Subject: [PATCH 10/11] arch/nios2: 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. Remove extern "C" support from files that don't declare objects or functions. 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/nios2/include/kernel_arch_data.h | 26 ++++++++++++-------------- include/arch/nios2/arch.h | 13 ++++++------- include/arch/nios2/asm_inline_gcc.h | 8 -------- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/arch/nios2/include/kernel_arch_data.h b/arch/nios2/include/kernel_arch_data.h index ae2c7d694335b..6643103f37f53 100644 --- a/arch/nios2/include/kernel_arch_data.h +++ b/arch/nios2/include/kernel_arch_data.h @@ -21,23 +21,11 @@ #ifndef ZEPHYR_ARCH_NIOS2_INCLUDE_KERNEL_ARCH_DATA_H_ #define ZEPHYR_ARCH_NIOS2_INCLUDE_KERNEL_ARCH_DATA_H_ -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include #include -#ifndef _ASMLANGUAGE -#include -#include -#include -#include -#include -#endif - /* stacks */ #define STACK_ALIGN_SIZE 4 @@ -47,12 +35,22 @@ extern "C" { #ifndef _ASMLANGUAGE -extern K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE); +#include +#include +#include +#include +#include -#endif /* _ASMLANGUAGE */ +#ifdef __cplusplus +extern "C" { +#endif + +extern K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE); #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_ARCH_NIOS2_INCLUDE_KERNEL_ARCH_DATA_H_ */ diff --git a/include/arch/nios2/arch.h b/include/arch/nios2/arch.h index 82d82c8f37f4c..b59feba5a2587 100644 --- a/include/arch/nios2/arch.h +++ b/include/arch/nios2/arch.h @@ -22,10 +22,6 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif - #define STACK_ALIGN 4 #ifndef _ASMLANGUAGE @@ -33,6 +29,9 @@ extern "C" { #include #include +#ifdef __cplusplus +extern "C" { +#endif /** * Configure a static interrupt. @@ -210,10 +209,10 @@ static ALWAYS_INLINE void arch_nop(void) __asm__ volatile("nop"); } -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif -#endif +#endif /* _ASMLANGUAGE */ + +#endif /* ZEPHYR_INCLUDE_ARCH_NIOS2_ARCH_H_ */ diff --git a/include/arch/nios2/asm_inline_gcc.h b/include/arch/nios2/asm_inline_gcc.h index 8846e981de89e..9f4a428f1f350 100644 --- a/include/arch/nios2/asm_inline_gcc.h +++ b/include/arch/nios2/asm_inline_gcc.h @@ -7,10 +7,6 @@ #ifndef ZEPHYR_INCLUDE_ARCH_NIOS2_ASM_INLINE_GCC_H_ #define ZEPHYR_INCLUDE_ARCH_NIOS2_ASM_INLINE_GCC_H_ -#ifdef __cplusplus -extern "C" { -#endif - /* * The file must not be included directly * Include arch/cpu.h instead @@ -21,8 +17,4 @@ extern "C" { #include #endif /* _ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* _ASM_INLINE_GCC_PUBLIC_GCC_H */ From 4b3ebbad41af2d5bd72505f7f0c435dcbc4c4f98 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 12:52:11 -0500 Subject: [PATCH 11/11] arc: 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. Remove extern "C" support from files that don't declare objects or functions. In arch/arc/arch.h the extern "C" in the including context is left active during an include to avoid more complex restructuring. 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/arc/include/kernel_arch_data.h | 15 +++++++-------- arch/arc/include/kernel_arch_func.h | 12 ++++++------ arch/arc/include/kernel_arch_thread.h | 9 +++++++++ arch/arc/include/swap_macros.h | 8 -------- arch/arc/include/v2/cache.h | 8 ++++---- arch/arc/include/vector_table.h | 12 ++++++------ include/arch/arc/arch.h | 2 ++ include/arch/arc/v2/arc_connect.h | 10 +++++----- include/arch/arc/v2/asm_inline_gcc.h | 15 +++++++-------- include/arch/arc/v2/aux_regs.h | 8 -------- include/arch/arc/v2/ffs.h | 12 ++++++------ include/arch/arc/v2/sys_io.h | 13 +++++++------ soc/arc/snps_arc_iot/sysconf.h | 6 +++--- 13 files changed, 62 insertions(+), 68 deletions(-) diff --git a/arch/arc/include/kernel_arch_data.h b/arch/arc/include/kernel_arch_data.h index 65686ec376a7f..d2c76e0ff59fd 100644 --- a/arch/arc/include/kernel_arch_data.h +++ b/arch/arc/include/kernel_arch_data.h @@ -20,10 +20,6 @@ #ifndef ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_DATA_H_ #define ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_DATA_H_ -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include @@ -36,9 +32,11 @@ extern "C" { #include #include #include + +#ifdef __cplusplus +extern "C" { #endif -#ifndef _ASMLANGUAGE #ifdef CONFIG_ARC_HAS_SECURE struct _irq_stack_frame { u32_t lp_end; @@ -170,6 +168,10 @@ struct _callee_saved_stack { typedef struct _callee_saved_stack _callee_saved_stack_t; +#ifdef __cplusplus +} +#endif + #endif /* _ASMLANGUAGE */ /* stacks */ @@ -179,8 +181,5 @@ typedef struct _callee_saved_stack _callee_saved_stack_t; #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_ARC_INCLUDE_KERNEL_ARCH_DATA_H_ */ diff --git a/arch/arc/include/kernel_arch_func.h b/arch/arc/include/kernel_arch_func.h index 530a3423e4128..30648bd652233 100644 --- a/arch/arc/include/kernel_arch_func.h +++ b/arch/arc/include/kernel_arch_func.h @@ -20,10 +20,6 @@ #ifndef ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_FUNC_H_ #define ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_FUNC_H_ -#ifdef __cplusplus -extern "C" { -#endif - #if !defined(_ASMLANGUAGE) #ifdef CONFIG_CPU_ARCV2 @@ -31,6 +27,10 @@ extern "C" { #include #endif +#ifdef __cplusplus +extern "C" { +#endif + static ALWAYS_INLINE _cpu_t *z_arch_curr_cpu(void) { #ifdef CONFIG_SMP @@ -80,10 +80,10 @@ extern void z_arc_fatal_error(unsigned int reason, const z_arch_esf_t *esf); extern void z_arch_sched_ipi(void); -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_FUNC_H_ */ diff --git a/arch/arc/include/kernel_arch_thread.h b/arch/arc/include/kernel_arch_thread.h index 1288f176afb9a..7ab37ae50fb4d 100644 --- a/arch/arc/include/kernel_arch_thread.h +++ b/arch/arc/include/kernel_arch_thread.h @@ -31,6 +31,10 @@ #ifndef _ASMLANGUAGE #include +#ifdef __cplusplus +extern "C" { +#endif + struct _callee_saved { u32_t sp; /* r28 */ }; @@ -60,6 +64,11 @@ struct _thread_arch { typedef struct _thread_arch _thread_arch_t; +#ifdef __cplusplus +} +#endif + #endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_THREAD_H_ */ diff --git a/arch/arc/include/swap_macros.h b/arch/arc/include/swap_macros.h index b7eab4dab909d..b319446f7f0d1 100644 --- a/arch/arc/include/swap_macros.h +++ b/arch/arc/include/swap_macros.h @@ -14,10 +14,6 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif - #ifdef _ASMLANGUAGE /* entering this macro, current is in r2 */ @@ -338,8 +334,4 @@ extern "C" { #endif /* _ASMLANGUAGE */ -#ifdef __cplusplus -} -#endif - #endif /* ZEPHYR_ARCH_ARC_INCLUDE_SWAP_MACROS_H_ */ diff --git a/arch/arc/include/v2/cache.h b/arch/arc/include/v2/cache.h index 59b679a4450e1..747a08932fe85 100644 --- a/arch/arc/include/v2/cache.h +++ b/arch/arc/include/v2/cache.h @@ -17,12 +17,12 @@ #include +#ifndef _ASMLANGUAGE + #ifdef __cplusplus extern "C" { #endif -#ifndef _ASMLANGUAGE - /* i-cache defines for IC_CTRL register */ #define IC_CACHE_ENABLE 0x00 #define IC_CACHE_DISABLE 0x01 @@ -50,10 +50,10 @@ static ALWAYS_INLINE void z_icache_setup(void) } } -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_ARCH_ARC_INCLUDE_V2_CACHE_H_ */ diff --git a/arch/arc/include/vector_table.h b/arch/arc/include/vector_table.h index cfc30c281d2db..38ceb16053e39 100644 --- a/arch/arc/include/vector_table.h +++ b/arch/arc/include/vector_table.h @@ -21,10 +21,6 @@ #ifndef ZEPHYR_ARCH_ARC_INCLUDE_VECTOR_TABLE_H_ #define ZEPHYR_ARCH_ARC_INCLUDE_VECTOR_TABLE_H_ -#ifdef __cplusplus -extern "C" { -#endif - #define EXC_EV_TRAP 0x9 #ifdef _ASMLANGUAGE @@ -55,6 +51,10 @@ GTEXT(_isr_wrapper) #else +#ifdef __cplusplus +extern "C" { +#endif + extern void __reset(void); extern void __memory_error(void); extern void __instruction_error(void); @@ -70,10 +70,10 @@ extern void __ev_div_zero(void); extern void __ev_dc_error(void); extern void __ev_maligned(void); -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_ARCH_ARC_INCLUDE_VECTOR_TABLE_H_ */ diff --git a/include/arch/arc/arch.h b/include/arch/arc/arch.h index ed55933eb05da..a5ace88be4e55 100644 --- a/include/arch/arc/arch.h +++ b/include/arch/arc/arch.h @@ -160,6 +160,8 @@ extern "C" { #ifdef CONFIG_ARC_MPU #ifndef _ASMLANGUAGE + +/* Legacy case: retain containing extern "C" with C++ */ #include #define K_MEM_PARTITION_P_NA_U_NA AUX_MPU_ATTR_N diff --git a/include/arch/arc/v2/arc_connect.h b/include/arch/arc/v2/arc_connect.h index 8e7e274ed1ef5..e248b4bbd98d0 100644 --- a/include/arch/arc/v2/arc_connect.h +++ b/include/arch/arc/v2/arc_connect.h @@ -14,14 +14,13 @@ #ifndef ZEPHYR_INCLUDE_ARCH_ARC_V2_ARC_CONNECT_H_ #define ZEPHYR_INCLUDE_ARCH_ARC_V2_ARC_CONNECT_H_ +#ifndef _ASMLANGUAGE +#include #ifdef __cplusplus extern "C" { #endif -#ifndef _ASMLANGUAGE -#include - #define _ARC_V2_CONNECT_BCR 0x0d0 #define _ARC_V2_CONNECT_IDU_BCR 0x0d5 #define _ARC_V2_CONNECT_GFRC_BCR 0x0d6 @@ -227,9 +226,10 @@ extern void z_arc_connect_idu_set_mask(u32_t irq_num, u32_t mask); extern u32_t z_arc_connect_idu_read_mask(u32_t irq_num); extern u32_t z_arc_connect_idu_check_first(u32_t irq_num); -#endif - #ifdef __cplusplus } #endif + +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_INCLUDE_ARCH_ARC_V2_ARC_CONNECT_H_ */ diff --git a/include/arch/arc/v2/asm_inline_gcc.h b/include/arch/arc/v2/asm_inline_gcc.h index 90dd1a0b497e6..99f8a004bcd26 100644 --- a/include/arch/arc/v2/asm_inline_gcc.h +++ b/include/arch/arc/v2/asm_inline_gcc.h @@ -9,26 +9,25 @@ #ifndef ZEPHYR_INCLUDE_ARCH_ARC_V2_ASM_INLINE_GCC_H_ #define ZEPHYR_INCLUDE_ARCH_ARC_V2_ASM_INLINE_GCC_H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include #include +#ifdef __cplusplus +extern "C" { +#endif + + /** * @brief read timestamp register (CPU frequency) */ extern u64_t z_tsc_read(void); - - -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_INCLUDE_ARCH_ARC_V2_ASM_INLINE_GCC_H_ */ diff --git a/include/arch/arc/v2/aux_regs.h b/include/arch/arc/v2/aux_regs.h index 19f291370e093..3e1a0dfceb579 100644 --- a/include/arch/arc/v2/aux_regs.h +++ b/include/arch/arc/v2/aux_regs.h @@ -15,10 +15,6 @@ #ifndef ZEPHYR_INCLUDE_ARCH_ARC_V2_AUX_REGS_H_ #define ZEPHYR_INCLUDE_ARCH_ARC_V2_AUX_REGS_H_ -#ifdef __cplusplus -extern "C" { -#endif - #define _ARC_V2_LP_START 0x002 #define _ARC_V2_LP_END 0x003 #define _ARC_V2_IDENTITY 0x004 @@ -201,8 +197,4 @@ extern "C" { __ret; \ }) -#ifdef __cplusplus -} -#endif - #endif /* ZEPHYR_INCLUDE_ARCH_ARC_V2_AUX_REGS_H_ */ diff --git a/include/arch/arc/v2/ffs.h b/include/arch/arc/v2/ffs.h index 23607aa5e3a58..9b4d30a94da8b 100644 --- a/include/arch/arc/v2/ffs.h +++ b/include/arch/arc/v2/ffs.h @@ -14,14 +14,14 @@ #ifndef ZEPHYR_INCLUDE_ARCH_ARC_V2_FFS_H_ #define ZEPHYR_INCLUDE_ARCH_ARC_V2_FFS_H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include +#ifdef __cplusplus +extern "C" { +#endif + /** * * @brief find most significant bit set in a 32-bit word @@ -81,10 +81,10 @@ static ALWAYS_INLINE unsigned int find_lsb_set(u32_t op) } #endif -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_INCLUDE_ARCH_ARC_V2_FFS_H_ */ diff --git a/include/arch/arc/v2/sys_io.h b/include/arch/arc/v2/sys_io.h index da73b31ef3a7b..1cf96259eea10 100644 --- a/include/arch/arc/v2/sys_io.h +++ b/include/arch/arc/v2/sys_io.h @@ -7,10 +7,6 @@ #ifndef ZEPHYR_INCLUDE_ARCH_ARC_V2_SYS_IO_H_ #define ZEPHYR_INCLUDE_ARCH_ARC_V2_SYS_IO_H_ -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _ASMLANGUAGE #include @@ -18,6 +14,11 @@ extern "C" { #include #include + +#ifdef __cplusplus +extern "C" { +#endif + /* Implementation of sys_io.h's documented functions */ static ALWAYS_INLINE @@ -300,10 +301,10 @@ static ALWAYS_INLINE return ret; } -#endif /* _ASMLANGUAGE */ - #ifdef __cplusplus } #endif +#endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_INCLUDE_ARCH_ARC_V2_SYS_IO_H_ */ diff --git a/soc/arc/snps_arc_iot/sysconf.h b/soc/arc/snps_arc_iot/sysconf.h index 728c52f551a6e..aebe39fddcd37 100644 --- a/soc/arc/snps_arc_iot/sysconf.h +++ b/soc/arc/snps_arc_iot/sysconf.h @@ -8,12 +8,12 @@ #ifndef _ARC_IOT_SYSCONF_H_ #define _ARC_IOT_SYSCONF_H_ +#include + #ifdef __cplusplus extern "C" { #endif -#include - typedef struct sysconf_reg { volatile uint32_t reserved1; /* 0x0 */ volatile uint32_t AHBCLKDIV; /* AHB clock divisor */ @@ -164,4 +164,4 @@ extern void arc_iot_eflash_clk_div(uint8_t div); } #endif -#endif /* _ARC_IOT_SYSCONF_H_ */ \ No newline at end of file +#endif /* _ARC_IOT_SYSCONF_H_ */