Skip to content

Commit 1465f6d

Browse files
Fix module-import-in-extern-c compiler error
This fixes a compiler error when building C++ projects that use the 'modules' C++ language feature consume Mbed TLS. The specific error is module-import-in-extern-c, which occurs when `#include`s occur within `extern C` blocks. ``` $ clang-17 -std=c++20 -fmodules -Itf-psa-crypto/include -Itf-psa-crypto/drivers/builtin/include -o sample sample.cpp In file included from sample.cpp:8: In file included from tf-psa-crypto/drivers/builtin/include/mbedtls/private/chachapoly.h:44: tf-psa-crypto/drivers/builtin/include/mbedtls/private/chacha20.h:26:1: error: import of C++ module '_Builtin_stdint' appears within extern "C" language linkage specification [-Wmodule-import-in-extern-c] 26 | #include <stdint.h> | ^ tf-psa-crypto/drivers/builtin/include/mbedtls/private/chachapoly.h:35:1: note: extern "C" language linkage specification begins here 35 | extern "C" { | ^ 1 error generated. ``` This seems to primarily be an issue with clang. See https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fmodules Signed-off-by: zacharykeyessonos <[email protected]>
1 parent e185d7f commit 1465f6d

27 files changed

+161
-108
lines changed

include/mbedtls/aes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@
4949
/** Invalid input data. */
5050
#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
5151

