Skip to content

Commit be413af

Browse files
Fix-Pointxiaoxiang781216
authored andcommitted
compiler: Fix inlining stack-overflow.
If the compiler optimization is disabled, the stack-usage of inlining functions will not be optimized. In this case, force inlining can lead to stack-overflow (e.g. qemu-armeabi-v7a-bl). This commit replaced the definition of the always_inline_function and inline_function with the inline keyword to avoid force-inlining. Signed-off-by: ouyangxiangzhen <[email protected]>
1 parent f309d65 commit be413af

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

include/nuttx/compiler.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,19 @@
249249
/* The always_inline_function attribute informs GCC that the function should
250250
* always be inlined, regardless of the level of optimization. The
251251
* noinline_function indicates that the function should never be inlined.
252+
* Note that if the compiler optimization is disabled, the stack-usage of
253+
* the inline functions will not be optimized. In this case, force inlining
254+
* can lead to stack-overflow.
252255
*/
253256

254-
# define always_inline_function __attribute__((always_inline,no_instrument_function)) inline
255-
# define inline_function __attribute__((always_inline)) inline
257+
# ifdef CONFIG_DEBUG_NOOPT
258+
# define always_inline_function inline
259+
# define inline_function inline
260+
# else
261+
# define always_inline_function __attribute__((always_inline,no_instrument_function)) inline
262+
# define inline_function __attribute__((always_inline)) inline
263+
# endif
264+
256265
# define noinline_function __attribute__((noinline))
257266

258267
/* The noinstrument_function attribute informs GCC don't instrument it */

0 commit comments

Comments
 (0)