clangs warns of the implicit cast of RAND_MAX to float:
error: implicit conversion from 'int' to 'float' changes value from
2147483647 to 2147483648 [-Werror,-Wimplicit-const-int-float-conversion]
So make it explicit.
clang does not work by using whitespace for defining the -z option:
$ make test t=misc/tst-gcs-disabled
[...]
clang: error: no such file or directory: 'gcs=always'
Use the usual comma separate way.
clang might generate an abort call when cleanup functions (set by
__attribute__ ((cleanup)) calls functions not marked as nothrow.
We can mitigate by marking some internal functions as __THROW,
but it is not possible for functions that issue used-provided
callbacks (for instance pthread_once).
The configure check might ignore if compiler driver warns that the
option is no support, so force fatal warnings.
If fixes the elf/tst-plt-rewrite regressions when ld.lld is used.
The multiplication is only required if the branch is taken, and the
compiler might not optimize it away.
If fixes the following issues when testcase is built with clang:
FAIL: math/test-ldouble-erf
Failure: erf (-0x4p-16384): Exception "Underflow" set
Failure: erf (0x1p-10000): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded54f38760a41abb84p-16384): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded54f38760a41abb88p-16384): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded54f4p-16384): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded54f8p-16384): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded5518p-16384): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded551cp-16384): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded552p-16384): Exception "Underflow" set
Failure: erf (0x4p-16384): Exception "Underflow" set
Failure: erf_downward (-0x4p-16384): Exception "Underflow" set
Failure: erf_downward (0x1p-10000): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded54f38760a41abb84p-16384): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded54f38760a41abb88p-16384): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded54f4p-16384): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded54f8p-16384): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded5518p-16384): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded551cp-16384): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded552p-16384): Exception "Underflow" set
Failure: erf_downward (0x4p-16384): Exception "Underflow" set
Failure: erf_towardzero (-0x4p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x1p-10000): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded54f38760a41abb84p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded54f38760a41abb88p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded54f4p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded54f8p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded5518p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded551cp-16384): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded552p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x4p-16384): Exception "Underflow" set
Failure: erf_upward (-0x4p-16384): Exception "Underflow" set
Failure: erf_upward (0x1p-10000): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded54f38760a41abb84p-16384): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded54f38760a41abb88p-16384): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded54f4p-16384): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded54f8p-16384): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded5518p-16384): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded551cp-16384): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded552p-16384): Exception "Underflow" set
Failure: erf_upward (0x4p-16384): Exception "Underflow" set
Checked on aarch64-linux-gnu with gcc and clang.
The pointer alias comparison will be optimized away by the compiler,
and gcc and clang will evaluate differently (clang evaluates as
false, while gcc as true).
clang does not handle pseudo normal numbers, so disable the fpclassify
and isnormal builtin optimization if clang is used. This only affect
x86, so add a new header, fp-builtin-denormal.h, which defines whether
the architecture required to disable the optimization through a new
glibc define (__FP_BUILTIN_DENORMAL).
It fixes the regression on test-ldouble-fpclassify and test-float64x-fpclassify
when built with clang:
Failure: fpclassify (pseudo_zero): Exception "Invalid operation" set
Failure: fpclassify (pseudo_inf): Exception "Invalid operation" set
Failure: fpclassify (pseudo_qnan): Exception "Invalid operation" set
Failure: fpclassify (pseudo_snan): Exception "Invalid operation" set
Failure: fpclassify (pseudo_unnormal): Exception "Invalid operation" set
Failure: fpclassify_downward (pseudo_zero): Exception "Invalid operation" set
Failure: fpclassify_downward (pseudo_inf): Exception "Invalid operation" set
Failure: fpclassify_downward (pseudo_qnan): Exception "Invalid operation" set
Failure: fpclassify_downward (pseudo_snan): Exception "Invalid operation" set
Failure: fpclassify_downward (pseudo_unnormal): Exception "Invalid operation" set
Failure: fpclassify_towardzero (pseudo_zero): Exception "Invalid operation" set
Failure: fpclassify_towardzero (pseudo_inf): Exception "Invalid operation" set
Failure: fpclassify_towardzero (pseudo_qnan): Exception "Invalid operation" set
Failure: fpclassify_towardzero (pseudo_snan): Exception "Invalid operation" set
Failure: fpclassify_towardzero (pseudo_unnormal): Exception "Invalid operation" set
Failure: fpclassify_upward (pseudo_zero): Exception "Invalid operation" set
Failure: fpclassify_upward (pseudo_inf): Exception "Invalid operation" set
Failure: fpclassify_upward (pseudo_qnan): Exception "Invalid operation" set
Failure: fpclassify_upward (pseudo_snan): Exception "Invalid operation" set
Failure: fpclassify_upward (pseudo_unnormal): Exception "Invalid operation" set
clang does not check for unordered numbers with builtins for
_Float128 type.
It fixes multiple issues with math tests, such as:
Failure: fmax (0, qNaN): Exception "Invalid operation" set
Failure: fmax (0, -qNaN): Exception "Invalid operation" set
Failure: fmax (-0, qNaN): Exception "Invalid operation" set
Failure: fmax (-0, -qNaN): Exception "Invalid operation" set
Failure: fmax (9, qNaN): Exception "Invalid operation" set
Failure: fmax (9, -qNaN): Exception "Invalid operation" set
Failure: fmax (-9, qNaN): Exception "Invalid operation" set
Failure: fmax (-9, -qNaN): Exception "Invalid operation" set
clang generates internal calls for some _chk symbol, so add internal
aliases for them, and stub some with rtld-stubbed-symbols to avoid
ld.so linker issues.
clang warns that the alias will be always resolve to
__GI___feupdateenv even if weak definition of __GI_feupdateenv
is overridden, which is really the intention.
The .cfi_label is a gas extension not supported by clang. From a
ziglang discussion [1], it seems that it is not really required.
[1] https://github.com/ziglang/zig/issues/3340
Recent clang version optimizes some loops contructions to strlen [1],
so adds the symbol on symbol-hacks.h to call the internal __GI_strlen.
[1] facd7dfc80
Recent clang version optimizes some loops contructions to strlen [1],
which might generate function calls when self-relocation is not
already done (on tunable parsing). Use an out-of-line function
with __attribute_optimization_barrier__ to avoid this.
[1] facd7dfc80
Recent lld version default to --no-undefined-version, which triggers
errors when building multiple libraries. For ld.so it fails with:
ld.lld: error: version script assignment of 'GLIBC_2.4' to symbol '__stack_chk_guard' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_PRIVATE' to symbol '__nptl_set_robust_list_avail' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_PRIVATE' to symbol '__pointer_chk_guard' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_PRIVATE' to symbol '_dl_starting_up' failed: symbol not defined
While for libc.so:
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_clearerr' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_fgetc' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_fileno' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_freopen' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_fscanf' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_fseek' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_peekc_unlocked' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_stderr_' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_stdin_' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_stdout_' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_pclose' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_perror' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_rewind' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_scanf' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_setbuf' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_setlinebuf' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_wdefault_setbuf' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '_IO_wfile_setbuf' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '__ctype32_tolower' failed: symbol not defined
ld.lld: error: version script assignment of 'GLIBC_2.17' to symbol '__ctype32_toupper' failed: symbol not defined
ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
The way version script is created with multiple missing symbols is
to simplify the build for multiple ABIs with different symbol
symbols. For instance, __stack_chk_guard is defined by default to
avoid the need of each ABI to add this symbol on its own version
script depending of which stack protector ABI it uses.
The libc.so warnings does show unused symbol being defined (like
_IO_clearerr), which might trigger potential errors depending of
how symbol are exported. However, since we do have teh ABI checks
for missing and extra symbol the linker extra checks are not really
required. So disable them for now.
clang 20 triggers an error for the unused '-c' argument used to create
errlist-data-aux-shared.S, errlist-data-aux.S, siglist-aux-shared.S,
and siglist-aux.S.
GCC enables it by default, clang in the other hand sets -fno-trapping-math.
This is required to fix some math and stdlib tests that explicit raises
floating point exceptions:
math/test-double-canonicalize.out
testing double (without inline functions)
Failure: canonicalize (max_value): Exception "Overflow" set
Failure: canonicalize (max_value): Exception "Inexact" set
Failure: canonicalize (-max_value): Exception "Overflow" set
Failure: canonicalize (-max_value): Exception "Inexact" set
Failure: canonicalize_downward (max_value): Exception "Overflow" set
Failure: canonicalize_downward (max_value): Exception "Inexact" set
Failure: canonicalize_downward (-max_value): Exception "Overflow" set
Failure: canonicalize_downward (-max_value): Exception "Inexact" set
Failure: canonicalize_towardzero (max_value): Exception "Overflow" set
Failure: canonicalize_towardzero (max_value): Exception "Inexact" set
Failure: canonicalize_towardzero (-max_value): Exception "Overflow" set
Failure: canonicalize_towardzero (-max_value): Exception "Inexact" set
Failure: canonicalize_upward (max_value): Exception "Overflow" set
Failure: canonicalize_upward (max_value): Exception "Inexact" set
Failure: canonicalize_upward (-max_value): Exception "Overflow" set
Failure: canonicalize_upward (-max_value): Exception "Inexact" set
test-float-catanh.out
testing float (without inline functions)
Failure: Real part of: catanh (-0x1.000002p+0 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh (-0x1.000002p+0 - 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh (-0x1.000002p+0 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh (-0x1.000002p+0 + 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh (-0xf.fffffp-4 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh (-0xf.fffffp-4 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh (0x1.000002p+0 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh (0x1.000002p+0 - 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh (0x1.000002p+0 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh (0x1.000002p+0 + 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh (0xf.fffffp-4 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh (0xf.fffffp-4 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_downward (-0x1.000002p+0 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_downward (-0x1.000002p+0 - 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh_downward (-0x1.000002p+0 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_downward (-0x1.000002p+0 + 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh_downward (-0xf.fffffp-4 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_downward (-0xf.fffffp-4 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_downward (0x1.000002p+0 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_downward (0x1.000002p+0 - 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh_downward (0x1.000002p+0 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_downward (0x1.000002p+0 + 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh_downward (0xf.fffffp-4 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_downward (0xf.fffffp-4 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_towardzero (-0x1.000002p+0 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_towardzero (-0x1.000002p+0 - 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh_towardzero (-0x1.000002p+0 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_towardzero (-0x1.000002p+0 + 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh_towardzero (-0xf.fffffp-4 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_towardzero (-0xf.fffffp-4 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_towardzero (0x1.000002p+0 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_towardzero (0x1.000002p+0 - 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh_towardzero (0x1.000002p+0 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_towardzero (0x1.000002p+0 + 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh_towardzero (0xf.fffffp-4 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_towardzero (0xf.fffffp-4 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_upward (-0x1.000002p+0 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_upward (-0x1.000002p+0 - 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh_upward (-0x1.000002p+0 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_upward (-0x1.000002p+0 + 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh_upward (-0xf.fffffp-4 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_upward (-0xf.fffffp-4 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_upward (0x1.000002p+0 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_upward (0x1.000002p+0 - 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh_upward (0x1.000002p+0 + 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_upward (0x1.000002p+0 + 0x8p-152 i): Exception "Underflow" set
Failure: Real part of: catanh_upward (0xf.fffffp-4 - 0x4p-128 i): Exception "Underflow" set
Failure: Real part of: catanh_upward (0xf.fffffp-4 + 0x4p-128 i): Exception "Underflow" set
The clang default to warning for missing fall-through and it does
not support all comment-like annotation that gcc does. Use a
proper attribute instead.
The __ifunc_resolver macro expands to:
extern __typeof (__redirect_name) name __attribute__ ((ifunc ("iname_ifunc")));
static __typeof (__redirect_name) *name_ifunc (void) { [...] };
And although NAME_IFUNC is and alias for NAME, clang still emits
an 'unused function 'name_ifunc' [-Werror,-Wunused-function]'
warning. The static is used to avoid name pollution on static
linkage.
clang does correctly propagate the no_stack_protector attribute for
inline function used in ifunc selectors. For instance, the exp function
is expanded as:
static inline void *
ieee754_exp_ifunc_selector (void)
{
[...]
}
extern __typeof (__redirect_ieee754_exp) __ieee754_exp
__attribute__ ((ifunc ("__ieee754_exp" "_ifunc")));
static __attribute__((no_stack_protector)) __typeof (__redirect_ieee754_exp) *i
__ieee754_exp_ifunc (void)
{
__typeof (__redirect_ieee754_exp) *res = ieee754_exp_ifunc_selector ();
return res;
};
The ifunc selection ended being compiled with -fstack-protector, and
with debug function set to the ifunc selector
(ieee754_exp_ifunc_selector) auxiliary function instead of the
selector itself.
The ifunc selector are called early, before TCB is setup, which
causes SIGSEGV for statically linked binaries.
To fix it use __always_inline instead of inline. It should not change
code generation on gcc and it fixes the code generation issue on
clang. It also fixes function debug information.
clang-19 does support it, but it should be gated as an option to
assemble (either with -Wa or -Xassembler). So add a test for -Wa
as well if -msse2avx is not supported.
clang issues:
dtotimespec.c:31:25: error: implicit conversion from 'time_t' (aka
'long') to 'double' changes value from 9223372036854775807 to
9223372036854775808 [-Werror,-Wimplicit-const-int-float-conversion]
else if (sec >= 1.0 + TYPE_MAXIMUM (time_t))
~ ^~~~~~~~~~~~~~~~~~~~~
../include/intprops.h:57:4: note: expanded from macro 'TYPE_MAXIMUM'
((t) (! TYPE_SIGNED (t)
\
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So explicit cast it to double.
clang emits an error while building vfprintf-internal for default
case:
error: result of comparison of constant 255 with expression of type
'char' is always true
[-Werror,-Wtautological-constant-out-of-range-compare]
if (spec <= UCHAR_MAX
The test is indeed not required for default non-wide build.
On ABIs with defined 'char' was unsigned type, clang fails to build
support_process_state.c with:
support_process_state.c:70:21: error: result of comparison of constant -1 with expression of type 'char' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
70 | if (cur_state == -1)
| ~~~~~~~~~ ^ ~~
1 error generated.
The constant should be used with c_cc, which for all supported ABIs
is defined as unsigned char. By using it as literar char constant,
clang triggers an error when compared with signal literal o ABIs that
define 'char' as unsigned.
On aarch64, clang shows:
../sysdeps/posix/fpathconf.c:118:21: error: right side of operator
converted from negative value to unsigned: -1 to 18446744073709551615
[-Werror]
#if _POSIX_VDISABLE == -1
~~~~~~~~~~~~~~~ ^ ~~
Commit 939da41143 added symbols redirections to handle ISO C
namespace, however clang do not support to redeclare the function
prototype.
This patch replaces the symbol redirections by direct asm aliases, as
done to handle libcall generation done by compiler on some loop
optimizations.
Checked on all affected ABIs.
clang emits an warning when a double alias redirection is used, to warn
the the original symbol will be used even when weak definition is
overridden. Howerver, this is a common pattern for weak_alias, where
multiple alias are set to same symbol.
Clang issues:
../sysdeps/ieee754/dbl-64/s_llround.c:83:30: error: incompatible
redeclaration of library function 'lround'
[-Werror,-Wincompatible-library-redeclaration]
libm_alias_double (__lround, lround)
^
../sysdeps/ieee754/dbl-64/s_llround.c:83:30: note: 'lround' is a builtin
with type 'long (double)'
clang warns:
../sysdeps/x86/fpu/powl_helper.c:233:3: error: absolute value function
'__builtin_fabsf' given an argument of type 'typeof (res)' (aka 'long
double') but has parameter of type 'float' which may cause truncation of
value [-Werror,-Wabsolute-value]
math_check_force_underflow (res);
^
./math-underflow.h:45:11: note: expanded from macro
'math_check_force_underflow'
if (fabs_tg (force_underflow_tmp) \
^
./math-underflow.h:27:20: note: expanded from macro 'fabs_tg'
#define fabs_tg(x) __MATH_TG ((x), (__typeof (x)) __builtin_fabs, (x))
^
../math/math.h:899:16: note: expanded from macro '__MATH_TG'
float: FUNC ## f ARGS, \
^
<scratch space>:73:1: note: expanded from here
__builtin_fabsf
^
It simplifies the code a bit and avoid the clang warning:
./config.h:12:2: error: #include_next in file found relative to primary
source file or found by absolute path; will search from start of include
path [-Werror,-Winclude-next-absolute-path]
#include_next <config.h>
^