patches for DPDK stable branches
 help / color / Atom feed
* [dpdk-stable] [PATCH] usertools: fix python 3 support of
@ 2019-09-06 12:19 Robin Jarry
  0 siblings, 0 replies; only message in thread
From: Robin Jarry @ 2019-09-06 12:19 UTC (permalink / raw)
  To: Neil Horman; +Cc: dev, John McNamara, stable, Olivier Matz

Running this script on ubuntu-18.04 with python 3 and pyelftools
installed produces no output but no error is reported neither:

  ~$ python3 usertools/ -r build/app/testpmd
  ~$ echo $?

While with python 2, it works:

  ~# python2 usertools/ -r build/app/testpmd
  {"pci_ids": [], "name": "dpio"}
  {"pci_ids": [], "name": "dpbp"}
  {"pci_ids": [], "name": "dpaa2_qdma"}

Looking in the code of pyelftools, ELFFile.get_section_by_name performs
a lookup in a _section_name_map dictionary which contains a mapping of
section names to section numbers. Section names are strings, not bytes.
We must not encode the string before using it as argument to this
function. Otherwise the lookup fails and the script assumes there is no
ELF section in the file. Then it exits without any error.

Also, section tags are strings, not bytes, fix the following error on
python 3:

  Traceback (most recent call last):
    File "usertools/", line 612, in <module>
    File "usertools/", line 601, in main
    File "usertools/", line 442, in
      rc = tag.needed.find(b"librte_pmd")
  TypeError: must be str, not bytes

Fixes: c67c9a5c646a ("tools: query binaries for HW and other support information")
Cc: Neil Horman <>
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: John McNamara <>

Signed-off-by: Robin Jarry <>
Reviewed-by: Olivier Matz <>
 usertools/ | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/usertools/ b/usertools/
index 03623d5b8b48..d2d4aa3c143f 100755
--- a/usertools/
+++ b/usertools/
@@ -14,7 +14,7 @@
 import string
 import sys
 from elftools.common.exceptions import ELFError
-from elftools.common.py3compat import (byte2int, bytes2str, str2bytes)
+from elftools.common.py3compat import (byte2int, bytes2str)
 from elftools.elf.elffile import ELFFile
 from optparse import OptionParser
@@ -267,7 +267,7 @@ def _section_from_spec(self, spec):
                 return None
         except ValueError:
             # Not a number. Must be a name then
-            return self.elffile.get_section_by_name(str2bytes(spec))
+            return self.elffile.get_section_by_name(spec)
     def pretty_print_pmdinfo(self, pmdinfo):
         global pcidb
@@ -439,7 +439,7 @@ def process_dt_needed_entries(self):
         for tag in dynsec.iter_tags():
             if tag.entry.d_tag == 'DT_NEEDED':
-                rc = tag.needed.find(b"librte_pmd")
+                rc = tag.needed.find("librte_pmd")
                 if (rc != -1):
                     library = search_file(tag.needed,
                                           runpath + ":" + ldlibpath +

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-06 12:19 [dpdk-stable] [PATCH] usertools: fix python 3 support of Robin Jarry

patches for DPDK stable branches

Archives are clonable:
	git clone --mirror stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ \
	public-inbox-index stable

Newsgroup available over NNTP:

AGPL code for this site: git clone public-inbox