Skip to contentSkip to conversation

buildtools: fix invalid symbols

PATCH Superseded Mingjin Ye 5 participants 11 messages Jun 27, 2024 – Jul 11, 2024

lore
Share & tools
lore

Mingjin Ye

author
#0 lore raw

PATCH 1/1 buildtools: fix invalid symbols

ELF files generated by higher version compilers wrap multiple symbols prefixed with "this_pmd_name".

This patch fixes the issue by filtering invalid symbols.

Bugzilla ID: 1466

Fixes 6c4bf8f42432 ("buildtools: add Python pmdinfogen")
---
 buildtools/pmdinfogen.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
buildtools/pmdinfogen.py +2 -1
index 2a44f17bda..6ea97caec7 100755
@@ -200,7 +200,8 @@ def dump(self, file):
 def load_drivers(image):
     drivers = []
     for symbol in image.find_by_prefix("this_pmd_name"):
-        drivers.append(Driver.load(image, symbol))
+        if len(symbol.string_value) != 0:
+            drivers.append(Driver.load(image, symbol))
     return drivers
 
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 19 lines · Mingjin Ye

ELF files generated by higher version compilers wrap multiple symbols prefixed with "this_pmd_name".

This patch fixes the issue by filtering invalid symbols.

Bugzilla ID: 1466

Fixes 6c4bf8f42432 ("buildtools: add Python pmdinfogen")
---
 buildtools/pmdinfogen.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
buildtools/pmdinfogen.py +0 -0
index 2a44f17bda..6ea97caec7 100755

buildtools/pmdinfogen.py def dump(self, file): · line 204

Quoted 6 lines
buildtools/pmdinfogen.py +2 -1
@@ -200,7 +200,8 @@ def dump(self, file):
 def load_drivers(image):
     drivers = []
     for symbol in image.find_by_prefix("this_pmd_name"):
-        drivers.append(Driver.load(image, symbol))
+        if len(symbol.string_value) != 0:
+            drivers.append(Driver.load(image, symbol))

One small suggestion. Empty strings evaluate to boolean false, so the condition can just be simplified to:

	if symbol.string_value:
	    drivers.append(....)

/Bruce

#2 lore raw
Quoted 31 lines · Bruce Richardson
Quoted 19 lines · Mingjin Ye

ELF files generated by higher version compilers wrap multiple symbols prefixed with "this_pmd_name".

This patch fixes the issue by filtering invalid symbols.

Bugzilla ID: 1466

Fixes 6c4bf8f42432 ("buildtools: add Python pmdinfogen")
---
 buildtools/pmdinfogen.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
buildtools/pmdinfogen.py +0 -0
index 2a44f17bda..6ea97caec7 100755

buildtools/pmdinfogen.py def dump(self, file): · line 204

Quoted 6 lines
buildtools/pmdinfogen.py +2 -1
@@ -200,7 +200,8 @@ def dump(self, file):
 def load_drivers(image):
     drivers = []
     for symbol in image.find_by_prefix("this_pmd_name"):
-        drivers.append(Driver.load(image, symbol))
+        if len(symbol.string_value) != 0:
+            drivers.append(Driver.load(image, symbol))

One small suggestion. Empty strings evaluate to boolean false, so the condition can just be simplified to:

Quoted 2 lines
        if symbol.string_value:
            drivers.append(....)

I have the same comment than what Ali tried with:
https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/

I would prefer we don't rely on the content of symbols (that we don't know anything about) when we can filter on the symbol names exactly which is something DPDK controls.

My suggestion is to filter symbol *names* with regex ^this_pmd_name[0-9]+$.

Signature · 1 line
David Marchand
#3 lore raw
In reply to Mingjin Ye
Quoted 11 lines · Mingjin Ye

ELF files generated by higher version compilers wrap multiple symbols prefixed with "this_pmd_name".

This patch fixes the issue by filtering invalid symbols.

Bugzilla ID: 1466

Fixes 6c4bf8f42432 ("buildtools: add Python pmdinfogen")

Is it the same issue as:
https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/
?

Signature · 1 line
David Marchand
author
#4 lore raw

PATCH v2 1/1 buildtools: fix invalid symbols

In reply to Mingjin Ye

Elf files generated by higher version compilers wrap multiple symbols prefixed with "this_pmd_name".

The patch uses the regex "^this_pmd_name[0-9]+$" to match the symbol name.

Bugzilla ID: 1466

Fixes 6c4bf8f42432 ("buildtools: add Python pmdinfogen")

---
v2: Use regex ^this_pmd_name[0-9]+$ to filter symbols *names*

---
 buildtools/pmdinfogen.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
buildtools/pmdinfogen.py +3 -2
index 2a44f17bda..0fbcc697ed 100755
@@ -6,6 +6,7 @@
 import argparse
 import ctypes
 import json
+import re
 import sys
 import tempfile
 
@@ -70,7 +71,7 @@ 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):
+            if re.match(prefix, symbol.name):
                 yield ELFSymbol(self._image, symbol)
 
 
@@ -199,7 +200,7 @@ def dump(self, file):
 
 def load_drivers(image):
     drivers = []
-    for symbol in image.find_by_prefix("this_pmd_name"):
+    for symbol in image.find_by_prefix("^this_pmd_name[0-9]+$"):
         drivers.append(Driver.load(image, symbol))
     return drivers
 
Signature · 1 line
2.25.1
Tested-by on v2 1/1
#5 lore raw
Quoted 14 lines

-----Original Message-----
From: Mingjin Ye <[email protected]>
Sent: Monday, July 1, 2024 6:33 PM
To: [email protected]
Cc: Ye, MingjinX <[email protected]>; [email protected]; Dmitry Kozlyuk <[email protected]>
Subject: [PATCH v2] buildtools: fix invalid symbols

