Skip to content

Commit 58d5e35

Browse files
hIAhmadkartben
authored andcommitted
toolchain: Add assembly-side counterpart of __aligned
Zephyr toolchain abstraction provides a macro __aligned(x) to add specified alignment, in bytes, to a chosen symbol for C/C++ source files but there is no portable counterpart available for symbols defined in assembly source files. This change-set adds a new macro ALIGN(x) for this purpose. Signed-off-by: Irfan Ahmad <[email protected]>
1 parent 4342d71 commit 58d5e35

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

include/zephyr/toolchain/common.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2010-2014 Wind River Systems, Inc.
3+
* Copyright (c) 2025 Siemens AG
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -60,6 +61,37 @@
6061
#define SECTION .section
6162
#endif
6263

64+
/*
65+
* General directive for assembly code, to align the following symbol, in bytes.
66+
*
67+
* Example:
68+
*
69+
* ALIGN(4)
70+
* test_symbol:
71+
*
72+
* 'test_symbol' will get aligned to 4 bytes.
73+
*/
74+
75+
#if defined(_ASMLANGUAGE) && !defined(_LINKER)
76+
77+
#if defined(CONFIG_X86) || defined(CONFIG_ARM) || defined(CONFIG_ARM64) || \
78+
defined(CONFIG_NIOS2) || defined(CONFIG_RISCV) || \
79+
defined(CONFIG_XTENSA) || defined(CONFIG_MIPS) || \
80+
defined(CONFIG_ARCH_POSIX)
81+
#define ALIGN(x) .balign x
82+
#elif defined(CONFIG_ARC)
83+
/* .align assembler directive is supported by all ARC toolchains and it is
84+
* implemented in the same way across ARC toolchains.
85+
*/
86+
#define ALIGN(x) .align x
87+
#elif defined(CONFIG_SPARC)
88+
#define ALIGN(x) .align x
89+
#else
90+
#error Architecture unsupported
91+
#endif
92+
93+
#endif /* defined(_ASMLANGUAGE) && !defined(_LINKER) */
94+
6395
/*
6496
* If the project is being built for speed (i.e. not for minimum size) then
6597
* align functions and branches in executable sections to improve performance.

0 commit comments

Comments
 (0)