Public bug reported:

Ubuntu's debhelper delta "dh_strip: set a unique build-id before
stripping files" runs

  debugedit --build-id --build-id-seed=<pkg>/<version> <file>

on every unstripped ELF file. For files whose section header table is
not at the end of the file, which is what patchelf produces, debugedit
(via libelf) corrupts the file: all section headers are zeroed. dh_strip
then fails:

  objcopy: warning: 
debian/libfortran-testdrive-0/usr/lib/x86_64-linux-gnu/libtest-drive-gnu.so.0 
has a corrupt string table index
  objcopy: unable to modify '...' due to errors
  dh_strip: error: objcopy --only-keep-debug --compress-debug-sections ... 
returned exit code 1

Root cause in libelf/debugedit: LP: #2169676.

Affected: every package built with dh-fortran, because dh_fortran_lib
renames the shared libraries with "patchelf --set-soname" (fortran-
testdrive, fortran-jonquil, fortran-toml, ... in stonking-proposed; most
likely also cdo, which fails the same way on libcdi_f2003-gnu.so). Any
other package that patchelfs files before dh_strip is affected too.
Debian builds these packages fine because its dh_strip does not run
debugedit.

Workaround tested in a stonking container: in dh_strip, run debugedit on
a copy. If the copy is corrupted, rewrite the file with objcopy, which
moves the section header table to the end of the file, and run debugedit
again; only replace the file if the result is valid. With it, fortran-
testdrive 0.6.1-1, fortran-toml 0.5.2-1 and fortran-jonquil 0.3.2-1
build. The unique build-id is kept and the dbgsym packages are
generated.

--- a/dh_strip
+++ b/dh_strip
@@ -298,7 +298,26 @@
        return unless $file_info =~ /not stripped/;
 
        # set a uniqe build-id
-       doit("debugedit", "--build-id", "--build-id-seed=$seed", $file);
+       # debugedit (libelf) corrupts files whose section header table is not
+       # at the end of the file, as produced by patchelf.  Work on a copy and
+       # if it got corrupted, retry on a copy rewritten by objcopy, which
+       # moves the section header table to the end of the file.
+       my $tmpcopy = "$file.dh-debugedit";
+       my $elf_corrupt = sub {
+               system("readelf -S -W $tmpcopy 2>&1 | grep -q -e \"^readelf: 
\\(Error\\|Warning\\)\" -e \"<no-strings>\"") == 0;
+       };
+       doit("cp", "-a", $file, $tmpcopy);
+       doit("debugedit", "--build-id", "--build-id-seed=$seed", $tmpcopy);
+       if ($elf_corrupt->()) {
+               doit($objcopy, $file, $tmpcopy);
+               doit("debugedit", "--build-id", "--build-id-seed=$seed", 
$tmpcopy);
+       }
+       if ($elf_corrupt->()) {
+               warning("debugedit corrupted $file, not setting a unique 
build-id");
+               doit("rm", "-f", $tmpcopy);
+       } else {
+               doit("mv", $tmpcopy, $file);
+       }
        $file_info = get_file_type($file, 0); # get changed build-id
 
        if ($use_build_id) {

Once libelf/debugedit is fixed, this workaround can be dropped.

** Affects: debhelper (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: ftbfs update-excuse

** Tags added: update-excuse

** Tags added: ftbfs

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2169677

Title:
  dh_strip: Ubuntu's debugedit --build-id-seed step corrupts patchelf-
  modified ELF files, FTBFS in dh_strip (dh-fortran packages)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/debhelper/+bug/2169677/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to