Package: perl
Version: 5.24.1-3+deb9u1
Severity: normal
Tags: upstream patch


Cross-building perl fails unless there is a copy of errno.h in
/usr/include or /usr/local/include. These are almost certainly
build-arch files unless you are building in a sysroot. The code is
essentially assuming a non-multiarch layout and the use of a
sysroot. When the sysroot is '' (as it is when crossing on debian)
this picks up the potentially wrong-arch errno.h of the build system.

The offending code is:
  my ($linux_errno_h) = grep { -e $_ } map { "$_/errno.h" }
      "$sysroot/usr/include", "$sysroot/usr/local/include",
      split / / => $Config{locincpth} or
          die "Cannot find errno.h";
in ext/Error/Errno_pm.PL

For glibc-only systems this assumption does not break anything because
errno.h does not change by architecture. Nevertheless this is not
robust, and will break if/when #798955 is implemented. 

On a Debian (i.e. multiarch) system a search for header files should
look in /usr/include/$DEB_HOST_MULTIARCH before /usr/include. Once
798955 is implemented, looking in /usr/include is arguably incorrect,
although $sysroot/usr/include still makes sense

There is no obvious variable in the config file to set up this
search. The closest is incpth, and using that does work, which is what
the attached patch does. I'm not sure that it is really the optimum
include path set to search. Possibly yet another config option for
this would be the right thing to do. Better would be defining one for
$DEB_HOST_MULTIARCH so the path can be composed. 

I noticed this because I'm bootstrapping using rebootstrap, which
builds all libc6-dev's with #798955 implemented, so there is no
/usr/include/errno.h at all. You can simulate this by moving all the
headers in libc6-dev from /usr/include to /usr/include/$DEB_HOST_MULTIARCH

Patch supplied as simple patch and dpkg 3.0 (quilt) format fix.


Wookey
diff -urN perl-5.24.1.orig/ext/Errno/Errno_pm.PL perl-5.24.1/ext/Errno/Errno_pm.PL
--- perl-5.24.1.orig/ext/Errno/Errno_pm.PL	2017-09-15 16:04:41.332385550 +0000
+++ perl-5.24.1/ext/Errno/Errno_pm.PL	2017-09-15 16:04:56.948023389 +0000
@@ -133,7 +133,7 @@
 	# Some Linuxes have weird errno.hs which generate
 	# no #file or #line directives
 	my ($linux_errno_h) = grep { -e $_ } map { "$_/errno.h" }
-	    "$sysroot/usr/include", "$sysroot/usr/local/include",
+	    split( / /,"$Config{incpth}"), "$sysroot/usr/include", "$sysroot/usr/local/include/",
 	    split / / => $Config{locincpth} or
 		die "Cannot find errno.h";
 	$file{$linux_errno_h} = 1;
diff -urN perl-5.24.1.orig/debian/patches/crossbuild-multiarch-paths-errno-fix.diff perl-5.24.1/debian/patches/crossbuild-multiarch-paths-errno-fix.diff
--- perl-5.24.1.orig/debian/patches/crossbuild-multiarch-paths-errno-fix.diff	1970-01-01 01:00:00.000000000 +0100
+++ perl-5.24.1/debian/patches/crossbuild-multiarch-paths-errno-fix.diff	2017-09-15 17:13:55.843532995 +0100
@@ -0,0 +1,20 @@
+Description: Look in multiarch include paths so errno.h is found when crossing
+ errno.h may be in /usr/include/$multiarch/ on a debian system.
+ The build system needs to look in there, but currently assumes a sysroot with no multiarch paths
+ The sysroot is harmless here, but the lack of multiarch support is fatal.
+ The config does not include the multiarch path simply. Closest available 
+ is incpth which includes gcc internal arch-specific dirs and the correct multiarch dirs.
 
+Author: Wookey <woo...@debian.org>
+Last-Update: 2017-09-15
+
+--- perl-5.24.1.orig/ext/Errno/Errno_pm.PL
++++ perl-5.24.1/ext/Errno/Errno_pm.PL
+@@ -133,7 +133,7 @@ sub get_files {
+ 	# Some Linuxes have weird errno.hs which generate
+ 	# no #file or #line directives
+ 	my ($linux_errno_h) = grep { -e $_ } map { "$_/errno.h" }
+-	    "$sysroot/usr/include", "$sysroot/usr/local/include",
++	    split( / /,"$Config{incpth}"), "$sysroot/usr/include", "$sysroot/usr/local/include/",
+ 	    split / / => $Config{locincpth} or
+ 		die "Cannot find errno.h";
+ 	$file{$linux_errno_h} = 1;
diff -urN perl-5.24.1.orig/debian/patches/series perl-5.24.1/debian/patches/series
--- perl-5.24.1.orig/debian/patches/series	2017-09-15 17:04:41.172389260 +0100
+++ perl-5.24.1/debian/patches/series	2017-09-15 17:09:30.273687590 +0100
@@ -71,3 +71,4 @@
 fixes/getopt-long-4.diff
 fixes/fbm-instr-crash.diff
 debian/CVE-2016-1238/base-pm-amends-pt2.diff
+crossbuild-multiarch-paths-errno-fix.diff

Reply via email to