mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-25 04:01:10 +00:00
813378e9fe
This patch obsoletes support for SVID libm error handling (the system where a user-defined function matherr is called on a libm function error; only enabled if you also set _LIB_VERSION = _SVID_ or _LIB_VERSION = _XOPEN_) and the use of the _LIB_VERSION global variable to control libm error handling. matherr and _LIB_VERSION are made into compat symbols, not supported for new ports or for static linking. The libieee.a object file (which sets _LIB_VERSION = _IEEE_, so disabling errno setting for some functions) is also removed, and all the related definitions are removed from math.h. The manual already recommends against using matherr, and it's already not supported for _Float128 functions (those use new wrappers that don't support matherr, only errno) - this patch means that it becomes possible to e.g. add sinf32 as an alias to sinf without that resulting in undesired matherr support in sinf32 for existing glibc ports. matherr support is not part of any standard supported by glibc (it was removed in XPG4). Because matherr is a function to be defined by the user, of course user programs defining such a function will still continue to link; it just quietly won't be used. If they try to write to the library's copy of _LIB_VERSION to enable SVID error handling, however, they will get a link error (but if they define their own _LIB_VERSION variable, they won't). I expect the most likely case of build failures from this patch to be programs with unconditional cargo-culted uses of -lieee (based on a notion of "I want IEEE floating point", not any actual requirement for that library). Ideally, the new-port-or-static-linking case would use the new wrappers used for _Float128. This is not implemented in this patch, because of the complication of architecture-specific (powerpc32 and sparc) sqrt wrappers that use _LIB_VERSION and __kernel_standard directly. Thus, the old wrappers and __kernel_standard are still built unconditionally, and _LIB_VERSION still exists in static libm. But when the old wrappers and __kernel_standard are built in the non-compat case, _LIB_VERSION and matherr are defined as macros so code to support those features isn't actually built into static libm or new ports' shared libm after this patch. I intend to move to the new wrappers for static libm and new ports in followup patches. I believe the sqrt wrappers for powerpc32 and sparc can reasonably be removed. GCC already optimizes the normal case of sqrt by generating code that uses a hardware instruction and only calls the sqrt function if the argument was negative (if -fno-math-errno, of course, it just uses the hardware instruction without any check for negative argument being needed). Thus those wrappers will only actually get called in the case of negative arguments, which is not a case it makes sense to optimize for. But even without removing the powerpc32 and sparc wrappers it should still be possible to move to the new wrappers for static libm and new ports, just without having those dubious architecture-specific optimizations in static libm. Everything said about matherr equally applies to matherrf and matherrl (IA64-specific, undocumented), except that the structure of IA64 libm means it won't be converted to using the new wrappers (it doesn't use the old ones either, but its own error-handling code instead). As with other tests of compat symbols, I expect test-matherr and test-matherr-2 to need to become appropriately conditional once we have a system for disabling such tests for ports too new to have the relevant symbols. Tested for x86_64 and x86, and with build-many-glibcs.py. * math/math.h [__USE_MISC] (_LIB_VERSION_TYPE): Remove. [__USE_MISC] (_LIB_VERSION): Likewise. [__USE_MISC] (struct exception): Likewise. [__USE_MISC] (matherr): Likewise. [__USE_MISC] (DOMAIN): Likewise. [__USE_MISC] (SING): Likewise. [__USE_MISC] (OVERFLOW): Likewise. [__USE_MISC] (UNDERFLOW): Likewise. [__USE_MISC] (TLOSS): Likewise. [__USE_MISC] (PLOSS): Likewise. [__USE_MISC] (HUGE): Likewise. [__USE_XOPEN] (MAXFLOAT): Define even if [__USE_MISC]. * math/math-svid-compat.h: New file. * conform/linknamespace.pl (@whitelist): Remove matherr, matherrf and matherrl. * include/math.h [!_ISOMAC] (__matherr): Remove. * manual/arith.texi (FP Exceptions): Do not document matherr. * math/Makefile (tests): Change test-matherr to test-matherr-3. (tests-internal): New variable. (install-lib): Do not add libieee.a. (non-lib.a): Likewise. (extra-objs): Do not add libieee.a and ieee-math.o. (CPPFLAGS-s_lib_version.c): Remove variable. ($(objpfx)libieee.a): Remove rule. ($(addprefix $(objpfx), $(tests-internal)): Depend on $(libm). * math/ieee-math.c: Remove. * math/libm-test-support.c (matherr): Remove. * math/test-matherr.c: Use <support/test-driver.c>. Add copyright and license notices. Include <math-svid-compat.h> and <shlib-compat.h>. (matherr): Undefine as macro. Use compat_symbol_reference. (_LIB_VERSION): Likewise. * math/test-matherr-2.c: New file. * math/test-matherr-3.c: Likewise. * sysdeps/generic/math_private.h (__kernel_standard): Remove declaration. (__kernel_standard_f): Likewise. (__kernel_standard_l): Likewise. * sysdeps/ieee754/s_lib_version.c: Do not include <math.h> or <math_private.h>. Include <math-svid-compat.h>. (_LIB_VERSION): Undefine as macro. (_LIB_VERSION_INTERNAL): Always initialize to _POSIX_. Define only if [LIBM_SVID_COMPAT || !defined SHARED]. If [LIBM_SVID_COMPAT], use compat_symbol. * sysdeps/ieee754/s_matherr.c: Do not include <math.h> or <math_private.h>. Include <math-svid-compat.h>. (matherr): Undefine as macro. (__matherr): Define only if [LIBM_SVID_COMPAT]. Use compat_symbol. * sysdeps/ia64/fpu/libm_error.c: Include <math-svid-compat.h>. [_LIBC && LIBM_SVID_COMPAT] (matherrf): Use compat_symbol_reference. [_LIBC && LIBM_SVID_COMPAT] (matherrl): Likewise. [_LIBC && !LIBM_SVID_COMPAT] (matherrf): Define as macro. [_LIBC && !LIBM_SVID_COMPAT] (matherrl): Likewise. * sysdeps/ia64/fpu/libm_support.h: Include <math-svid-compat.h>. (MATHERR_D): Remove declaration. [!_LIBC] (_LIB_VERSION_TYPE): Likewise [!LIBM_BUILD] (_LIB_VERSIONIMF): Likewise. [LIBM_BUILD] (pmatherrf): Likewise. [LIBM_BUILD] (pmatherr): Likewise. [LIBM_BUILD] (pmatherrl): Likewise. (DOMAIN): Likewise. (SING): Likewise. (OVERFLOW): Likewise. (UNDERFLOW): Likewise. (TLOSS): Likewise. (PLOSS): Likewise. * sysdeps/ia64/fpu/s_matherrf.c: Include <math-svid-compat.h>. (__matherrf): Define only if [LIBM_SVID_COMPAT]. Use compat_symbol. * sysdeps/ia64/fpu/s_matherrl.c: Include <math-svid-compat.h>. (__matherrl): Define only if [LIBM_SVID_COMPAT]. Use compat_symbol. * math/lgamma-compat.h: Include <math-svid-compat.h>. * math/w_acos_compat.c: Likewise. * math/w_acosf_compat.c: Likewise. * math/w_acosh_compat.c: Likewise. * math/w_acoshf_compat.c: Likewise. * math/w_acoshl_compat.c: Likewise. * math/w_acosl_compat.c: Likewise. * math/w_asin_compat.c: Likewise. * math/w_asinf_compat.c: Likewise. * math/w_asinl_compat.c: Likewise. * math/w_atan2_compat.c: Likewise. * math/w_atan2f_compat.c: Likewise. * math/w_atan2l_compat.c: Likewise. * math/w_atanh_compat.c: Likewise. * math/w_atanhf_compat.c: Likewise. * math/w_atanhl_compat.c: Likewise. * math/w_cosh_compat.c: Likewise. * math/w_coshf_compat.c: Likewise. * math/w_coshl_compat.c: Likewise. * math/w_exp10_compat.c: Likewise. * math/w_exp10f_compat.c: Likewise. * math/w_exp10l_compat.c: Likewise. * math/w_exp2_compat.c: Likewise. * math/w_exp2f_compat.c: Likewise. * math/w_exp2l_compat.c: Likewise. * math/w_fmod_compat.c: Likewise. * math/w_fmodf_compat.c: Likewise. * math/w_fmodl_compat.c: Likewise. * math/w_hypot_compat.c: Likewise. * math/w_hypotf_compat.c: Likewise. * math/w_hypotl_compat.c: Likewise. * math/w_j0_compat.c: Likewise. * math/w_j0f_compat.c: Likewise. * math/w_j0l_compat.c: Likewise. * math/w_j1_compat.c: Likewise. * math/w_j1f_compat.c: Likewise. * math/w_j1l_compat.c: Likewise. * math/w_jn_compat.c: Likewise. * math/w_jnf_compat.c: Likewise. * math/w_jnl_compat.c: Likewise. * math/w_lgamma_main.c: Likewise. * math/w_lgamma_r_compat.c: Likewise. * math/w_lgammaf_main.c: Likewise. * math/w_lgammaf_r_compat.c: Likewise. * math/w_lgammal_main.c: Likewise. * math/w_lgammal_r_compat.c: Likewise. * math/w_log10_compat.c: Likewise. * math/w_log10f_compat.c: Likewise. * math/w_log10l_compat.c: Likewise. * math/w_log2_compat.c: Likewise. * math/w_log2f_compat.c: Likewise. * math/w_log2l_compat.c: Likewise. * math/w_log_compat.c: Likewise. * math/w_logf_compat.c: Likewise. * math/w_logl_compat.c: Likewise. * math/w_pow_compat.c: Likewise. * math/w_powf_compat.c: Likewise. * math/w_powl_compat.c: Likewise. * math/w_remainder_compat.c: Likewise. * math/w_remainderf_compat.c: Likewise. * math/w_remainderl_compat.c: Likewise. * math/w_scalb_compat.c: Likewise. * math/w_scalbf_compat.c: Likewise. * math/w_scalbl_compat.c: Likewise. * math/w_sinh_compat.c: Likewise. * math/w_sinhf_compat.c: Likewise. * math/w_sinhl_compat.c: Likewise. * math/w_sqrt_compat.c: Likewise. * math/w_sqrtf_compat.c: Likewise. * math/w_sqrtl_compat.c: Likewise. * math/w_tgamma_compat.c: Likewise. * math/w_tgammaf_compat.c: Likewise. * math/w_tgammal_compat.c: Likewise. * sysdeps/ieee754/dbl-64/w_exp_compat.c: Likewise. * sysdeps/ieee754/flt-32/w_expf_compat.c: Likewise. * sysdeps/ieee754/k_standard.c: Likewise. * sysdeps/ieee754/k_standardf.c: Likewise. * sysdeps/ieee754/k_standardl.c: Likewise. * sysdeps/ieee754/ldbl-128/w_expl_compat.c: Likewise. * sysdeps/ieee754/ldbl-128ibm/w_expl_compat.c: Likewise. * sysdeps/ieee754/ldbl-96/w_expl_compat.c: Likewise. * sysdeps/powerpc/powerpc32/power4/fpu/w_sqrt_compat.S: Likewise. * sysdeps/powerpc/powerpc32/power4/fpu/w_sqrtf_compat.S: Likewise. * sysdeps/powerpc/powerpc32/power5/fpu/w_sqrt_compat.S: Likewise. * sysdeps/powerpc/powerpc32/power5/fpu/w_sqrtf_compat.S: Likewise. * sysdeps/sparc/sparc32/fpu/w_sqrt_compat.S: Likewise. * sysdeps/sparc/sparc32/fpu/w_sqrtf_compat.S: Likewise. * sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/w_sqrt_compat-vis3.S: Likewise. * sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/w_sqrtf_compat-vis3.S: Likewise. * sysdeps/sparc/sparc32/sparcv9/fpu/w_sqrt_compat.S: Likewise. * sysdeps/sparc/sparc32/sparcv9/fpu/w_sqrtf_compat.S: Likewise. * sysdeps/sparc/sparc64/fpu/w_sqrt_compat.S: Likewise. * sysdeps/sparc/sparc64/fpu/w_sqrtf_compat.S: Likewise.
234 lines
7.4 KiB
Raku
234 lines
7.4 KiB
Raku
#!/usr/bin/perl
|
|
|
|
# Check that use of symbols declared in a given header does not result
|
|
# in any symbols being brought in that are not reserved with external
|
|
# linkage for the given standard.
|
|
|
|
# Copyright (C) 2014-2017 Free Software Foundation, Inc.
|
|
# This file is part of the GNU C Library.
|
|
|
|
# The GNU C Library is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
# License as published by the Free Software Foundation; either
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
# The GNU C Library is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Lesser General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
# License along with the GNU C Library; if not, see
|
|
# <http://www.gnu.org/licenses/>.
|
|
|
|
use GlibcConform;
|
|
use Getopt::Long;
|
|
|
|
GetOptions ('header=s' => \$header, 'standard=s' => \$standard,
|
|
'flags=s' => \$flags, 'cc=s' => \$CC, 'tmpdir=s' => \$tmpdir,
|
|
'stdsyms=s' => \$stdsyms_file, 'libsyms=s' => \$libsyms_file,
|
|
'readelf=s' => \$READELF);
|
|
|
|
# Load the list of symbols that are OK.
|
|
%stdsyms = ();
|
|
open (STDSYMS, "<$stdsyms_file") || die ("open $stdsyms_file: $!\n");
|
|
while (<STDSYMS>) {
|
|
chomp;
|
|
$stdsyms{$_} = 1;
|
|
}
|
|
close (STDSYMS) || die ("close $stdsyms_file: $!\n");
|
|
|
|
# The following whitelisted symbols are also allowed for now.
|
|
#
|
|
# * Bug 17576: stdin, stdout, stderr only reserved with external
|
|
# linkage when stdio.h included (and possibly not then), not
|
|
# generally.
|
|
#
|
|
# * Bug 18442: re_syntax_options wrongly brought in by regcomp and
|
|
# used by re_comp.
|
|
#
|
|
@whitelist = qw(stdin stdout stderr re_syntax_options);
|
|
foreach my $sym (@whitelist) {
|
|
$stdsyms{$sym} = 1;
|
|
}
|
|
|
|
# Return information about GLOBAL and WEAK symbols listed in readelf
|
|
# -s output.
|
|
sub list_syms {
|
|
my ($syms_file) = @_;
|
|
open (SYMS, "<$syms_file") || die ("open $syms_file: $!\n");
|
|
my ($file) = $syms_file;
|
|
my (@ret) = ();
|
|
while (<SYMS>) {
|
|
chomp;
|
|
if (/^File: (.*)/) {
|
|
$file = $1;
|
|
$file =~ s|^.*/||;
|
|
next;
|
|
}
|
|
s/^\s*//;
|
|
# Architecture-specific st_other bits appear inside [] and disrupt
|
|
# the format of readelf output.
|
|
s/\[.*?\]//;
|
|
my (@fields) = split (/\s+/, $_);
|
|
if (@fields < 8) {
|
|
next;
|
|
}
|
|
my ($bind) = $fields[4];
|
|
my ($ndx) = $fields[6];
|
|
my ($sym) = $fields[7];
|
|
if ($bind ne "GLOBAL" && $bind ne "WEAK") {
|
|
next;
|
|
}
|
|
if ($sym !~ /^\w+$/) {
|
|
next;
|
|
}
|
|
push (@ret, [$file, $sym, $bind, $ndx ne "UND"]);
|
|
}
|
|
close (SYMS) || die ("close $syms_file: $!\n");
|
|
return @ret;
|
|
}
|
|
|
|
# Load information about GLOBAL and WEAK symbols defined or used in
|
|
# the standard libraries.
|
|
# Symbols from a given object, except for weak defined symbols.
|
|
%seen_syms = ();
|
|
# Strong undefined symbols from a given object.
|
|
%strong_undef_syms = ();
|
|
# Objects defining a given symbol (strongly or weakly).
|
|
%sym_objs = ();
|
|
@sym_data = list_syms ($libsyms_file);
|
|
foreach my $sym (@sym_data) {
|
|
my ($file, $name, $bind, $defined) = @$sym;
|
|
if ($defined) {
|
|
if (!defined ($sym_objs{$name})) {
|
|
$sym_objs{$name} = [];
|
|
}
|
|
push (@{$sym_objs{$name}}, $file);
|
|
}
|
|
if ($bind eq "GLOBAL" || !$defined) {
|
|
if (!defined ($seen_syms{$file})) {
|
|
$seen_syms{$file} = [];
|
|
}
|
|
push (@{$seen_syms{$file}}, $name);
|
|
}
|
|
if ($bind eq "GLOBAL" && !$defined) {
|
|
if (!defined ($strong_undef_syms{$file})) {
|
|
$strong_undef_syms{$file} = [];
|
|
}
|
|
push (@{$strong_undef_syms{$file}}, $name);
|
|
}
|
|
}
|
|
|
|
# Determine what ELF-level symbols are brought in by use of C-level
|
|
# symbols declared in the given header.
|
|
#
|
|
# The rules followed are heuristic and so may produce false positives
|
|
# and false negatives.
|
|
#
|
|
# * All undefined symbols are considered of signficance, but it is
|
|
# possible that (a) any standard library definition is weak, so can be
|
|
# overridden by the user's definition, and (b) the symbol is only used
|
|
# conditionally and not if the program is limited to standard
|
|
# functionality.
|
|
#
|
|
# * If a symbol reference is only brought in by the user using a data
|
|
# symbol rather than a function from the standard library, this will
|
|
# not be detected.
|
|
#
|
|
# * If a symbol reference is only brought in by crt*.o or libgcc, this
|
|
# will not be detected.
|
|
#
|
|
# * If a symbol reference is only brought in through __builtin_foo in
|
|
# a standard macro being compiled to call foo, this will not be
|
|
# detected.
|
|
#
|
|
# * Header inclusions should be compiled several times with different
|
|
# options such as -O2, -D_FORTIFY_SOURCE and -D_FILE_OFFSET_BITS=64 to
|
|
# find out what symbols are undefined from such a compilation; this is
|
|
# not yet implemented.
|
|
#
|
|
# * This script finds symbols referenced through use of macros on the
|
|
# basis that if a macro calls an internal function, that function must
|
|
# also be declared in the header. However, the header might also
|
|
# declare implementation-namespace functions that are not called by
|
|
# any standard macro in the header, resulting in false positives for
|
|
# any symbols brought in only through use of those
|
|
# implementation-namespace functions.
|
|
#
|
|
# * Namespace issues can apply for dynamic linking as well as static
|
|
# linking, when a call is from one shared library to another or uses a
|
|
# PLT entry for a call within a shared library; such issues are only
|
|
# detected by this script if the same namespace issue applies for
|
|
# static linking.
|
|
|
|
@c_syms = list_exported_functions ("$CC $flags", $standard, $header, $tmpdir);
|
|
$cincfile = "$tmpdir/undef-$$.c";
|
|
$cincfile_o = "$tmpdir/undef-$$.o";
|
|
$cincfile_sym = "$tmpdir/undef-$$.sym";
|
|
open (CINCFILE, ">$cincfile") || die ("open $cincfile: $!\n");
|
|
print CINCFILE "#include <$header>\n";
|
|
foreach my $sym (sort @c_syms) {
|
|
print CINCFILE "void *__glibc_test_$sym = (void *) &$sym;\n";
|
|
}
|
|
close CINCFILE || die ("close $cincfile: $!\n");
|
|
system ("$CC $flags -D_ISOMAC $CFLAGS{$standard} -c $cincfile -o $cincfile_o")
|
|
&& die ("compiling failed\n");
|
|
system ("LC_ALL=C $READELF -W -s $cincfile_o > $cincfile_sym")
|
|
&& die ("readelf failed\n");
|
|
@elf_syms = list_syms ($cincfile_sym);
|
|
unlink ($cincfile) || die ("unlink $cincfile: $!\n");
|
|
unlink ($cincfile_o) || die ("unlink $cincfile_o: $!\n");
|
|
unlink ($cincfile_sym) || die ("unlink $cincfile_sym: $!\n");
|
|
|
|
%seen_where = ();
|
|
%files_seen = ();
|
|
%all_undef = ();
|
|
%current_undef = ();
|
|
foreach my $sym (@elf_syms) {
|
|
my ($file, $name, $bind, $defined) = @$sym;
|
|
if ($bind eq "GLOBAL" && !$defined) {
|
|
$seen_where{$name} = "[initial] $name";
|
|
$all_undef{$name} = "[initial] $name";
|
|
$current_undef{$name} = "[initial] $name";
|
|
}
|
|
}
|
|
|
|
while (%current_undef) {
|
|
%new_undef = ();
|
|
foreach my $sym (sort keys %current_undef) {
|
|
foreach my $file (@{$sym_objs{$sym}}) {
|
|
if (defined ($files_seen{$file})) {
|
|
next;
|
|
}
|
|
$files_seen{$file} = 1;
|
|
foreach my $ssym (@{$seen_syms{$file}}) {
|
|
if (!defined ($seen_where{$ssym})) {
|
|
$seen_where{$ssym} = "$current_undef{$sym} -> [$file] $ssym";
|
|
}
|
|
}
|
|
foreach my $usym (@{$strong_undef_syms{$file}}) {
|
|
if (!defined ($all_undef{$usym})) {
|
|
$all_undef{$usym} = "$current_undef{$sym} -> [$file] $usym";
|
|
$new_undef{$usym} = "$current_undef{$sym} -> [$file] $usym";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
%current_undef = %new_undef;
|
|
}
|
|
|
|
$ret = 0;
|
|
foreach my $sym (sort keys %seen_where) {
|
|
if ($sym =~ /^_/) {
|
|
next;
|
|
}
|
|
if (defined ($stdsyms{$sym})) {
|
|
next;
|
|
}
|
|
print "$seen_where{$sym}\n";
|
|
$ret = 1;
|
|
}
|
|
|
|
exit $ret;
|