Build: Add a check for __attribute__((__always_inline__)).

All even remotely relevant GCC and Clang versions support this
attribute. The test is useful to detect support in compilers that
don't define __GNUC__ or __clang__, for example, Solaris Studio.
This commit is contained in:
Lasse Collin 2023-10-22 17:51:11 +03:00
parent 4a1ef58ae7
commit 34aa4725ed
3 changed files with 17 additions and 0 deletions

View File

@ -829,6 +829,10 @@ calculation if supported by the system" ON)
endif()
endif()
# Check for __attribute__((__always_inline__)) support.
tuklib_check_func_attribute_always_inline(HAVE_FUNC_ATTRIBUTE_ALWAYS_INLINE)
tuklib_add_definition_if(liblzma HAVE_FUNC_ATTRIBUTE_ALWAYS_INLINE)
# Symbol visibility support:
#
# The C_VISIBILITY_PRESET property takes care of adding the compiler

View File

@ -39,6 +39,14 @@ function(tuklib_check_attribute CODE RESULT)
": unknown attribute")
endfunction()
function(tuklib_check_func_attribute_always_inline RESULT)
tuklib_check_attribute("
__attribute__((__always_inline__))
static inline int my_inline_func(int x) { return x + 1; }
void my_func(void) { return my_inline_func(123); }
" "${RESULT}")
endfunction()
function(tuklib_check_func_attribute_constructor RESULT)
tuklib_check_attribute("
__attribute__((__constructor__))

View File

@ -844,6 +844,11 @@ AC_ARG_ENABLE([ifunc], [AS_HELP_STRING([--disable-ifunc],
[], [enable_ifunc=yes])
AS_IF([test "x$enable_ifunc" = xyes], [AX_GCC_FUNC_ATTRIBUTE([ifunc])])
# GCC >= 3.2 and Clang support the attribute always_inline but a few other
# compilers support it too. So it's better to check for the support here
# instead of just checking if __GNUC__ or __clang__ is defined.
AX_GCC_FUNC_ATTRIBUTE([always_inline])
###############################################################################
# Checks for library functions.