aboutsummaryrefslogtreecommitdiff
path: root/tools/include/nolibc/compiler.h
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2024-08-07 23:51:42 +0200
committerThomas Weißschuh <linux@weissschuh.net>2024-08-12 22:22:03 +0200
commite098eebb63cb1c03813559b5db9da4451ba3a318 (patch)
treece51a9c0d995c48dd14e2231a5c548e63db8d836 /tools/include/nolibc/compiler.h
parentef32e9b6a325d1d013b30d898b4dff94082902cd (diff)
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>
Diffstat (limited to 'tools/include/nolibc/compiler.h')
-rw-r--r--tools/include/nolibc/compiler.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h
index 3a1d5b8d4fb9..9bc6a706a332 100644
--- a/tools/include/nolibc/compiler.h
+++ b/tools/include/nolibc/compiler.h
@@ -12,8 +12,13 @@
# define __nolibc_has_attribute(attr) 0
#endif
-#define __nolibc_entrypoint __attribute__((optimize("Os", "omit-frame-pointer")))
-#define __nolibc_entrypoint_epilogue() __builtin_unreachable()
+#if __nolibc_has_attribute(naked)
+# define __nolibc_entrypoint __attribute__((naked))
+# define __nolibc_entrypoint_epilogue()
+#else
+# define __nolibc_entrypoint __attribute__((optimize("Os", "omit-frame-pointer")))
+# define __nolibc_entrypoint_epilogue() __builtin_unreachable()
+#endif /* __nolibc_has_attribute(naked) */
#if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) || defined(__SSP_EXPLICIT__)