From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 31BA4A052A; Mon, 25 Jan 2021 23:13:14 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 582831411AE; Mon, 25 Jan 2021 23:13:08 +0100 (CET) Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by mails.dpdk.org (Postfix) with ESMTP id 7A0A814117E for ; Mon, 25 Jan 2021 23:13:06 +0100 (CET) Received: by mail-lj1-f172.google.com with SMTP id u11so17227503ljo.13 for ; Mon, 25 Jan 2021 14:13:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2CDwtKlfrd2aL+D5Bpa+F0L6hfk8gqxP3AGZ7G2I7h8=; b=NawQ9XYI4tihb2M0jLKEJmSdeEDsbIj9Z4iGEApt+C3P2f/uSD77jDNHlIocatPFcG 2NvbyFinxeQgOc/M9re13lu/fWz3f6cBIgQt4gh3n70MVZWoeWKi1ItsJEqluWpxQ+pD 5lQFZkt+9MwUo56zfVP1nLfYU7RtiAUSmDgzqVROBN5ja+s/6pqLg9xGMqTWGpdBfQ2m 5B/9RoI5u6SC4H5LCOxevtwZdhRttLXLbF+psboYn4r3UZ8P8Bbpo6ITAoBjFjpqd7pp jeBzt1PtyeJM7DAepEQs2THOBKN4jAgxE7RC2COZLaSeCWUs9bvQJGPL26t7zomm0ZOU m7aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2CDwtKlfrd2aL+D5Bpa+F0L6hfk8gqxP3AGZ7G2I7h8=; b=MVPr5I6YXz8hgVejhDrOTp38M3HuRlT5dmo1fkAjMn42xtAqJftNyodnQIcKL0Hdkb 9I6Kd+BqrEpKyULFGbcCY8C1AWtkypqJ7Ig7EsTH1DAV0O2HsRz4PBPYU6UV8XRWjUaU S2OsN/xEB8ekAnuPZn5II918nnBRKO+jIgoRF0pM15U2RjLZmlP81DJBedJqunsiZ2SU B0OiQXyPS+zNbU6RjxBF+n0pNYEiFKdLt5tcixw+t61BVQHfV5A1OUmVj6xcMUhw4MrL V8ehYgOLdbqEKbp4t5ELaILp7vmVZ/Q7nlmA78hgPs+6pVjkv7EjtBpiI2PZt4qejVy6 NFUA== X-Gm-Message-State: AOAM531Iwp4IJdD/xOdfWDLCEh54E4xPSJS7GhmkLkDIFrTM1T4tHBbA ePjFpso/Ke+OaGsEdMZII/KESxGcxd8= X-Google-Smtp-Source: ABdhPJyTIEwsWrnlK83BJWTN1q5yS44Dj6/WNe5KiabyjdmDoDFvQZa3jxxDektc7Vo9NQoDDGWN8g== X-Received: by 2002:a2e:3e05:: with SMTP id l5mr1313628lja.54.1611612785751; Mon, 25 Jan 2021 14:13:05 -0800 (PST) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id w2sm533831lfd.305.2021.01.25.14.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jan 2021 14:13:05 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Ali Alnubani , Bruce Richardson , Thomas Monjalon , Dmitry Kozlyuk , Neil Horman Date: Tue, 26 Jan 2021 01:12:48 +0300 Message-Id: <20210125221251.19147-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210125221251.19147-1-dmitry.kozliuk@gmail.com> References: <20210125221251.19147-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 1/3] pmdinfogen: fix build with pyelftools < 0.24 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" pyelftools had some breaking changes [1] and API enhancements [2] between 0.23 (used in Ubuntu 16.04) and 0.24. Ensure compatibility with both legacy and modern versions. [1]: https://github.com/eliben/pyelftools/pull/76 [2]: https://github.com/eliben/pyelftools/pull/56 Signed-off-by: Dmitry Kozlyuk --- To be squashed with 043e0ba6c ("buildtools: add Python pmdinfogen"). buildtools/pmdinfogen.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/buildtools/pmdinfogen.py b/buildtools/pmdinfogen.py index 893a6c571..7a739ec7d 100755 --- a/buildtools/pmdinfogen.py +++ b/buildtools/pmdinfogen.py @@ -10,6 +10,7 @@ import tempfile try: + import elftools from elftools.elf.elffile import ELFFile from elftools.elf.sections import SymbolTableSection except ImportError: @@ -38,8 +39,13 @@ def get_value(self, offset, size): class ELFImage: def __init__(self, data): + version = tuple(int(c) for c in elftools.__version__.split(".")) + self._legacy_elftools = version < (0, 24) + self._image = ELFFile(data) - self._symtab = self._image.get_section_by_name(".symtab") + + section = b".symtab" if self._legacy_elftools else ".symtab" + self._symtab = self._image.get_section_by_name(section) if not isinstance(self._symtab, SymbolTableSection): raise Exception(".symtab section is not a symbol table") @@ -48,10 +54,20 @@ def is_big_endian(self): return not self._image.little_endian def find_by_name(self, name): - symbol = self._symtab.get_symbol_by_name(name) + symbol = self._get_symbol_by_name(name) return ELFSymbol(self._image, symbol[0]) if symbol else None + def _get_symbol_by_name(self, name): + if not self._legacy_elftools: + return self._symtab.get_symbol_by_name(name) + name = name.encode("utf-8") + for symbol in self._symtab.iter_symbols(): + if symbol.name == name: + return [symbol] + return None + def find_by_prefix(self, prefix): + prefix = prefix.encode("utf-8") if self._legacy_elftools else prefix for i in range(self._symtab.num_symbols()): symbol = self._symtab.get_symbol(i) if symbol.name.startswith(prefix): -- 2.29.2