tools/nolibc: add autodetection for stackprotector support

The stackprotector support in nolibc should be enabled iff it is also
enabled in the compiler.
Use the preprocessor defines added by gcc and clang if stackprotector
support is enable to automatically do so in nolibc.

This completely removes the need for any user-visible API.

To avoid inlining the lengthy preprocessor check into every user
introduce a new header compiler.h that abstracts the logic away.

As the define NOLIBC_STACKPROTECTOR is now not user-relevant anymore
prefix it with an underscore.

Suggested-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/lkml/20230520133237.GA27501@1wt.eu/
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
This commit is contained in:
Thomas Weißschuh
2023-05-21 11:36:34 +02:00
committed by Paul E. McKenney
parent e21a2eef74
commit 818924d129
11 changed files with 42 additions and 30 deletions
+3 -7
View File
@@ -7,13 +7,9 @@
#ifndef _NOLIBC_STACKPROTECTOR_H
#define _NOLIBC_STACKPROTECTOR_H
#include "arch.h"
#include "compiler.h"
#if defined(NOLIBC_STACKPROTECTOR)
#if !defined(__ARCH_SUPPORTS_STACK_PROTECTOR)
#error "nolibc does not support stack protectors on this arch"
#endif
#if defined(_NOLIBC_STACKPROTECTOR)
#include "sys.h"
#include "stdlib.h"
@@ -49,6 +45,6 @@ void __stack_chk_init(void)
if (__stack_chk_guard != (uintptr_t) &__stack_chk_guard)
__stack_chk_guard ^= (uintptr_t) &__stack_chk_guard;
}
#endif /* defined(NOLIBC_STACKPROTECTOR) */
#endif /* defined(_NOLIBC_STACKPROTECTOR) */
#endif /* _NOLIBC_STACKPROTECTOR_H */