From 2107482334fe99ce2d3e03dd18bcbd8a00a726a2 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 14 Jan 2019 20:56:55 +0000 Subject: [PATCH] scripts: move ProvidedSymbols() and SuggestBPP() to separate files ProvidedSymbols() used to be defined both in lib.prov.in and lib.req.in, fix this code duplication by moving ProvidedSymbols() to separate provided_symbols executable script. Likewise, SuggestBPP() used to be defined both in lib.prov.in and lib.req.in, fix this code duplication by moving SuggestBPP() to separate suggest_bpp executable script. --- rpm-4_0.spec | 2 ++ scripts/Makefile.am | 2 ++ scripts/lib.prov.in | 42 +++------------------------------------- scripts/lib.req.in | 42 +++------------------------------------- scripts/provided_symbols | 35 +++++++++++++++++++++++++++++++++ scripts/suggest_bpp | 11 +++++++++++ 6 files changed, 56 insertions(+), 78 deletions(-) create mode 100755 scripts/provided_symbols create mode 100755 scripts/suggest_bpp diff --git a/rpm-4_0.spec b/rpm-4_0.spec index d6c5531..827bef9 100644 --- a/rpm-4_0.spec +++ b/rpm-4_0.spec @@ -475,10 +475,12 @@ mv -T %buildroot%_rpmlibdir/{,build}macros %rpmattr %_rpmlibdir/percolate %rpmattr %_rpmlibdir/pkgconfig.* %rpmattr %_rpmlibdir/pkgconfiglib.* +%rpmattr %_rpmlibdir/provided_symbols %rpmattr %_rpmlibdir/rpmlib.* %rpmattr %_rpmlibdir/shell.* %rpmattr %_rpmlibdir/shebang.* %rpmattr %_rpmlibdir/static.* +%rpmattr %_rpmlibdir/suggest_bpp %rpmattr %_rpmlibdir/symlinks.* %rpmattr %_rpmlibdir/tmpdir.sh %rpmattr %_rpmlibdir/verify-elf diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 066fdd3..49c2c0c 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -20,6 +20,7 @@ EXTRA_DIST = \ files.req files.req.files 0common-files.req.list \ is_elf_so_executable \ ldd lib.req lib.req.files lib.prov lib.prov.files shlib.req.awk \ + provided_symbols suggest_bpp \ pam.req pam.req.files pam.prov pam.prov.files \ percolate \ pkgconfig.req pkgconfiglib.req pkgconfig.req.files \ @@ -51,6 +52,7 @@ config_SCRIPTS = \ files.req files.req.files \ is_elf_so_executable \ ldd lib.req lib.req.files lib.prov lib.prov.files shlib.req.awk \ + provided_symbols suggest_bpp \ pam.req pam.req.files pam.prov pam.prov.files \ pkgconfig.req pkgconfiglib.req pkgconfig.req.files \ percolate \ diff --git a/scripts/lib.prov.in b/scripts/lib.prov.in index 61e9ee1..f41758a 100755 --- a/scripts/lib.prov.in +++ b/scripts/lib.prov.in @@ -1,6 +1,6 @@ #!/bin/sh -efu # -# Copyright (C) 2000-2006 Dmitry V. Levin +# Copyright (C) 2000-2019 Dmitry V. Levin # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -99,12 +99,12 @@ LibProv() printf '%s\n' "$provname" return 0 fi - local sym="$(ProvidedSymbols "$f")" + local sym="$(@RPMCONFIGDIR@/provided_symbols "$f")" if [ -n "$sym" ]; then local n bpp set n=$(printf '%s\n' "$sym" |wc -l) Verbose "$f: $n symbols" - bpp=$(SuggestBPP "$n") + bpp=$(@RPMCONFIGDIR@/suggest_bpp "$n") set=$(printf '%s\n' "$sym" |@RPMCONFIGDIR@/mkset "$bpp") printf '%s = %s\n' "$provname" "$set" else @@ -113,40 +113,4 @@ LibProv() fi } -ProvidedSymbols() -{ - readelf --wide --dyn-syms "$1" | - awk '+$1 && NF>=8 && -# dl-lookup.c: /st_value -($2!="00000000" && $2!="0000000000000000" || $4=="TLS") && -# dl-lookup.c: /ALLOWED_STT -($4=="NOTYPE" || $4=="OBJECT" || $4 == "FUNC" || $4=="COMMON" || $4=="TLS" || $4=="IFUNC") && -# dl-lookup.c: /hidden -($6=="DEFAULT" || $6=="PROTECTED") && -# dl-lookup.c: /switch.*ST_BIND -($5=="GLOBAL" || $5=="WEAK" || $5 == "UNIQUE") { - # dl-lookup.c: /st_shndx - match($0, "[[:space:]][[:digit:]]+[[:space:]]+([^[:space:]()@]+)(@+[^[:space:]()@]+)?$", a) - sym = a[1] - if (sym == "" || - # ignore special symbols found in each library - sym == "__bss_start" || - sym == "_edata" || - sym == "_end" || - sym == "_fini" || - sym == "_init") - next - print sym -}' | - LC_ALL=C sort -u -} - -SuggestBPP() -{ - # For the number of symbols in the range 2^{m-1}..2^m-1, - # use m+10 bits per symbol. Upper bound on the error rate - # is 2^{-10} (about 0.1%). - perl -le 'print int log(shift) / log(2) + 11' "$1" -} - ArgvFileAction LibProv "$@" diff --git a/scripts/lib.req.in b/scripts/lib.req.in index 1410221..31758ae 100755 --- a/scripts/lib.req.in +++ b/scripts/lib.req.in @@ -1,6 +1,6 @@ #!/bin/sh -efu # -# Copyright (C) 2000-2006,2008 Dmitry V. Levin +# Copyright (C) 2000-2019 Dmitry V. Levin # Copyright (C) 2007-2010 Alexey Tourbin # # This program is free software; you can redistribute it and/or modify @@ -217,42 +217,6 @@ NF==2 && ($1==name || basename($1)==name) && $1~"^/" && $2~"^[(]0x" {print $1} LC_ALL=C sort -t$'\t' -m -u -k2,2 -k1,1 -o "$tmpdir"/sym2lib{,} "$tmpdir"/a/sym2lib } -ProvidedSymbols() -{ - readelf --wide --dyn-syms "$1" | - awk '+$1 && NF>=8 && -# dl-lookup.c: /st_value -($2!="00000000" && $2!="0000000000000000" || $4=="TLS") && -# dl-lookup.c: /ALLOWED_STT -($4=="NOTYPE" || $4=="OBJECT" || $4 == "FUNC" || $4=="COMMON" || $4=="TLS" || $4=="IFUNC") && -# dl-lookup.c: /hidden -($6=="DEFAULT" || $6=="PROTECTED") && -# dl-lookup.c: /switch.*ST_BIND -($5=="GLOBAL" || $5=="WEAK" || $5 == "UNIQUE") { - # dl-lookup.c: /st_shndx - match($0, "[[:space:]][[:digit:]]+[[:space:]]+([^[:space:]()@]+)(@+[^[:space:]()@]+)?$", a) - sym = a[1] - if (sym == "" || - # ignore special symbols found in each library - sym == "__bss_start" || - sym == "_edata" || - sym == "_end" || - sym == "_fini" || - sym == "_init") - next - print sym -}' | - LC_ALL=C sort -u -} - -SuggestBPP() -{ - # For the number of symbols in the range 2^{m-1}..2^m-1, - # use m+10 bits per symbol. Upper bound on the error rate - # is 2^{-10} (about 0.1%). - perl -le 'print int log(shift) / log(2) + 11' "$1" -} - ArgvFileAction LibReq "$@" [ -s "$tmpdir"/lib2dep ] || exit 0 @@ -286,10 +250,10 @@ while IFS=$'\t' read -r lib dep; do continue fi # Deal with bpp. - provsym=$(ProvidedSymbols "$lib") + provsym=$(@RPMCONFIGDIR@/provided_symbols "$lib") if [ -n "$provsym" ]; then provn=$(printf '%s\n' "$provsym" |wc -l) - bpp=$(SuggestBPP "$provn") + bpp=$(@RPMCONFIGDIR@/suggest_bpp "$provn") else Warning "$lib provides no symbols" bpp=10 diff --git a/scripts/provided_symbols b/scripts/provided_symbols new file mode 100755 index 0000000..ab3686d --- /dev/null +++ b/scripts/provided_symbols @@ -0,0 +1,35 @@ +#!/bin/sh -efu +# +# Copyright (C) 2010-2011 Alexey Tourbin +# Copyright (C) 2018 Dmitry V. Levin +# Copyright (C) 2018 Gleb Fotengauer-Malinovskiy +# All rights reserved. +# +# SPDX-License-Identifier: GPL-2.0-or-later + +export LC_ALL=C + +readelf --wide --dyn-syms -- "$@" | + awk '+$1 && NF>=8 && +# dl-lookup.c: /st_value +($2!="00000000" && $2!="0000000000000000" || $4=="TLS") && +# dl-lookup.c: /ALLOWED_STT +($4=="NOTYPE" || $4=="OBJECT" || $4 == "FUNC" || $4=="COMMON" || $4=="TLS" || $4=="IFUNC") && +# dl-lookup.c: /hidden +($6=="DEFAULT" || $6=="PROTECTED") && +# dl-lookup.c: /switch.*ST_BIND +($5=="GLOBAL" || $5=="WEAK" || $5 == "UNIQUE") { + # dl-lookup.c: /st_shndx + match($0, "[[:space:]][[:digit:]]+[[:space:]]+([^[:space:]()@]+)(@+[^[:space:]()@]+)?$", a) + sym = a[1] + if (sym == "" || + # ignore special symbols found in each library + sym == "__bss_start" || + sym == "_edata" || + sym == "_end" || + sym == "_fini" || + sym == "_init") + next + print sym +}' | + sort -u diff --git a/scripts/suggest_bpp b/scripts/suggest_bpp new file mode 100755 index 0000000..e82195f --- /dev/null +++ b/scripts/suggest_bpp @@ -0,0 +1,11 @@ +#!/bin/sh -efu +# +# Copyright (C) 2010 Alexey Tourbin +# All rights reserved. +# +# SPDX-License-Identifier: GPL-2.0-or-later + +# For the number of symbols in the range 2^{m-1}..2^m-1, +# use m+10 bits per symbol. Upper bound on the error rate +# is 2^{-10} (about 0.1%). +exec perl -le 'print int log(shift) / log(2) + 11' "$1"