about summary refs log tree commit diff
path: root/elf/tst-glibcelf.py
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2022-08-19 11:16:32 +0200
committerFlorian Weimer <fweimer@redhat.com>2022-08-23 19:33:38 +0200
commitbd13cb19f5e15e9e9a92a536e755fd93a97a67f6 (patch)
treeb1ab4c7e4bc89fe2c1e894702d5b335eb622808b /elf/tst-glibcelf.py
parentaf6b1cce9812273c7f597be6536d28eaec6fb89b (diff)
downloadglibc-bd13cb19f5e15e9e9a92a536e755fd93a97a67f6.tar.gz
glibc-bd13cb19f5e15e9e9a92a536e755fd93a97a67f6.tar.xz
glibc-bd13cb19f5e15e9e9a92a536e755fd93a97a67f6.zip
scripts/glibcelf.py: Add hashing support
ELF and GNU hashes can now be computed using the elf_hash and
gnu_hash functions.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'elf/tst-glibcelf.py')
-rw-r--r--elf/tst-glibcelf.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/elf/tst-glibcelf.py b/elf/tst-glibcelf.py
index bf15a3bad4..e5026e2289 100644
--- a/elf/tst-glibcelf.py
+++ b/elf/tst-glibcelf.py
@@ -240,6 +240,24 @@ def check_constant_values(cc):
             error('{}: glibcelf has {!r}, <elf.h> has {!r}'.format(
                 name, glibcelf_value, elf_h_value))
 
+def check_hashes():
+    for name, expected_elf, expected_gnu in (
+            ('', 0, 0x1505),
+            ('PPPPPPPPPPPP', 0, 0x9f105c45),
+            ('GLIBC_2.0', 0xd696910, 0xf66c3dd5),
+            ('GLIBC_2.34', 0x69691b4, 0xc3f3f90c),
+            ('GLIBC_PRIVATE', 0x963cf85, 0x692a260)):
+        for convert in (lambda x: x, lambda x: x.encode('UTF-8')):
+            name = convert(name)
+            actual_elf = glibcelf.elf_hash(name)
+            if actual_elf != expected_elf:
+                error('elf_hash({!r}): {:x} != 0x{:x}'.format(
+                    name, actual_elf, expected_elf))
+            actual_gnu = glibcelf.gnu_hash(name)
+            if actual_gnu != expected_gnu:
+                error('gnu_hash({!r}): {:x} != 0x{:x}'.format(
+                    name, actual_gnu, expected_gnu))
+
 def main():
     """The main entry point."""
     parser = argparse.ArgumentParser(
@@ -251,6 +269,7 @@ def main():
     check_duplicates()
     check_constant_prefixes()
     check_constant_values(cc=args.cc)
+    check_hashes()
 
     if errors_encountered > 0:
         print("note: errors encountered:", errors_encountered)