Skip to content

Commit 3a8feb8

Browse files
committed
Improve check for a function attribute support.
The compiler may advertise function attribute support with __has_attribute operator even though it does not implement the feature on some architecture. This fixes the issue with GCC 11 on ppc64le with __attribute__((zero_call_used_regs("used"))). Fixes: #959.
1 parent 2b9523a commit 3a8feb8

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

configure.ac

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,27 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
680680
])
681681
CFLAGS=$saved_CFLAGS
682682
683+
dnl Force compiler to use zero_call_used_regs("used") to check for the function attribute support.
684+
dnl Otherwise the compiler may falsely advertise it with __has_attribute operator, even though
685+
dnl it does not implement it on some archs.
686+
AC_MSG_CHECKING([for zero_call_used_regs(user)])
687+
saved_CFLAGS=$CFLAGS
688+
CFLAGS="-O0 -Werror"
689+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
690+
void _test_function(void);
691+
__attribute__((zero_call_used_regs("used"))) void _test_function(void) {
692+
volatile int *i; volatile int j = 0; if (j) *i = 0;
693+
}
694+
]],
695+
[[ _test_function() ]]
696+
)],[
697+
AC_DEFINE([HAVE_ATTRIBUTE_ZEROCALLUSEDREGS], 1, [Define to 1 to use __attribute__((zero_call_used_regs("used")))])
698+
AC_MSG_RESULT([yes])
699+
], [
700+
AC_MSG_RESULT([no])
701+
])
702+
CFLAGS=$saved_CFLAGS
703+
683704
AC_MSG_CHECKING([for systemd tmpfiles config directory])
684705
if test "x$prefix" != "xNONE"; then
685706
saved_PKG_CONFIG=$PKG_CONFIG

lib/crypto_backend/memutils.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99

1010
#define ATTR_NOINLINE __attribute__ ((noinline))
1111
#define ATTR_ZERO_REGS
12-
#if defined __has_attribute
13-
# if __has_attribute (zero_call_used_regs)
12+
#if HAVE_ATTRIBUTE_ZEROCALLUSEDREGS
1413
# undef ATTR_ZERO_REGS
1514
# define ATTR_ZERO_REGS __attribute__ ((zero_call_used_regs("used")))
16-
# endif
1715
#endif
1816

1917
/* Workaround for https://github.com/google/sanitizers/issues/1507 */

meson.build

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,21 @@ if cc.links(
697697
description: 'Define to 1 to use __attribute__((symver))')
698698
endif
699699

700+
# ==========================================================================
701+
# Check compiler support for zero_called_used_regs("used") function attribute
702+
if cc.links(
703+
'''void _test_fn(void);
704+
705+
__attribute__((zero_call_used_regs("used"))) void _test_fn(void) {
706+
volatile int *i; volatile int j = 0; if (j) *i = 0;
707+
}
708+
int main(void) { _test_fn(); return 0; }''',
709+
args: ['-O0', '-Werror' ],
710+
name: 'for zero_call_used_regs("used") attribute support')
711+
conf.set10('HAVE_ATTRIBUTE_ZEROCALLUSEDREGS', true,
712+
description: 'Define to 1 to use __attribute__((zero_call_used_regs("used")))')
713+
endif
714+
700715
# ==========================================================================
701716

702717
if get_option('dev-random')

0 commit comments

Comments
 (0)