compiler.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
  2. /*
  3. * NOLIBC compiler support header
  4. * Copyright (C) 2023 Thomas Weißschuh <linux@weissschuh.net>
  5. */
  6. #ifndef _NOLIBC_COMPILER_H
  7. #define _NOLIBC_COMPILER_H
  8. #if defined(__has_attribute)
  9. # define __nolibc_has_attribute(attr) __has_attribute(attr)
  10. #else
  11. # define __nolibc_has_attribute(attr) 0
  12. #endif
  13. #if __nolibc_has_attribute(naked)
  14. # define __nolibc_entrypoint __attribute__((naked))
  15. # define __nolibc_entrypoint_epilogue()
  16. #else
  17. # define __nolibc_entrypoint __attribute__((optimize("Os", "omit-frame-pointer")))
  18. # define __nolibc_entrypoint_epilogue() __builtin_unreachable()
  19. #endif /* __nolibc_has_attribute(naked) */
  20. #if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) || defined(__SSP_EXPLICIT__)
  21. #define _NOLIBC_STACKPROTECTOR
  22. #endif /* defined(__SSP__) ... */
  23. #if __nolibc_has_attribute(no_stack_protector)
  24. # define __no_stack_protector __attribute__((no_stack_protector))
  25. #else
  26. # define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
  27. #endif /* __nolibc_has_attribute(no_stack_protector) */
  28. #endif /* _NOLIBC_COMPILER_H */