From nobody Sun Feb 8 03:57:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568219323; cv=none; d=zoho.com; s=zohoarc; b=QKxZG3OPVcU7hHVVpUa7bjdN8mpY9+3mp9RYCFTMejWb/YTCg5MCqC4Ym3F1iJ6qv4FgzLc9jQJ7aFC0TL59i+DODUIqtP0yVu6Rd2DJ3hjOxeJr0xIm/4m2ZSg1omabj63MQ2omEvTNEULZv/b0xrKq3CXgId/zUzaOssox/d0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568219323; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=5TwPzFeiyAFzyh+2ZlgemWayWN4hN9bNAXJKUoIdNzA=; b=GIWAJJhyJ6XAcvewA8miogm/uFFpiqnvbyY+sa1Cw0srq0Qk5ZHCnGFi4gt2cgfn/+8nbVYVp32s+acKaqHtxEdkmYGsVxWMSLgbORcRF+tfU2wxdnTLrjJ3MObNr7Dv3FX3Fe6EyT11OkYroDRXUtgmhtP8qHhWiijyIuVTfVM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568219323127566.3663973972822; Wed, 11 Sep 2019 09:28:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F5B8A371AD; Wed, 11 Sep 2019 16:28:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B08E1F9; Wed, 11 Sep 2019 16:28:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C339E249B0; Wed, 11 Sep 2019 16:28:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8BGSLIZ013145 for ; Wed, 11 Sep 2019 12:28:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9890E6012A; Wed, 11 Sep 2019 16:28:21 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (dhcp-32.gsslab.fab.redhat.com [10.33.9.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08AE96017E; Wed, 11 Sep 2019 16:28:20 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 11 Sep 2019 17:23:21 +0100 Message-Id: <20190911162333.8668-13-berrange@redhat.com> In-Reply-To: <20190911162333.8668-1-berrange@redhat.com> References: <20190911162333.8668-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 12/24] src: rewrite symfile library checker in Python X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Wed, 11 Sep 2019 16:28:42 +0000 (UTC) As part of an goal to eliminate Perl from libvirt build tools, rewrite the check-symfile.pl tool in Python. This was a straight conversion, manually going line-by-line to change the syntax from Perl to Python. Thus the overall structure of the file and approach is the same. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/Makefile.am | 10 +++--- src/check-symfile.pl | 70 -------------------------------------- src/check-symfile.py | 80 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 75 deletions(-) delete mode 100755 src/check-symfile.pl create mode 100755 src/check-symfile.py diff --git a/src/Makefile.am b/src/Makefile.am index 4bdd16af22..a145f69140 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -275,11 +275,11 @@ PDWTAGS =3D \ # rule for libvirt.la. However, checking symbols relies on Linux ELF layo= ut if WITH_LINUX check-symfile: libvirt.syms libvirt.la - $(AM_V_GEN)$(PERL) $(srcdir)/check-symfile.pl libvirt.syms \ - .libs/libvirt.so + $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(srcdir)/check-symfile.py \ + libvirt.syms .libs/libvirt.so check-admin-symfile: libvirt_admin.syms libvirt-admin.la - $(AM_V_GEN)$(PERL) $(srcdir)/check-symfile.pl libvirt_admin.syms \ - .libs/libvirt-admin.so + $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(srcdir)/check-symfile.py \ + libvirt_admin.syms .libs/libvirt-admin.so else ! WITH_LINUX check-symfile: check-admin-symfile: @@ -290,7 +290,7 @@ check-symsorting: check-admin-symsorting: $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(srcdir)/check-symsorting.py \ $(srcdir) $(ADMIN_SYM_FILES) -EXTRA_DIST +=3D check-symfile.pl check-symsorting.py +EXTRA_DIST +=3D check-symfile.py check-symsorting.py =20 # Keep this list synced with RPC_PROBE_FILES PROTOCOL_STRUCTS =3D \ diff --git a/src/check-symfile.pl b/src/check-symfile.pl deleted file mode 100755 index 4f88300864..0000000000 --- a/src/check-symfile.pl +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2012-2013 Red Hat, Inc. -# -# This 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. -# -# This 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 this library. If not, see -# . - -die "syntax: $0 SYMFILE ELFLIB(S)" unless int(@ARGV) >=3D 2; - -my $symfile =3D shift @ARGV; -my @elflibs =3D @ARGV; - -my %wantsyms; -my %gotsyms; - -my $ret =3D 0; - -open SYMFILE, $symfile or die "cannot read $symfile: $!"; - -while () { - next if /{/; - next if /}/; - next if /global:/; - next if /local:/; - next if /^\s*$/; - next if /^\s*#/; - next if /\*/; - - die "malformed line $_" unless /^\s*(\S+);$/; - - if (exists $wantsyms{$1}) { - print STDERR "Symbol $1 is listed twice\n"; - $ret =3D 1; - } else { - $wantsyms{$1} =3D 1; - } -} -close SYMFILE; - -foreach my $elflib (@elflibs) { - open NM, "-|", "nm", $elflib or die "cannot run 'nm $elflib': $!"; - - while () { - next unless /^\S+\s(?:[TBD])\s(\S+)\s*$/; - - $gotsyms{$1} =3D 1; - } - - close NM; -} - -foreach my $sym (keys(%wantsyms)) { - next if exists $gotsyms{$sym}; - - print STDERR "Expected symbol $sym is not in ELF library\n"; - $ret =3D 1; -} - -exit($ret); diff --git a/src/check-symfile.py b/src/check-symfile.py new file mode 100755 index 0000000000..3154619bfe --- /dev/null +++ b/src/check-symfile.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +# +# Copyright (C) 2012-2019 Red Hat, Inc. +# +# This 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. +# +# This 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 this library. If not, see +# . + +from __future__ import print_function + +import re +import subprocess +import sys + +if len(sys.argv) < 3: + print("syntax: %s SYMFILE ELFLIB(S)" % sys.argv[0], file=3Dsys.stderr) + +symfile =3D sys.argv[1] +elflibs =3D sys.argv[2:] + +wantsyms =3D {} +gotsyms =3D {} + +ret =3D 0 + +with open(symfile, "r") as fh: + for line in fh: + line =3D line.strip() + if line.find("{") !=3D -1: + continue + if line.find("}") !=3D -1: + continue + if line in ["global:", "local:"]: + continue + if line =3D=3D "": + continue + if line[0] =3D=3D '#': + continue + if line.find("*") !=3D -1: + continue + + line =3D line.strip(";") + + if line in wantsyms: + print("Symbol $1 is listed twice", file=3Dsys.stderr) + ret =3D 1 + else: + wantsyms[line] =3D True + +for elflib in elflibs: + nm =3D subprocess.Popen(["nm", elflib], shell=3DFalse, stdout=3Dsubpro= cess.PIPE).stdout + + symprog =3D re.compile(r'''^\S+\s(?:[TBD])\s(\S+)\s*$''') + for line in nm: + line =3D line.decode("utf-8") + symmatch =3D symprog.match(line) + if symmatch is None: + continue + + gotsyms[symmatch.group(1)] =3D True + + +for sym in wantsyms.keys(): + if sym in gotsyms: + continue + + print("Expected symbol '%s' is not in ELF library" % sym, file=3Dsys.s= tderr) + ret =3D 1 + +sys.exit(ret) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list