Elf files generated by higher version compilers wrap multiple symbols prefixed with "this_pmd_name".

The patch uses the regex "^this_pmd_name[0-9]+$" to match the symbol name.

Quoted 8 lines

Bugzilla ID: 1466

Fixes 6c4bf8f42432 ("buildtools: add Python pmdinfogen")

---
v2: Use regex ^this_pmd_name[0-9]+$ to filter symbols *names*
---

#6 lore raw
In reply to Mingjin Ye

Adding Ali in the loop, as he was working on a similar patch.

buildtools/pmdinfogen.py def find_by_prefix(self, prefix):

Quoted 31 lines · Mingjin Ye

Elf files generated by higher version compilers wrap multiple symbols prefixed with "this_pmd_name".

The patch uses the regex "^this_pmd_name[0-9]+$" to match the symbol name.

Bugzilla ID: 1466

Fixes 6c4bf8f42432 ("buildtools: add Python pmdinfogen")

---
v2: Use regex ^this_pmd_name[0-9]+$ to filter symbols *names*

---
 buildtools/pmdinfogen.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
buildtools/pmdinfogen.py +1 -0
index 2a44f17bda..0fbcc697ed 100755
@@ -6,6 +6,7 @@
 import argparse
 import ctypes
 import json
+import re
 import sys
 import tempfile
 
@@ -70,7 +71,7 @@ def find_by_prefix(self, prefix):

This function does not find symbols with a prefix anymore... Please rename.

Quoted 9 lines
buildtools/pmdinfogen.py +1 -1
         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):
+            if re.match(prefix, symbol.name):
                 yield ELFSymbol(self._image, symbol)
 
 

buildtools/pmdinfogen.py def dump(self, file): · line 205

Quoted 7 lines
buildtools/pmdinfogen.py +1 -1
@@ -199,7 +200,7 @@ def dump(self, file):
 
 def load_drivers(image):
     drivers = []
-    for symbol in image.find_by_prefix("this_pmd_name"):
+    for symbol in image.find_by_prefix("^this_pmd_name[0-9]+$"):
         drivers.append(Driver.load(image, symbol))
     return drivers

The COFF implementation is probably broken by this change as it is still filtering symbols with a prefix.
Please update.

Signature · 1 line
David Marchand
author
#7 lore raw

PATCH v3 1/1 buildtools: fix invalid symbols

In reply to Mingjin Ye

In scenarios where a higher clang compiler is used and ASAN is enabled, the generated ELF file will additionally insert undefined debug symbols with the same prefix. This causes duplicate C code to be generated.

This patch fixes this issue by skipping the unspecified symbol type.

Fixes 6c4bf8f42432 ("buildtools: add Python pmdinfogen")
---
 buildtools/pmdinfogen.py | 3 +++
 1 file changed, 3 insertions(+)
buildtools/pmdinfogen.py +3 -0
index 2a44f17bda..9896f107dc 100755
@@ -70,6 +70,9 @@ 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)
+            # Skip unspecified symbol type
+            if symbol.entry.st_info['type'] == "STT_NOTYPE":
+                continue
             if symbol.name.startswith(prefix):
                 yield ELFSymbol(self._image, symbol)
 
Signature · 1 line
2.25.1
Tested-by on v3 1/1
#8 lore raw
Quoted 13 lines

-----Original Message-----
From: Mingjin Ye <[email protected]>
Sent: Friday, July 5, 2024 11:26 AM
To: [email protected]
Cc: [email protected]; Ali Alnubani <[email protected]>; Mingjin Ye <[email protected]>; [email protected]; Dmitry Kozlyuk <[email protected]>
Subject: [PATCH v3] buildtools: fix invalid symbols

In scenarios where a higher clang compiler is used and ASAN is enabled, the generated ELF file will additionally insert undefined debug symbols with the same prefix. This causes duplicate C code to be generated.

Quoted 7 lines

This patch fixes this issue by skipping the unspecified symbol type.

Fixes 6c4bf8f42432 ("buildtools: add Python pmdinfogen")

---

Can confirm it fixes the build failure in my environment, thanks Mingjin.

Regards,
Ali

Tested-by on v3 1/1
#9 lore raw
In reply to Mingjin Ye
Quoted 13 lines

-----Original Message-----
From: Mingjin Ye <[email protected]>
Sent: Friday, July 5, 2024 4:26 PM
To: [email protected]
Cc: Marchand, David <[email protected]>; [email protected]; Ye, MingjinX <[email protected]>; [email protected]; Dmitry Kozlyuk <[email protected]>
Subject: [PATCH v3] buildtools: fix invalid symbols

In scenarios where a higher clang compiler is used and ASAN is enabled, the generated ELF file will additionally insert undefined debug symbols with the same prefix. This causes duplicate C code to be generated.

Quoted 7 lines

This patch fixes this issue by skipping the unspecified symbol type.

Fixes 6c4bf8f42432 ("buildtools: add Python pmdinfogen")

---

#10 lore raw
In reply to Mingjin Ye
Quoted 6 lines · Mingjin Ye

In scenarios where a higher clang compiler is used and ASAN is enabled, the generated ELF file will additionally insert undefined debug symbols with the same prefix. This causes duplicate C code to be generated.

This patch fixes this issue by skipping the unspecified symbol type.

You did not reply to my comments on v3 and here we have a new hack. This hack is ugly and not future proof (I can imagine some other symbols may appear in the future. If those symbols are not of type "STT_NOTYPE" we will have to find another filter at this point...).

Please have a try with:
https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/

Thanks.

Signature · 1 line
David Marchand