This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=07df658150f5c6c9ad4e5e4ff287f7a1cd56b111

commit 07df658150f5c6c9ad4e5e4ff287f7a1cd56b111
Author: Guillem Jover <[email protected]>
AuthorDate: Wed Feb 22 01:36:29 2023 +0100

    Dpkg::Shlibs::Objdump: Switch get_format() to return a colon-separated 
string
    
    This makes debugging the format easier, as the string should be easier
    to understand than a string of hexadecimal bytes.
---
 scripts/Dpkg/Shlibs.pm         |  4 ++--
 scripts/Dpkg/Shlibs/Objdump.pm | 39 +++++++++++++++++++++++++++++++++++----
 scripts/dpkg-shlibdeps.pl      |  7 ++++---
 3 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/scripts/Dpkg/Shlibs.pm b/scripts/Dpkg/Shlibs.pm
index e367fc63c..938efed6e 100644
--- a/scripts/Dpkg/Shlibs.pm
+++ b/scripts/Dpkg/Shlibs.pm
@@ -186,8 +186,8 @@ sub find_library {
             } elsif ($format eq $libformat) {
                push @libs, canonpath("$checkdir/$lib");
            } else {
-               debug(1, "Skipping lib $checkdir/$lib, libabi=0x%s != 
objabi=0x%s",
-                     unpack('H*', $libformat), unpack('H*', $format));
+                debug(1, "Skipping lib $checkdir/$lib, libabi=<%s> != 
objabi=<%s>",
+                      $libformat, $format);
            }
        }
     }
diff --git a/scripts/Dpkg/Shlibs/Objdump.pm b/scripts/Dpkg/Shlibs/Objdump.pm
index a2f3aefcd..661d07424 100644
--- a/scripts/Dpkg/Shlibs/Objdump.pm
+++ b/scripts/Dpkg/Shlibs/Objdump.pm
@@ -166,6 +166,31 @@ use constant {
     EF_SH_MACH_MASK         => 0x0000001f,
 };
 
+# These map machine IDs to their name.
+my %elf_mach_name = (
+    EM_NONE()               => 'none',
+    EM_386()                => 'i386',
+    EM_68K()                => 'm68k',
+    EM_AARCH64()            => 'arm64',
+    EM_ALPHA()              => 'alpha',
+    EM_ARCV2()              => 'arcv2',
+    EM_ARM()                => 'arm',
+    EM_IA64()               => 'ia64',
+    EM_LOONGARCH()          => 'loong',
+    EM_MIPS()               => 'mips',
+    EM_NIOS32()             => 'nios2',
+    EM_OR1K()               => 'or1k',
+    EM_PARISC()             => 'hppa',
+    EM_PPC()                => 'ppc',
+    EM_PPC64()              => 'ppc64',
+    EM_RISCV()              => 'riscv',
+    EM_S390()               => 's390',
+    EM_SH()                 => 'sh',
+    EM_SPARC()              => 'sparc',
+    EM_SPARC64()            => 'sparc64',
+    EM_X86_64()             => 'amd64',
+);
+
 # These map alternative or old machine IDs to their canonical form.
 my %elf_mach_map = (
     EM_ALPHA_OLD()          => EM_ALPHA,
@@ -213,17 +238,22 @@ sub get_format {
     return unless $elf{magic} eq "\x7fELF";
     return unless $elf{vertype} == EV_CURRENT;
 
+    my %abi;
     my ($elf_word, $elf_endian);
     if ($elf{bits} == ELF_BITS_32) {
+        $abi{bits} = 32;
         $elf_word = 'L';
     } elsif ($elf{bits} == ELF_BITS_64) {
+        $abi{bits} = 64;
         $elf_word = 'Q';
     } else {
         return;
     }
     if ($elf{endian} == ELF_ORDER_2LSB) {
+        $abi{endian} = 'l';
         $elf_endian = '<';
     } elsif ($elf{endian} == ELF_ORDER_2MSB) {
+        $abi{endian} = 'b';
         $elf_endian = '>';
     } else {
         return;
@@ -235,13 +265,14 @@ sub get_format {
 
     # Canonicalize the machine ID.
     $elf{mach} = $elf_mach_map{$elf{mach}} // $elf{mach};
+    $abi{mach} = $elf_mach_name{$elf{mach}} // $elf{mach};
 
     # Mask any processor flags that might not change the architecture ABI.
-    $elf{flags} &= $elf_flags_mask{$elf{mach}} // 0;
+    $abi{flags} = $elf{flags} & ($elf_flags_mask{$elf{mach}} // 0);
 
-    # Repack for easy comparison, as a big-endian byte stream, so that
-    # unpacking for output gives meaningful results.
-    $format{$file} = pack 'C2(SL)>', @elf{qw(bits endian mach flags)};
+    # Normalize into a colon-separated string for easy comparison, and easy
+    # debugging aid.
+    $format{$file} = join ':', 'ELF', @abi{qw(bits endian mach flags)};
 
     return $format{$file};
 }
diff --git a/scripts/dpkg-shlibdeps.pl b/scripts/dpkg-shlibdeps.pl
index 2fc31a83f..ade77de0d 100755
--- a/scripts/dpkg-shlibdeps.pl
+++ b/scripts/dpkg-shlibdeps.pl
@@ -202,12 +202,13 @@ foreach my $file (keys %exec) {
            $global_soname_notfound{$soname} = 1;
            my $msg = g_('cannot find library %s needed by %s (ELF ' .
                         "format: '%s' abi: '%s'; RPATH: '%s')");
-           my $exec_abi = unpack 'H*', $obj->{exec_abi};
            if (scalar(split_soname($soname))) {
-               errormsg($msg, $soname, $file, $obj->{format}, $exec_abi, 
join(':', @{$obj->{RPATH}}));
+                errormsg($msg, $soname, $file, $obj->{format}, 
$obj->{exec_abi},
+                         join(':', @{$obj->{RPATH}}));
                $error_count++;
            } else {
-               warning($msg, $soname, $file, $obj->{format}, $exec_abi, 
join(':', @{$obj->{RPATH}}));
+                warning($msg, $soname, $file, $obj->{format}, $obj->{exec_abi},
+                        join(':', @{$obj->{RPATH}}));
            }
            next;
        }

-- 
Dpkg.Org's dpkg

Reply via email to