Skip to content

Commit 817f527

Browse files
pabigotioannisg
authored andcommitted
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 <[email protected]>
1 parent c315475 commit 817f527

File tree

5 files changed

+28
-32
lines changed

5 files changed

+28
-32
lines changed

arch/xtensa/include/kernel_arch_data.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,26 @@
2020
#ifndef ZEPHYR_ARCH_XTENSA_INCLUDE_KERNEL_ARCH_DATA_H_
2121
#define ZEPHYR_ARCH_XTENSA_INCLUDE_KERNEL_ARCH_DATA_H_
2222

23-
#ifdef __cplusplus
24-
extern "C" {
25-
#endif
26-
2723
#include <toolchain.h>
2824
#include <linker/sections.h>
2925
#include <arch/cpu.h>
3026
#include <kernel_arch_thread.h>
3127

28+
/* stacks */
29+
#define STACK_ROUND_UP(x) ROUND_UP(x, STACK_ALIGN_SIZE)
30+
#define STACK_ROUND_DOWN(x) ROUND_DOWN(x, STACK_ALIGN_SIZE)
31+
3232
#if !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__)
3333
#include <kernel.h> /* public kernel API */
3434
#include <kernel_internal.h>
3535
#include <zephyr/types.h>
3636
#include <sys/dlist.h>
3737
#include <sys/util.h>
3838

39+
#ifdef __cplusplus
40+
extern "C" {
41+
#endif
42+
3943
/* Bitmask definitions for the struct k_thread->flags bit field */
4044

4145
/* executing context is interrupt handler */
@@ -47,20 +51,15 @@ extern "C" {
4751

4852
typedef struct __esf __esf_t;
4953

50-
#endif /*! _ASMLANGUAGE && ! __ASSEMBLER__ */
51-
5254
#ifdef CONFIG_USE_SWITCH
5355
void xtensa_switch(void *switch_to, void **switched_from);
5456
#define z_arch_switch xtensa_switch
5557
#endif
5658

57-
/* stacks */
58-
#define STACK_ROUND_UP(x) ROUND_UP(x, STACK_ALIGN_SIZE)
59-
#define STACK_ROUND_DOWN(x) ROUND_DOWN(x, STACK_ALIGN_SIZE)
60-
6159
#ifdef __cplusplus
6260
}
6361
#endif
6462

65-
#endif /* ZEPHYR_ARCH_XTENSA_INCLUDE_KERNEL_ARCH_DATA_H_ */
63+
#endif /*! _ASMLANGUAGE && ! __ASSEMBLER__ */
6664

65+
#endif /* ZEPHYR_ARCH_XTENSA_INCLUDE_KERNEL_ARCH_DATA_H_ */

arch/xtensa/include/kernel_arch_func.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#ifndef _ASMLANGUAGE
1313
#include <string.h>
1414
#include <stdbool.h>
15+
#include <stddef.h> /* For size_t */
1516

1617
#ifdef __cplusplus
1718
extern "C" {
@@ -119,8 +120,6 @@ z_set_thread_return_value(struct k_thread *thread, unsigned int value)
119120

120121
extern void k_cpu_atomic_idle(unsigned int key);
121122

122-
#include <stddef.h> /* For size_t */
123-
124123
#ifdef __cplusplus
125124
}
126125
#endif

arch/xtensa/include/xtensa_config.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
#ifndef ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_CONFIG_H_
77
#define ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_CONFIG_H_
88

9-
#ifdef __cplusplus
10-
extern "C" {
11-
#endif
12-
139
#include <xtensa/hal.h>
1410
#include <xtensa/config/core.h>
1511
#include <xtensa/config/system.h> /* required for XSHAL_CLIB */
@@ -133,9 +129,4 @@ extern "C" {
133129
#define XT_STACK_EXTRA_CLIB (XT_XTRA_SIZE + XT_CLIB_CONTEXT_AREA_SIZE)
134130

135131

136-
#ifdef __cplusplus
137-
}
138-
#endif
139-
140132
#endif /* ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_CONFIG_H_ */
141-

arch/xtensa/include/xtensa_context.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919
#ifndef ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_CONTEXT_H_
2020
#define ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_CONTEXT_H_
2121

22-
#ifdef __ASSEMBLER__
23-
#include <xtensa/coreasm.h>
24-
#endif
25-
2622
#include <xtensa/config/tie.h>
2723
#include <xtensa/corebits.h>
2824
#include <xtensa/config/system.h>
2925
#include <xtensa/xtruntime-frames.h>
3026

27+
#ifdef __ASSEMBLER__
28+
#include <xtensa/coreasm.h>
29+
#else /* __ASSEMBLER__ */
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
#endif /* __ASSEMBLER__ */
3134

3235
/* Align a value up to nearest n-byte boundary, where n is a power of 2. */
3336
#define ALIGNUP(n, val) (((val) + (n)-1) & -(n))
@@ -310,8 +313,11 @@ ret
310313
#define RET(sz) retw
311314
#define RET0 retw
312315
#endif /* __XTENSA_CALL0_ABI__ */
316+
#else /* __ASSEMBLER__ */
317+
#ifdef __cplusplus
318+
}
319+
#endif
313320
#endif /* __ASSEMBLER__ */
314321

315322

316323
#endif /* ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_CONTEXT_H_ */
317-

include/arch/xtensa/arch.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515

1616
#include <irq.h>
1717

18-
#ifdef __cplusplus
19-
extern "C" {
20-
#endif
21-
2218
#include <generated_dts_board.h>
2319
#if !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__)
2420
#include <arch/common/sys_io.h>
@@ -36,6 +32,10 @@ extern "C" {
3632

3733
#include <arch/xtensa/exc.h>
3834

35+
#ifdef __cplusplus
36+
extern "C" {
37+
#endif
38+
3939
/* internal routine documented in C file, needed by IRQ_CONNECT() macro */
4040
extern void z_irq_priority_set(u32_t irq, u32_t prio, u32_t flags);
4141

@@ -95,9 +95,10 @@ static ALWAYS_INLINE void arch_nop(void)
9595
__asm__ volatile("nop");
9696
}
9797

98-
#endif /* !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) */
9998
#ifdef __cplusplus
10099
}
101100
#endif
102101

102+
#endif /* !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) */
103+
103104
#endif /* ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_H_ */

0 commit comments

Comments
 (0)