rpm-build/scripts/provided_symbols
Gleb Fotengauer-Malinovskiy 051d1fee67 scripts/provided_symbols: use elfutils' readelf instead of binutils' one
This script is designed to ignore lines that don't follow the expected
format, but it is widely known that the output format of readelf utility
from the binutils project can be quite unreliable.  The output format
may vary on certain architectures and ELFs created with certain build
tools may contain symbols with peculiar bits that affect the output.

Here is a couple of examples illustrating these issues:
* On PowerPC, ELF symbols frequently include the localentry bit.
  For instance:
$ readelf --wide --dyn-syms /lib64/libcrypto.so.1.1  | grep ASN1_VISIBLESTRING_new
   157: 00000000000938c0    60 FUNC    GLOBAL DEFAULT [<localentry>: 8]    11 ASN1_VISIBLESTRING_new@@OPENSSL_1_1_0
* On x86_64, a proprietary blob /usr/lib64/libjcPKCS11ds.so (distributed
  as an ELF) and on armh /usr/lib/libLLVM-16.so, contain symbols with
  OS-specific bits:
$ readelf --wide --dyn-syms /usr/lib64/libjcPKCS11ds.so | grep _ZNSt7collateIwE2idE
  2572: 00000000002df9c8     8 OBJECT  <OS specific>: 10 DEFAULT   26 _ZNSt7collateIwE2idE
$ readelf --wide --dyn-syms /usr/lib/libLLVM-16.so | grep _ZN4llvm13AllAnalysesOnINS_6ModuleEE6SetKeyE
 45060: 05af0478     8 OBJECT  <OS specific>: 10 DEFAULT   26 _ZN4llvm13AllAnalysesOnINS_6ModuleEE6SetKeyE@@LLVM_16

The issue related to PowerPC localentry bits was resolved in the commit
4f4a1d146 ("lib.prov, lib.req: enhance ProvidedSymbols") a long time
ago.  The issue related to OS-specific bits was discovered recently [1].

Instead of attempting to resolve the output issues of binutils' readelf
utility concerning OS-specific bits, it is more convenient to use
readelf from elfutils.  It has more reliable output (including the
handling of the cases described earlier) and is extensively utilized
within the project anyway.

[1] https://bugzilla.altlinux.org/46447

Reported-by: Konstantin A. Lepikhov <lakostis@altlinux.ru>
Reported-by: Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
Fixes: https://bugzilla.altlinux.org/46447
2023-06-08 05:00:00 +00:00

37 lines
1.1 KiB
Bash
Executable File

#!/bin/sh -efu
#
# Copyright (C) 2010-2011 Alexey Tourbin <at@altlinux.org>
# Copyright (C) 2018 Dmitry V. Levin <ldv@altlinux.org>
# Copyright (C) 2018 Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
# All rights reserved.
#
# SPDX-License-Identifier: GPL-2.0-or-later
export LC_ALL=C
eu-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" || $4 == "GNU_IFUNC") &&
# dl-lookup.c: /hidden
($6=="DEFAULT" || $6=="PROTECTED") &&
# dl-lookup.c: /switch.*ST_BIND
($5 == "GLOBAL" || $5 == "WEAK" || $5 == "UNIQUE" || $5 == "GNU_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