Skip to content

Commit e098eeb

Browse files
committed
tools/nolibc: compiler: use attribute((naked)) if available
The current entrypoint attributes optimize("Os", "omit-frame-pointer") are intended to avoid all compiler generated code, like function porologue and epilogue. This is the exact usecase implemented by the attribute "naked". Unfortunately this is not implemented by GCC for all targets, so only use it where available. This also provides compatibility with clang, which recognizes the "naked" attribute but not the previously used attribute "optimized". Acked-by: Willy Tarreau <w@1wt.eu> Link: https://lore.kernel.org/r/20240807-nolibc-llvm-v2-6-c20f2f5fc7c2@weissschuh.net Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
1 parent ef32e9b commit e098eeb

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

tools/include/nolibc/compiler.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
# define __nolibc_has_attribute(attr) 0
1313
#endif
1414

15-
#define __nolibc_entrypoint __attribute__((optimize("Os", "omit-frame-pointer")))
16-
#define __nolibc_entrypoint_epilogue() __builtin_unreachable()
15+
#if __nolibc_has_attribute(naked)
16+
# define __nolibc_entrypoint __attribute__((naked))
17+
# define __nolibc_entrypoint_epilogue()
18+
#else
19+
# define __nolibc_entrypoint __attribute__((optimize("Os", "omit-frame-pointer")))
20+
# define __nolibc_entrypoint_epilogue() __builtin_unreachable()
21+
#endif /* __nolibc_has_attribute(naked) */
1722

1823
#if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) || defined(__SSP_EXPLICIT__)
1924

0 commit comments

Comments
 (0)