summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorLagoLunatic <LagoLunatic@users.noreply.github.com>2025-12-15 20:08:14 -0500
committerGitHub <noreply@github.com>2025-12-15 17:08:14 -0800
commita11e3d6016a6eea4a90decd3e75500948f39f43a (patch)
treecdb54969fcaf9ed5782fb83d66b80c370b978e56 /tools
parentb9cb15ad981ac1da703d9f0bfd11de1a13d20bc4 (diff)
Fix bugs in weak_order_diff.py (#2955)
* Fix readelf path * Improve diffing of literal/in-function data order
Diffstat (limited to 'tools')
-rwxr-xr-xtools/utilities/weak_order_diff.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/tools/utilities/weak_order_diff.py b/tools/utilities/weak_order_diff.py
index fe2c786575..36d90d4d9f 100755
--- a/tools/utilities/weak_order_diff.py
+++ b/tools/utilities/weak_order_diff.py
@@ -1,12 +1,22 @@
#!/usr/bin/env python3
-from pathlib import Path
+import os
import re
+from pathlib import Path
import subprocess
from argparse import ArgumentParser
+
+def is_windows() -> bool:
+ return os.name == "nt"
+
+
+EXE = ".exe" if is_windows() else ""
+
+
def get_symbols(o_path: Path, diff_data: bool):
- output = subprocess.check_output(["readelf", "-Ws", o_path]).decode("ascii")
+ readelf_path = f"build/binutils/powerpc-eabi-readelf{EXE}"
+ output = subprocess.check_output([readelf_path, "-Ws", o_path]).decode("ascii")
symbols = []
for line in output.split("\n")[3:]:
if line == "":
@@ -25,10 +35,10 @@ def get_symbols(o_path: Path, diff_data: bool):
if vis == "HIDDEN":
continue
if re.search(r"^@\d+$", name):
- continue
+ name = "@"
if re.search(r"^lbl_[0-9a-f]+_(?:data|bss)_[0-9a-f]+$", name):
continue
- match = re.search(r"^(\S+)\$\d+$", name)
+ match = re.search(r"^(\S+\$)\d+$", name)
if match:
name = match.group(1)
else:
@@ -45,7 +55,9 @@ def get_symbols(o_path: Path, diff_data: bool):
return symbol_names
-def print_symbols_with_unmatched_order_for_object(relative_o_path: str, version: str, diff_data: bool):
+def print_symbols_with_unmatched_order_for_object(
+ relative_o_path: str, version: str, diff_data: bool
+):
target_o = Path("build") / version / "obj" / relative_o_path
base_o = Path("build") / version / "src" / relative_o_path
if not target_o.exists():
@@ -70,6 +82,8 @@ def print_symbols_with_unmatched_order_for_object(relative_o_path: str, version:
if target_sym == base_sym:
base_idx += 1
matched_count += 1
+ elif target_sym not in base_symbols:
+ print("MISSING SYMBOL:", target_sym)
else:
base_idx = base_symbols.index(target_sym)
base_idx += 1
@@ -81,12 +95,14 @@ def print_symbols_with_unmatched_order_for_object(relative_o_path: str, version:
def main():
- parser = ArgumentParser(description="Print differences in weak function order for an object.")
+ parser = ArgumentParser(
+ description="Print differences in weak function order for an object."
+ )
parser.add_argument(
"o_path",
type=str,
default="d/actor/d_a_alink.o",
- nargs='?',
+ nargs="?",
help="""relative path to the object file to diff (e.g. d/actor/d_a_alink.o).""",
)
parser.add_argument(
@@ -105,5 +121,6 @@ def main():
print_symbols_with_unmatched_order_for_object(args.o_path, args.version, args.data)
+
if __name__ == "__main__":
main()