Skip to content

Commit 2b6f65a

Browse files
committed
build_system/xfa: change API to fix alignment
This changes the API of xfa from XFA(array_name, prio) type element_name = INITIALIZER; to XFA(type, array_name, prio) element_name = INITIALIZER; this allows forcing natural alignment of the type, fixing failing tests on `native64`.
1 parent 2839224 commit 2b6f65a

File tree

22 files changed

+63
-60
lines changed

22 files changed

+63
-60
lines changed

core/lib/include/xfa.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ _Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
4343
*
4444
* @internal
4545
*/
46-
#define _XFA(name, prio) \
46+
#define _XFA(type, name, prio) \
4747
NO_SANITIZE_ARRAY \
48-
__attribute__((used, section(".xfa." #name "." #prio)))
48+
__attribute__((used, section(".xfa." #name "." #prio))) _Alignas(type) type
4949

5050
/**
5151
* @brief helper macro for other XFA_* macros
5252
*
5353
* @internal
5454
*/
55-
#define _XFA_CONST(name, prio) \
55+
#define _XFA_CONST(type, name, prio) \
5656
NO_SANITIZE_ARRAY \
57-
__attribute__((used, section(".roxfa." #name "." #prio)))
57+
__attribute__((used, section(".roxfa." #name "." #prio))) _Alignas(type) type
5858

5959
/**
6060
* @brief Define a read-only cross-file array
@@ -73,8 +73,8 @@ _Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
7373
#define XFA_INIT_CONST(type, name) \
7474
_Pragma("GCC diagnostic push") \
7575
_Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
76-
_XFA_CONST(name, 0_) type name [0] = {}; \
77-
_XFA_CONST(name, 9_) type name ## _end [0] = {}; \
76+
_XFA_CONST(type, name, 0_) name [0] = {}; \
77+
_XFA_CONST(type, name, 9_) name ## _end [0] = {}; \
7878
_Pragma("GCC diagnostic pop") \
7979
extern const unsigned __xfa_dummy
8080

@@ -95,8 +95,8 @@ _Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
9595
#define XFA_INIT(type, name) \
9696
_Pragma("GCC diagnostic push") \
9797
_Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
98-
_XFA(name, 0_) type name [0] = {}; \
99-
_XFA(name, 9_) type name ## _end [0] = {}; \
98+
_XFA(type, name, 0_) name [0] = {}; \
99+
_XFA(type, name, 9_) name ## _end [0] = {}; \
100100
_Pragma("GCC diagnostic pop") \
101101
extern const unsigned __xfa_dummy
102102

@@ -136,12 +136,13 @@ _Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
136136
*
137137
* Add this to the type in a variable definition, e.g.:
138138
*
139-
* XFA(driver_params, 0) driver_params_t _onboard = { .pin=42 };
139+
* XFA(driver_params_t, driver_params, 0) _onboard = { .pin=42 };
140140
*
141+
* @param[in] type type of the xfa elements
141142
* @param[in] xfa_name name of the xfa
142143
* @param[in] prio priority within the xfa
143144
*/
144-
#define XFA(xfa_name, prio) _XFA(xfa_name, 5_ ## prio)
145+
#define XFA(type, xfa_name, prio) _XFA(type, xfa_name, 5_ ## prio)
145146

146147
/**
147148
* @brief Define variable in read-only cross-file array
@@ -150,12 +151,13 @@ _Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
150151
*
151152
* Add this to the type in a variable definition, e.g.:
152153
*
153-
* XFA(driver_params, 0) driver_params_t _onboard = { .pin=42 };
154+
* XFA(driver_params_t, driver_params, 0) _onboard = { .pin=42 };
154155
*
156+
* @param[in] type type of the xfa elements
155157
* @param[in] xfa_name name of the xfa
156158
* @param[in] prio priority within the xfa
157159
*/
158-
#define XFA_CONST(xfa_name, prio) _XFA_CONST(xfa_name, 5_ ## prio)
160+
#define XFA_CONST(type, xfa_name, prio) _XFA_CONST(type, xfa_name, 5_ ## prio)
159161

160162
/**
161163
* @brief Add a pointer to cross-file array
@@ -174,8 +176,8 @@ _Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
174176
* @param[in] entry pointer variable to add to xfa
175177
*/
176178
#define XFA_ADD_PTR(xfa_name, prio, name, entry) \
177-
_XFA_CONST(xfa_name, 5_ ## prio) \
178-
__typeof__(entry) xfa_name ## _ ## prio ## _ ## name = entry
179+
_XFA_CONST(__typeof__(entry), xfa_name, 5_ ## prio) \
180+
xfa_name ## _ ## prio ## _ ## name = entry
179181

180182
/**
181183
* @brief Calculate number of entries in cross-file array

cpu/esp32/periph/sdmmc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ static_assert(SDMMC_CONFIG_NUMOF == ARRAY_SIZE(_sdmmc_devs),
111111
static_assert(SDMMC_CONFIG_NUMOF <= SOC_SDMMC_NUM_SLOTS,
112112
"SDMMC_CONFIG_NUMOF is greater than the supported number of slots");
113113

114-
XFA_CONST(sdmmc_devs, 0) sdmmc_dev_t * const _sdmmc_0 = (sdmmc_dev_t * const)&_sdmmc_devs[0];
114+
XFA_CONST(sdmmc_dev_t * const, sdmmc_devs, 0) _sdmmc_0 = (sdmmc_dev_t * const)&_sdmmc_devs[0];
115115
#if SDMMC_CONFIG_NUMOF > 1
116-
XFA_CONST(sdmmc_devs, 0) sdmmc_dev_t * const _sdmmc_1 = (sdmmc_dev_t * const)&_sdmmc_devs[1];
116+
XFA_CONST(sdmmc_dev_t * const, sdmmc_devs, 0) _sdmmc_1 = (sdmmc_dev_t * const)&_sdmmc_devs[1];
117117
#endif
118118

119119
/* forward declaration of internal functions */

cpu/stm32/periph/sdmmc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ static_assert(SDMMC_CONFIG_NUMOF < 3, "MCU supports only 2 SDIO/SD/MMC interface
239239
static_assert(SDMMC_CONFIG_NUMOF < 2, "MCU supports only 1 SDIO/SD/MMC interface");
240240
#endif
241241

242-
XFA_CONST(sdmmc_devs, 0) sdmmc_dev_t * const _sdmmc_1 = (sdmmc_dev_t * const)&_sdmmc_devs[0];
242+
XFA_CONST(sdmmc_dev_t * const, sdmmc_devs, 0) _sdmmc_1 = (sdmmc_dev_t * const)&_sdmmc_devs[0];
243243
#if SDMMC_CONFIG_NUMOF > 1
244-
XFA_CONST(sdmmc_devs, 0) sdmmc_dev_t * const _sdmmc_2 = (sdmmc_dev_t * const)&_sdmmc_devs[1];
244+
XFA_CONST(sdmmc_dev_t * const, sdmmc_devs, 0) _sdmmc_2 = (sdmmc_dev_t * const)&_sdmmc_devs[1];
245245
#endif
246246

247247
static inline bool _use_dma(const sdmmc_conf_t *conf)

drivers/include/mtd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ mtd_dev_t * const mtd_dev_xfa[];
164164
* @param idx Priority of the MTD device pointer within the XFA
165165
*/
166166
#define MTD_XFA_ADD(dev, idx) \
167-
XFA_CONST(mtd_dev_xfa, idx) mtd_dev_t *mtd ## idx = (mtd_dev_t *)&(dev)
167+
XFA_CONST(mtd_dev_t, mtd_dev_xfa, idx) *mtd ## idx = (mtd_dev_t *)&(dev)
168168

169169
/**
170170
* @brief Number of MTDs defined in the MTD device array in XFA

drivers/include/mtd_emulated.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extern "C" {
6363
.init_done = false, \
6464
}; \
6565
\
66-
XFA_CONST(mtd_dev_xfa, 99) mtd_dev_t CONCAT(*mtd_emulated, n) = (mtd_dev_t *)&mtd_emulated_dev ## n
66+
XFA_CONST(mtd_dev_t, mtd_dev_xfa, 99) CONCAT(*mtd_emulated, n) = (mtd_dev_t *)&mtd_emulated_dev ## n
6767

6868
#if MODULE_VFS_AUTO_MOUNT || DOXYGEN
6969
/**

drivers/include/sdmmc/sdmmc.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,9 +1397,10 @@ typedef struct sdmmc_dev {
13971397
*
13981398
* @warning To ensure to have the references to all SDIO/SD/MMC device
13991399
* descriptors in this array, the low-level SDIO/SD/MMC peripheral
1400-
* drivers must define the references to their SDIO/SD/MMC
1401-
* device descriptors as XFA members by using the macro
1402-
* `XFA_CONST(sdmmc_devs, 0)` as shown in the example below.
1400+
* drivers must define the references to their SDIO/SD/MMC device
1401+
* descriptors as XFA members by using the macro
1402+
* `XFA_CONST(sdmmc_dev_t *, sdmmc_devs, 0)` as shown in the example
1403+
* below.
14031404
*
14041405
* For example, if the low-level
14051406
* SDIO/SD/MMC peripheral driver defines an MCU-specific SDIO/SD/MMC
@@ -1422,8 +1423,8 @@ typedef struct sdmmc_dev {
14221423
* },
14231424
* };
14241425
*
1425-
* XFA_CONST(sdmmc_devs, 0) sdmmc_dev_t * const _sdmmc_1 = (sdmmc_dev_t * const)&_mcu_sdmmc_devs[0];
1426-
* XFA_CONST(sdmmc_devs, 0) sdmmc_dev_t * const _sdmmc_2 = (sdmmc_dev_t * const)&_mcu_sdmmc_devs[1];
1426+
* XFA_CONST(sdmmc_dev_t * const, sdmmc_devs, 0) _sdmmc_1 = (sdmmc_dev_t * const)&_mcu_sdmmc_devs[0];
1427+
* XFA_CONST(sdmmc_dev_t * const, sdmmc_devs, 0) _sdmmc_2 = (sdmmc_dev_t * const)&_mcu_sdmmc_devs[1];
14271428
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14281429
*
14291430
*/

drivers/mtd_sdcard/mtd_sdcard.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ const mtd_desc_t mtd_sdcard_driver = {
226226
.params = &sdcard_spi_params[n] \
227227
}; \
228228
\
229-
XFA_CONST(mtd_dev_xfa, m) mtd_dev_t CONCAT(*mtd, m) = (mtd_dev_t *)&mtd_sdcard_dev ## n
229+
XFA_CONST(mtd_dev_t, mtd_dev_xfa, m) CONCAT(*mtd, m) = (mtd_dev_t *)&mtd_sdcard_dev ## n
230230

231231
#define MTD_SDCARD_DEV_FS(n, m, filesystem) \
232232
VFS_AUTO_MOUNT(filesystem, VFS_MTD(mtd_sdcard_dev ## n), VFS_DEFAULT_SD(n), m)

drivers/mtd_sdmmc/mtd_sdmmc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ const mtd_desc_t mtd_sdmmc_driver = {
194194
.sdmmc_idx = n, \
195195
}; \
196196
\
197-
XFA_CONST(mtd_dev_xfa, m) mtd_dev_t CONCAT(*mtd, m) = (mtd_dev_t *)&mtd_sdmmc_dev ## n
197+
XFA_CONST(mtd_dev_t, mtd_dev_xfa, m) CONCAT(*mtd, m) = (mtd_dev_t *)&mtd_sdmmc_dev ## n
198198

199199
#if IS_USED(MODULE_MTD_SDCARD_DEFAULT)
200200
/* we use /sd1 as default mount point for coexistence with mtd_sdcard */

drivers/sdmmc/sdmmc_sdhc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ static_assert(SDHC_CONFIG_NUMOF < 3, "MCU supports only 2 SDHC peripherals");
144144
static_assert(SDHC_CONFIG_NUMOF < 2, "MCU supports only 1 SDHC peripheral");
145145
#endif
146146

147-
XFA_CONST(sdmmc_devs, 0) sdmmc_dev_t * const _sdmmc_0 = (sdmmc_dev_t * const)&_sdhc_devs[0];
147+
XFA_CONST(sdmmc_dev_t * const, sdmmc_devs, 0) _sdmmc_0 = (sdmmc_dev_t * const)&_sdhc_devs[0];
148148
#if SDHC_CONFIG_NUMOF > 1
149-
XFA_CONST(sdmmc_devs, 0) sdmmc_dev_t * const _sdmmc_1 = (sdmmc_dev_t * const)&_sdhc_devs[1];
149+
XFA_CONST(sdmmc_dev_t * const, sdmmc_devs, 0) _sdmmc_1 = (sdmmc_dev_t * const)&_sdhc_devs[1];
150150
#endif
151151

152152
static int _set_clock_rate(sdmmc_dev_t *dev, sdmmc_clock_rate_t rate);

examples/suit_update/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
5151
#if IS_USED(MODULE_SUIT_STORAGE_VFS)
5252
XFA_USE(char*, suit_storage_files_reg);
5353
#ifdef CPU_NATIVE
54-
XFA(suit_storage_files_reg, 0) char* _slot0 = VFS_DEFAULT_DATA "/SLOT0.txt";
55-
XFA(suit_storage_files_reg, 1) char* _slot1 = VFS_DEFAULT_DATA "/SLOT1.txt";
54+
XFA(char*, suit_storage_files_reg, 0) _slot0 = VFS_DEFAULT_DATA "/SLOT0.txt";
55+
XFA(char*, suit_storage_files_reg, 1) _slot1 = VFS_DEFAULT_DATA "/SLOT1.txt";
5656
#endif
5757
#endif
5858

0 commit comments

Comments
 (0)