52-
#ifdef __cplusplus
53-
extern "C" {
54-
#endif
55-
5652
#if !defined(MBEDTLS_AES_ALT)
5753
// Regular implementation
5854
//
@@ -96,6 +92,10 @@ typedef struct mbedtls_aes_xts_context {
9692
#include "aes_alt.h"
9793
#endif /* MBEDTLS_AES_ALT */
9894

95+
#ifdef __cplusplus
96+
extern "C" {
97+
#endif
98+
9999
/**
100100
* \brief This function initializes the specified AES context.
101101
*

include/mbedtls/aria.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838
/** Invalid data input length. */
3939
#define MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH -0x005E
4040

41-
#ifdef __cplusplus
42-
extern "C" {
43-
#endif
44-
4541
#if !defined(MBEDTLS_ARIA_ALT)
4642
// Regular implementation
4743
//
@@ -60,6 +56,10 @@ mbedtls_aria_context;
6056
#include "aria_alt.h"
6157
#endif /* MBEDTLS_ARIA_ALT */
6258

59+
#ifdef __cplusplus
60+
extern "C" {
61+
#endif
62+
6363
/**
6464
* \brief This function initializes the specified ARIA context.
6565
*

include/mbedtls/camellia.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
/** Invalid data input length. */
2828
#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026
2929

30-
#ifdef __cplusplus
31-
extern "C" {
32-
#endif
33-
3430
#if !defined(MBEDTLS_CAMELLIA_ALT)
3531
// Regular implementation
3632
//
@@ -48,6 +44,10 @@ mbedtls_camellia_context;
4844
#include "camellia_alt.h"
4945
#endif /* MBEDTLS_CAMELLIA_ALT */
5046

47+
#ifdef __cplusplus
48+
extern "C" {
49+
#endif
50+
5151
/**
5252
* \brief Initialize a CAMELLIA context.
5353
*

include/mbedtls/ccm.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@
5454
/** Authenticated decryption failed. */
5555
#define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F
5656

57-
#ifdef __cplusplus
58-
extern "C" {
59-
#endif
60-
6157
#if !defined(MBEDTLS_CCM_ALT)
6258
// Regular implementation
6359
//
@@ -98,6 +94,10 @@ mbedtls_ccm_context;
9894
#include "ccm_alt.h"
9995
#endif /* MBEDTLS_CCM_ALT */
10096

97+
#ifdef __cplusplus
98+
extern "C" {
99+
#endif
100+
101101
/**
102102
* \brief This function initializes the specified CCM context,
103103
* to make references valid, and prepare the context

include/mbedtls/chacha20.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
/** Invalid input parameter(s). */
3030
#define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051
3131

32-
#ifdef __cplusplus
33-
extern "C" {
34-
#endif
35-
3632
#if !defined(MBEDTLS_CHACHA20_ALT)
3733

3834
typedef struct mbedtls_chacha20_context {
@@ -46,6 +42,10 @@ mbedtls_chacha20_context;
4642
#include "chacha20_alt.h"
4743
#endif /* MBEDTLS_CHACHA20_ALT */
4844

45+
#ifdef __cplusplus
46+
extern "C" {
47+
#endif
48+
4949
/**
5050
* \brief This function initializes the specified ChaCha20 context.
5151
*

include/mbedtls/chachapoly.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
/** Authenticated decryption failed: data was not authentic. */
3232
#define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056
3333

34-
#ifdef __cplusplus
35-
extern "C" {
36-
#endif
37-
3834
typedef enum {
3935
MBEDTLS_CHACHAPOLY_ENCRYPT, /**< The mode value for performing encryption. */
4036
MBEDTLS_CHACHAPOLY_DECRYPT /**< The mode value for performing decryption. */
@@ -59,6 +55,10 @@ mbedtls_chachapoly_context;
5955
#include "chachapoly_alt.h"
6056
#endif /* !MBEDTLS_CHACHAPOLY_ALT */
6157

58+
#ifdef __cplusplus
59+
extern "C" {
60+
#endif
61+
6262
/**
6363
* \brief This function initializes the specified ChaCha20-Poly1305 context.
6464
*

include/mbedtls/cmac.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020

2121
#include "mbedtls/cipher.h"
2222

23-
#ifdef __cplusplus
24-
extern "C" {
25-
#endif
26-
2723
#define MBEDTLS_AES_BLOCK_SIZE 16
2824
#define MBEDTLS_DES3_BLOCK_SIZE 8
2925

@@ -72,6 +68,10 @@ struct mbedtls_cmac_context_t {
7268
#include "cmac_alt.h"
7369
#endif /* !MBEDTLS_CMAC_ALT */
7470

71+
#ifdef __cplusplus
72+
extern "C" {
73+
#endif
74+
7575
/**
7676
* \brief This function starts a new CMAC computation
7777
* by setting the CMAC key, and preparing to authenticate

include/mbedtls/des.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030

3131
#define MBEDTLS_DES_KEY_SIZE 8
3232

33-
#ifdef __cplusplus
34-
extern "C" {
35-
#endif
36-
3733
#if !defined(MBEDTLS_DES_ALT)
3834
// Regular implementation
3935
//
@@ -66,6 +62,10 @@ mbedtls_des3_context;
6662
#include "des_alt.h"
6763
#endif /* MBEDTLS_DES_ALT */
6864

65+
#ifdef __cplusplus
66+
extern "C" {
67+
#endif
68+
6969
/**
7070
* \brief Initialize DES context
7171
*

include/mbedtls/dhm.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ typedef enum {
8989
MBEDTLS_DHM_PARAM_K, /*!< The shared secret = \c G^(XY) mod \c P. */
9090
} mbedtls_dhm_parameter;
9191

92-
#ifdef __cplusplus
93-
extern "C" {
94-
#endif
95-
9692
#if !defined(MBEDTLS_DHM_ALT)
9793

9894
/**
@@ -116,6 +112,10 @@ mbedtls_dhm_context;
116112
#include "dhm_alt.h"
117113
#endif /* MBEDTLS_DHM_ALT */
118114

115+
#ifdef __cplusplus
116+
extern "C" {
117+
#endif
118+
119119
/**
120120
* \brief This function initializes the DHM context.
121121
*

include/mbedtls/ecjpake.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
#include "mbedtls/ecp.h"
3333
#include "mbedtls/md.h"
3434

35-
#ifdef __cplusplus
36-
extern "C" {
37-
#endif
38-
3935
/**
4036
* Roles in the EC J-PAKE exchange
4137
*/
@@ -79,6 +75,10 @@ typedef struct mbedtls_ecjpake_context {
7975
#include "ecjpake_alt.h"
8076
#endif /* MBEDTLS_ECJPAKE_ALT */
8177

78+
#ifdef __cplusplus
79+
extern "C" {
80+
#endif
81+
8282
/**
8383
* \brief Initialize an ECJPAKE context.
8484
*

0 commit comments

Comments
 (0)