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 <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2019-08-12 12:52:55 -05:00 committed by Ioannis Glaropoulos
commit ce3f07954a
13 changed files with 79 additions and 80 deletions

View file

@ -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 <toolchain.h>
@ -57,14 +53,18 @@ GTEXT(__reserved)
GTEXT(_PrepC)
GTEXT(_isr_wrapper)
#else
#else /* _ASMLANGUAGE */
#ifdef __cplusplus
extern "C" {
#endif
extern void *_vector_table[];
#endif /* _ASMLANGUAGE */
#ifdef __cplusplus
}
#endif
#endif /* _ASMLANGUAGE */
#endif /* ZEPHYR_ARCH_ARM_CORE_CORTEX_M_VECTOR_TABLE_H_ */

View file

@ -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_ */

View file

@ -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 <arm_cmse.h>
#include <stdint.h>
#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_ */

View file

@ -16,10 +16,6 @@
#include <arch/cpu.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _ASMLANGUAGE
/* nothing */
@ -30,6 +26,10 @@ extern "C" {
#include <arch/arm/exc.h>
#include <irq_offload.h>
#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_ */

View file

@ -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 <arch/arm/cortex_m/cmsis.h>
#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_ */

View file

@ -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 <arm_cmse.h>
#include <zephyr/types.h>
#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_ */

View file

@ -16,10 +16,6 @@
#include <arch/cpu.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _ASMLANGUAGE
/* nothing */
@ -28,6 +24,10 @@ extern "C" {
#include <irq_offload.h>
#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_ */

View file

@ -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 <toolchain.h>
#include <linker/sections.h>
#include <arch/cpu.h>
#include <kernel_arch_thread.h>
#ifndef _ASMLANGUAGE
#include <kernel.h>
#include <kernel_internal.h>
#include <zephyr/types.h>
#include <sys/dlist.h>
#include <sys/atomic.h>
#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 <kernel.h>
#include <kernel_internal.h>
#include <zephyr/types.h>
#include <sys/dlist.h>
#include <sys/atomic.h>
#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_ */

View file

@ -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 <arch/arm/cortex_m/mpu/arm_mpu.h>

View file

@ -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 <arch/arm/exc.h>
#include <irq.h>
#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_ */

View file

@ -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 <core_cm0.h>
#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_ */

View file

@ -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 <zephyr/types.h>
#include <sys/sys_io.h>
#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_ */

View file

@ -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 <zephyr/types.h>
#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_ */