Skip to content

Commit 43fc6a7

Browse files
pabigotioannisg
authored andcommitted
arch/riscv: 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 <[email protected]>
1 parent b81d59d commit 43fc6a7

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

arch/riscv/include/kernel_arch_data.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
#ifndef ZEPHYR_ARCH_RISCV_INCLUDE_KERNEL_ARCH_DATA_H_
1616
#define ZEPHYR_ARCH_RISCV_INCLUDE_KERNEL_ARCH_DATA_H_
1717

18-
#ifdef __cplusplus
19-
extern "C" {
20-
#endif
21-
2218
#include <toolchain.h>
2319
#include <linker/sections.h>
2420
#include <arch/cpu.h>
@@ -31,8 +27,16 @@ extern "C" {
3127
#include <sys/dlist.h>
3228
#include <kernel_internal.h>
3329

30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
3434
extern K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE);
3535

36+
#ifdef __cplusplus
37+
}
38+
#endif
39+
3640
#endif /* _ASMLANGUAGE */
3741

3842
#endif /* ZEPHYR_ARCH_RISCV_INCLUDE_KERNEL_ARCH_DATA_H_ */

include/arch/riscv/arch.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
#include <soc.h>
2525
#include <generated_dts_board.h>
2626

27-
#ifdef __cplusplus
28-
extern "C" {
29-
#endif
30-
3127
/* stacks, for RISCV architecture stack should be 16byte-aligned */
3228
#define STACK_ALIGN 16
3329

@@ -46,6 +42,10 @@ extern "C" {
4642
#ifndef _ASMLANGUAGE
4743
#include <sys/util.h>
4844

45+
#ifdef __cplusplus
46+
extern "C" {
47+
#endif
48+
4949
#define STACK_ROUND_UP(x) ROUND_UP(x, STACK_ALIGN)
5050
#define STACK_ROUND_DOWN(x) ROUND_DOWN(x, STACK_ALIGN)
5151

@@ -157,14 +157,15 @@ static ALWAYS_INLINE void arch_nop(void)
157157
extern u32_t z_timer_cycle_get_32(void);
158158
#define z_arch_k_cycle_get_32() z_timer_cycle_get_32()
159159

160+
#ifdef __cplusplus
161+
}
162+
#endif
163+
160164
#endif /*_ASMLANGUAGE */
161165

162166
#if defined(CONFIG_SOC_FAMILY_RISCV_PRIVILEGE)
163167
#include <arch/riscv/riscv-privilege/asm_inline.h>
164168
#endif
165169

166-
#ifdef __cplusplus
167-
}
168-
#endif
169170

170171
#endif

include/arch/riscv/exp.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
#ifndef ZEPHYR_INCLUDE_ARCH_RISCV_EXP_H_
1616
#define ZEPHYR_INCLUDE_ARCH_RISCV_EXP_H_
1717

18-
#ifdef __cplusplus
19-
extern "C" {
20-
#endif
21-
2218
#ifndef _ASMLANGUAGE
2319
#include <zephyr/types.h>
2420
#include <toolchain.h>
@@ -27,6 +23,10 @@ extern "C" {
2723
#include <soc_context.h>
2824
#endif
2925

26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
3030
/*
3131
* The name of the structure which contains soc-specific state, if
3232
* any, as well as the soc_esf_t typedef below, are part of the RISC-V
@@ -75,10 +75,11 @@ typedef struct __esf z_arch_esf_t;
7575
#ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE
7676
typedef struct soc_esf soc_esf_t;
7777
#endif
78-
#endif /* _ASMLANGUAGE */
7978

8079
#ifdef __cplusplus
8180
}
8281
#endif
8382

83+
#endif /* _ASMLANGUAGE */
84+
8485
#endif /* ZEPHYR_INCLUDE_ARCH_RISCV_EXP_H_ */

include/arch/riscv/riscv-privilege/asm_inline_gcc.h

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

10-
#ifdef __cplusplus
11-
extern "C" {
12-
#endif
13-
1410
/*
1511
* The file must not be included directly
1612
* Include arch/cpu.h instead
@@ -21,11 +17,6 @@ extern "C" {
2117

2218
#include <toolchain.h>
2319

24-
2520
#endif /* _ASMLANGUAGE */
2621

27-
#ifdef __cplusplus
28-
}
29-
#endif
30-
3122
#endif /* ZEPHYR_INCLUDE_ARCH_RISCV_RISCV_PRIVILEGE_ASM_INLINE_GCC_H_ */

0 commit comments

Comments
 (0)