Bug#718404: [PATCH] Don’t generate statically-linked-binary for golang packages
Package: lintian
Version: 2.5.15
Severity: wishlist
Tags: patch
The attached patch modifies lintian so that it will not generate
statically-linked-binary for every package built with golang-go.
This is preferable to adding override files in every package.
>From 05208d99ddb0afb68ae8affa1a7552231ed6276d Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Wed, 31 Jul 2013 10:28:10 +0200
Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20generate=20statically-linked-bina?=
=?UTF-8?q?ry=20for=20binary=20packages=20built=20with=20golang-go?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
checks/binaries.pm | 8 +++++
t/tests/binaries-golang/debian/Makefile | 48 +++++++++++++++++++++++++
t/tests/binaries-golang/debian/basic.c | 12 +++++++
t/tests/binaries-golang/debian/debian/control | 15 ++++++++
t/tests/binaries-golang/debian/debian/rules | 7 ++++
t/tests/binaries-golang/debian/getbuildid | 30 ++++++++++++++++
t/tests/binaries-golang/desc | 14 ++++++++
t/tests/binaries-golang/tags | 13 +++++++
8 files changed, 147 insertions(+)
create mode 100644 t/tests/binaries-golang/debian/Makefile
create mode 100644 t/tests/binaries-golang/debian/basic.c
create mode 100644 t/tests/binaries-golang/debian/debian/control
create mode 100644 t/tests/binaries-golang/debian/debian/rules
create mode 100755 t/tests/binaries-golang/debian/getbuildid
create mode 100644 t/tests/binaries-golang/desc
create mode 100644 t/tests/binaries-golang/tags
diff --git a/checks/binaries.pm b/checks/binaries.pm
index 80f0637..f26e809 100644
--- a/checks/binaries.pm
+++ b/checks/binaries.pm
@@ -225,6 +225,12 @@ for my $file ($info->sorted_index) {
$directories{"/$name"}++;
}
+my $src = $group->get_source_processable();
+my $built_with_golang;
+if (defined($src)) {
+ $built_with_golang = $src->info->relation('build-depends')->implies('golang-go');
+}
+
# process all files in package
foreach my $file ($info->sorted_index) {
my $fileinfo = $info->file_info ($file);
@@ -393,6 +399,8 @@ foreach my $file ($info->sorted_index) {
next if ($file =~ m%^boot/%);
next if ($file =~ /[\.-]static$/);
next if ($pkg =~ /-static$/);
+ # Binaries built by the Go compiler are statically linked by default.
+ next if ($built_with_golang);
# klibc binaries appear to be static.
next if (exists $objdump->{INTERP}
&& $objdump->{INTERP} =~ m,/lib/klibc-\S+\.so,);
diff --git a/t/tests/binaries-golang/debian/Makefile b/t/tests/binaries-golang/debian/Makefile
new file mode 100644
index 0000000..ac5bd0f
--- /dev/null
+++ b/t/tests/binaries-golang/debian/Makefile
@@ -0,0 +1,48 @@
+COMPILE:= $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
+# extract from readelf
+GETBUILDID:=./getbuildid
+
+all:
+ # rpath not matching any of the exceptions to the rpath checks
+ # - with profiling enabled.
+ $(COMPILE) -o basic basic.c -pg -Wl,--rpath,/usr/local/lib
+ # rpath shipped in the package, but one of {/usr}?/lib
+ $(COMPILE) -o basiclibrpath basic.c -Wl,--rpath,/usr/lib
+ # non-special rpath shipped in the package
+ $(COMPILE) -o basicshippedrpath basic.c -Wl,--rpath,/usr/share/foo
+ # static version of basic for debugging checks
+ $(COMPILE) -static -o basic.static basic.c
+ # version with debug
+ $(COMPILE) -o basicdebug -g3 -Wl,--build-id basic.c
+
+install:
+ # according to local debian rules /usr/lib/debug is unstripped
+ install -d $(DESTDIR)/usr/share/foo/
+ install -d $(DESTDIR)/usr/lib/debug/usr/share/foo/
+ install -d $(DESTDIR)/usr/lib/foo/
+ install -d $(DESTDIR)/usr/bin
+
+ install -m 755 -c basic $(DESTDIR)/usr/share/foo/basic
+ objcopy --only-keep-debug basic $(DESTDIR)/usr/lib/debug/usr/share/foo/basic
+ strip -s $(DESTDIR)/usr/lib/debug/usr/share/foo/basic
+ install -m 755 -c basiclibrpath $(DESTDIR)/usr/lib/foo/basiclibrpath
+ install -m 755 -c basicshippedrpath $(DESTDIR)/usr/lib/foo/basicshippedrpath
+ objcopy --only-keep-debug basic $(DESTDIR)/usr/lib/debug/basic
+ install -d "$(DESTDIR)/usr/lib/debug/.build-id/"`$(GETBUILDID) -s basicdebug`
+ install -m 755 -c basicdebug $(DESTDIR)/usr/share/foo/basicdebug
+ # force fake buildid in order to have tag matching ok (deadbeefdeadbeef)
+ install -d "$(DESTDIR)/usr/lib/debug/.build-id/de"
+ objcopy --compress-debug-sections basicdebug \
+ "$(DESTDIR)/usr/lib/debug/.build-id/de/deadbeefdeadbeef.debug"
+ install -d "$(DESTDIR)/usr/lib/debug/.build-id/"`$(GETBUILDID) -s basicdebug`
+ objcopy --compress-debug-sections --only-keep-debug basicdebug \
+ "$(DESTDIR)/usr/lib/debug/.build-id/"`$(GETBUILDID) -s basicdebug`"/"`$(GETBUILDID) -f basicdebug`.debug
+ install -m 755 -c basic.static $(DESTDIR)/usr/lib/debug/
+ # according to local debian rules unstripped in name avoid dh_strip to do the work
+ install -m 755 basicdebug $(DESTDIR)/usr/bin/unstripped
+ install -m 755 basic.static $(DESTDIR)/usr/bin/static
+
+clean distclean:
+ rm -f basic
+
+check test:
diff --git a/t/tests/binaries-golang/debian/basic.c b/t/tests/binaries-golang/debian/basic.c
new file mode 100644
index 0000000..7dea5a0
--- /dev/null
+++ b/t/tests/binaries-golang/debian/basic.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+int
+main(void)
+{
+ char t[10];
+ printf("Hello world!\n");
+ /* Bad choice for reading from stdin, but it forces a stack
+ protector, so meh.
+ */
+ gets (t);
+}
diff --git a/t/tests/binaries-golang/debian/debian/control b/t/tests/binaries-golang/debian/debian/control
new file mode 100644
index 0000000..662285f
--- /dev/null
+++ b/t/tests/binaries-golang/debian/debian/control
@@ -0,0 +1,15 @@
+Source: binaries-golang
+Priority: extra
+Section: devel
+Maintainer: Debian Lintian Maintainers <lintian-maint@debian.org>
+Standards-Version: 3.9.4
+Build-Depends: debhelper (>= 9), golang-go (>= 2:1.1.1-4)
+
+Package: binaries-golang
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: Test golang binaries
+ This is a test package designed to exercise some feature or tag of
+ Lintian. It is part of the Lintian test suite and may do very odd
+ things. It should not be installed like a regular package. It may
+ be an empty package.
diff --git a/t/tests/binaries-golang/debian/debian/rules b/t/tests/binaries-golang/debian/debian/rules
new file mode 100644
index 0000000..37608c2
--- /dev/null
+++ b/t/tests/binaries-golang/debian/debian/rules
@@ -0,0 +1,7 @@
+#!/usr/bin/make -f
+
+%:
+ dh $@
+
+override_dh_strip:
+ dh_strip -X usr/lib/debug -X unstripped
diff --git a/t/tests/binaries-golang/debian/getbuildid b/t/tests/binaries-golang/debian/getbuildid
new file mode 100755
index 0000000..0060d2b
--- /dev/null
+++ b/t/tests/binaries-golang/debian/getbuildid
@@ -0,0 +1,30 @@
+#!/bin/sh
+# get build-id of binary
+
+set -e
+
+usage() {
+ echo "Usage: getbuildid [flag] file";
+ echo " print build-id of an object file"
+ echo "flags:"
+ echo " -f : full build-id (default)."
+ echo " -s : short build-id aka the first two characters."
+}
+
+if test $# -lt 1; then usage; exit 77; fi
+if test $# -gt 3; then usage; exit 77; fi
+
+if test $# -eq 1; then
+ LC_ALL=C readelf -n "$1" | grep -i 'Build Id:' | sed 's/.*:[[:blank:]]*\([[:digit:]|abcdef]*\).*/\1/g'
+else
+ case "x$1" in
+ 'x-f')
+ LC_ALL=C readelf -n "$2" | grep -i 'Build Id:' | sed 's/.*:[[:blank:]]*\([[:digit:]|abcdef]*\).*/\1/g' ;;
+ 'x-s')
+ LC_ALL=C readelf -n "$2" | grep -i 'Build Id:' | sed 's/.*:[[:blank:]]*\([[:digit:]|abcdef]\{2\}\).*/\1/g' ;;
+ *)
+ exit 2;
+ esac
+fi
+
+exit 0;
diff --git a/t/tests/binaries-golang/desc b/t/tests/binaries-golang/desc
new file mode 100644
index 0000000..b7ba4de
--- /dev/null
+++ b/t/tests/binaries-golang/desc
@@ -0,0 +1,14 @@
+Testname: binaries-golang
+Sequence: 6000
+Version: 1.0
+Description: Misc errors related to golang binaries
+Architecture: any
+Test-For:
+ arch-dependent-file-in-usr-share
+ binary-compiled-with-profiling-enabled
+ binary-or-shlib-defines-rpath
+ debug-symbols-directly-in-usr-lib-debug
+ debug-file-should-use-detached-symbols
+ debug-file-with-no-debug-symbols
+ library-in-debug-or-profile-should-not-be-stripped
+ unstripped-binary-or-object
diff --git a/t/tests/binaries-golang/tags b/t/tests/binaries-golang/tags
new file mode 100644
index 0000000..3643b63
--- /dev/null
+++ b/t/tests/binaries-golang/tags
@@ -0,0 +1,13 @@
+E: binaries-golang: arch-dependent-file-in-usr-share usr/share/foo/basic
+E: binaries-golang: arch-dependent-file-in-usr-share usr/share/foo/basicdebug
+E: binaries-golang: binary-or-shlib-defines-rpath usr/lib/foo/basiclibrpath /usr/lib
+E: binaries-golang: binary-or-shlib-defines-rpath usr/share/foo/basic /usr/local/lib
+E: binaries-golang: debug-symbols-directly-in-usr-lib-debug usr/lib/debug/basic
+E: binaries-golang: library-in-debug-or-profile-should-not-be-stripped usr/lib/debug/usr/share/foo/basic
+E: binaries-golang: unstripped-binary-or-object usr/bin/unstripped
+W: binaries-golang: binary-compiled-with-profiling-enabled usr/share/foo/basic
+W: binaries-golang: binary-without-manpage usr/bin/static
+W: binaries-golang: binary-without-manpage usr/bin/unstripped
+W: binaries-golang: debug-file-should-use-detached-symbols usr/lib/debug/.build-id/de/deadbeefdeadbeef.debug
+W: binaries-golang: debug-file-with-no-debug-symbols usr/lib/debug/usr/share/foo/basic
+W: binaries-golang: debug-package-should-be-named-dbg usr/lib/debug/.build-id/
--
1.7.10.4
Reply to: