[debhelper-devel] [debhelper] 01/01: Add new dh_dwz helper along with a "dwz" sequence
Niels Thykier
nthykier at moszumanska.debian.org
Tue Oct 24 18:34:15 UTC 2017
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository debhelper.
commit d538205512b9b56389d0979c0eb9614295a92b9b
Author: Niels Thykier <niels at thykier.net>
Date: Mon Oct 23 06:28:19 2017 +0000
Add new dh_dwz helper along with a "dwz" sequence
Signed-off-by: Niels Thykier <niels at thykier.net>
---
debian/changelog | 5 ++
dh_dwz | 129 +++++++++++++++++++++++++++++++++++
lib/Debian/Debhelper/Sequence/dwz.pm | 10 +++
3 files changed, 144 insertions(+)
diff --git a/debian/changelog b/debian/changelog
index c17641a..cd802ff 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,11 @@ debhelper (10.10.4) UNRELEASED; urgency=medium
called as otherwise ninja tries and fails to regenerate the
build rules. Thanks to Helmut Grohne for reporting the
bug. (Closes: #879658)
+ * dh_dwz: Add new experimental tool to run dwz(1) to deduplicate
+ ELF debugging symbols. It should be generally be run before
+ dh_strip (as dh_strip compresses the debug symbols and dwz
+ expects uncompressed debug symbols). (Closes: #878888)
+ * dwz.pm: New sequence to add dh_dwz to the sequence.
-- Niels Thykier <niels at thykier.net> Tue, 24 Oct 2017 05:45:09 +0000
diff --git a/dh_dwz b/dh_dwz
new file mode 100755
index 0000000..39844d4
--- /dev/null
+++ b/dh_dwz
@@ -0,0 +1,129 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+dh_dwz - optimize DWARF debug information in ELF binaries via dwz
+
+=cut
+
+use strict;
+use warnings;
+use File::Find;
+use Debian::Debhelper::Dh_Lib;
+
+our $VERSION = DH_BUILTIN_VERSION;
+
+=head1 SYNOPSIS
+
+B<dh_dwz> [S<I<debhelper options>>] [B<-X>I<item>] [S<B<--> I<params>>]
+
+=head1 DESCRIPTION
+
+B<Caveat>: This tool is experimental and may disappear or change
+behaviour without any notice.
+
+B<dh_dwz> is a debhelper program that will optimize the (uncompressed)
+size of the DWARF debug information in ELF binaries. It does so by
+running L<dwz(1)> on all the ELF binaries in the package.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-X>I<item>, B<--exclude=>I<item>
+
+Exclude files that contain I<item> anywhere in their filename from being
+stripped. You may use this option multiple times to build up a list of
+things to exclude.
+
+=item B<--> I<params>
+
+Pass I<params> to L<dwz(1)> when it processes ELF binaries. This is
+mostly useful for setting memory related parameters (e.g. -l and -L).
+
+=back
+
+=head1 NOTES
+
+If the B<DEB_BUILD_OPTIONS> environment variable contains B<nostrip>,
+nothing will be stripped, in accordance with Debian policy (section
+10.1 "Binaries").
+
+While this tool technically does not remove debug information from
+binaries, it is still skipped when the B<DEB_BUILD_OPTIONS>
+environment variable contains B<nostrip>. This is because B<nostrip>
+is often used to optimize build times (e.g. for "build and
+test"-cycles) rather than optimizing for size.
+
+=cut
+
+init();
+
+# This variable can be used to turn off stripping (see Policy).
+exit 0 if get_buildoption('nostrip');
+
+warning('This tool is experimental and may change (or be retired) without any notice');
+
+my @elf_files;
+
+sub testfile {
+ my $fn = $_;
+ return if -l $fn; # Always skip symlinks.
+
+ # See if we were asked to exclude this file.
+ # Note that we have to test on the full filename, including directory.
+ foreach my $f (@{$dh{EXCLUDE}}) {
+ if ($fn =~ m/\Q$f\E/) {
+ $File::Find::prune = 1 if -d _;
+ return;
+ }
+ }
+ return if -d _;
+ # Do not process output files from dwz
+ return if index($fn, '/debug/.dwz/') > -1;
+ if (is_so_or_exec_elf_file($fn)) {
+ push(@elf_files, $fn);
+ }
+ return;
+}
+
+for my $package (@{$dh{DOPACKAGES}}) {
+ my $tmp = tmpdir($package);
+
+ next if not -d $tmp;
+
+ @elf_files = ();
+ find({
+ wanted => \&testfile,
+ no_chdir => 1,
+ }, $tmp);
+ next if not @elf_files;
+ # Consistent order;
+ @elf_files = sort(@elf_files);
+ my ($unique_files, $hardlinks) = find_hardlinks(@elf_files);
+
+ # TODO: Support multifile (-m)
+
+ xargs($unique_files, 'dwz', '-q', @{$dh{U_PARAMS}}, '--');
+ # Now change over any files we can that used to be hard links so
+ # they are again.
+ for my $hardlink (keys %{$hardlinks}) {
+ my $target = $hardlinks->{$hardlink};
+ # Remove old file.
+ rm_files($hardlink);
+ # Make new hardlink.
+ doit('ln', '-f', $target, $hardlink);
+ }
+}
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+This program is a part of debhelper.
+
+=head1 AUTHOR
+
+Niels Thykier <niels at thykier.net>
+
+=cut
diff --git a/lib/Debian/Debhelper/Sequence/dwz.pm b/lib/Debian/Debhelper/Sequence/dwz.pm
new file mode 100644
index 0000000..cb3f19d
--- /dev/null
+++ b/lib/Debian/Debhelper/Sequence/dwz.pm
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+# Enable dh_dwz
+
+use strict;
+use warnings;
+use Debian::Debhelper::Dh_Lib qw(warning);
+
+warning('This sequence is experimental and may change (or be retired) without any notice');
+
+insert_before('dh_strip', 'dh_dwz');
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git
More information about the debhelper-devel
mailing list