Build: Fix silently-ignored attribute problem on CompCert 3.12.

Tested on godbolt.org only.
This commit is contained in:
Lasse Collin 2023-09-26 19:28:01 +03:00
parent 68c4cfc40c
commit 34a48239ed
2 changed files with 35 additions and 7 deletions

View File

@ -759,6 +759,13 @@ set(CMAKE_REQUIRED_FLAGS "-Werror")
check_c_source_compiles("
__attribute__((__constructor__))
static void my_constructor_func(void) { return; }
/*
* CompCert 3.12 silently ignores unsupported attributes
* if the function appears to be unused. It doesn't consider
* that the unknown attribute might make the function used.
*/
void call_func(void);
void call_func(void) { my_constructor_func(); }
int main(void) { return 0; }
"
HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR)
@ -791,15 +798,22 @@ if(ALLOW_ATTR_IFUNC)
static void (*resolve_func(void)) (void) { return func; }
void func_ifunc(void)
__attribute__((__ifunc__(\"resolve_func\")));
int main(void) { return 0; }
/*
* CompCert 3.12 silently ignores unsupported attributes
* if the function appears to be unused. It doesn't consider
* that the unknown attribute might make the function used.
*
* 'clang -Wall' incorrectly warns that resolve_func is
* unused (-Wunused-function). Correct assembly output is
* still produced. This problem exists at least in Clang
* versions 4 to 17. The following silences the bogus warning:
* versions 4 to 17.
*
* The following make CompCert diagnose the unsupported
* attribute and silences the bogus Clang warning:
*/
void make_clang_quiet(void);
void make_clang_quiet(void) { resolve_func()(); }
void call_funcs(void);
void call_funcs(void) { resolve_func()(); func_ifunc(); }
int main(void) { return 0; }
"
HAVE_FUNC_ATTRIBUTE_IFUNC)
cmake_pop_check_state()

View File

@ -866,6 +866,13 @@ CFLAGS="$CFLAGS -Werror"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
__attribute__((__constructor__))
static void my_constructor_func(void) { return; }
/*
* CompCert 3.12 silently ignores unsupported attributes
* if the function appears to be unused. It doesn't consider
* that the unknown attribute might make the function used.
*/
void call_func(void);
void call_func(void) { my_constructor_func(); }
]])], [
AC_DEFINE([HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR], [1],
[Define to 1 if __attribute__((__constructor__))
@ -908,13 +915,20 @@ if test "x$enable_ifunc" = xyes ; then
void func_ifunc (void)
__attribute__((__ifunc__("resolve_func")));
/*
* CompCert 3.12 silently ignores unsupported attributes
* if the function appears to be unused. It doesn't consider
* that the unknown attribute might make the function used.
*
* 'clang -Wall' incorrectly warns that resolve_func is
* unused (-Wunused-function). Correct assembly output is
* still produced. This problem exists at least in Clang
* versions 4 to 17. The following silences the bogus warning:
* versions 4 to 17.
*
* The following make CompCert diagnose the unsupported
* attribute and silences the bogus Clang warning:
*/
void make_clang_quiet(void);
void make_clang_quiet(void) { resolve_func()(); }
void call_funcs(void);
void call_funcs(void) { resolve_func()(); func_ifunc(); }
]])], [
AC_DEFINE([HAVE_FUNC_ATTRIBUTE_IFUNC], [1],
[Define to 1 if __attribute__((__ifunc__()))