From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
To: dev@dpdk.org
Cc: Ali Alnubani <alialnu@nvidia.com>,
Bruce Richardson <bruce.richardson@intel.com>,
Thomas Monjalon <thomas@monjalon.net>,
Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
Neil Horman <nhorman@tuxdriver.com>
Subject: [dpdk-dev] [PATCH 1/3] pmdinfogen: fix build with pyelftools < 0.24
Date: Tue, 26 Jan 2021 01:12:48 +0300 [thread overview]
Message-ID: <20210125221251.19147-2-dmitry.kozliuk@gmail.com> (raw)
In-Reply-To: <20210125221251.19147-1-dmitry.kozliuk@gmail.com>
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 <dmitry.kozliuk@gmail.com>
---
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
next prev parent reply other threads:[~2021-01-25 22:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-25 22:12 [dpdk-dev] [PATCH 0/3] pmdinfogen fixes Dmitry Kozlyuk
2021-01-25 22:12 ` Dmitry Kozlyuk [this message]
2021-01-25 22:12 ` [dpdk-dev] [PATCH 2/3] buildtools: fix archive extraction for Python 3.5 Dmitry Kozlyuk
2021-01-25 22:12 ` [dpdk-dev] [PATCH 3/3] buildtools: use build subdirectory for temporary files Dmitry Kozlyuk
2021-01-25 23:44 ` [dpdk-dev] [PATCH 0/3] pmdinfogen fixes Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210125221251.19147-2-dmitry.kozliuk@gmail.com \
--to=dmitry.kozliuk@gmail.com \
--cc=alialnu@nvidia.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=nhorman@tuxdriver.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.