Bug#775940: Configure: determine sizeof(int) without running host arch code during cross building

Helmut Grohne helmut at subdivi.de
Wed Jan 21 19:00:20 UTC 2015


Package: src:perl
Version: 5.20.1-4
Tags: patch
User: helmutg at debian.org
Usertags: rebootstrap

In bug #762638, it was suggested[1] that perl's Configure is indeed
source and is indeed considered preferred form for modification (even
though the header of that file claims otherwise). Maybe it is good to
put this issue to test:

A major issue with cross building perl is that it tries to run host arch
code during configure. In quite a few cases this is completely
unnecessary. Consider its check for sizeof(int) for instance. As we know
from autotools, sizeof values can be determined by bisecting using
compile-only tests. I am therefore attaching a patch that turns the
compile&run test for sizeof(int) into a compile-only test.

Practically this means that people who wish to cross build perl no
longer need to feed the value of intsize. Of course, this is just a drop
in the bucket as there still are longsize, shortsize and many more. What
I am seeking here is the preferred method to fix all of them. So rather
than submitting a large patch pile against a possibly autogenerated
file, I am submitting an incremental improvement to observe the
processes.

I hope this works out

Helmut

[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=762638#29
    "The way it's set up now, we encourage people to simply patch
    Configure." (Andy Dougherty)
-------------- next part --------------
diff -Nru perl-5.20.1/debian/changelog perl-5.20.1/debian/changelog
--- perl-5.20.1/debian/changelog	2014-12-19 16:55:37.000000000 +0000
+++ perl-5.20.1/debian/changelog	2015-01-21 06:53:51.000000000 +0000
@@ -1,3 +1,10 @@
+perl (5.20.1-4.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Do not run host arch code to determine sizeof(int). (Closes: #-1)
+
+ -- Helmut Grohne <helmut at subdivi.de>  Wed, 21 Jan 2015 06:53:26 +0000
+
 perl (5.20.1-4) unstable; urgency=medium
 
   * Make perl-base and perl-modules Break pdl (<< 1:2.007-4)
diff -Nru perl-5.20.1/debian/patches/fixes/intsize_cross.diff perl-5.20.1/debian/patches/fixes/intsize_cross.diff
--- perl-5.20.1/debian/patches/fixes/intsize_cross.diff	1970-01-01 00:00:00.000000000 +0000
+++ perl-5.20.1/debian/patches/fixes/intsize_cross.diff	2015-01-21 07:06:22.000000000 +0000
@@ -0,0 +1,93 @@
+Description: do not run host arch code for determining sizeof(int)
+Author: Helmut Grohne <helmut at subdivi.de>
+Last-Update: 2015-01-21
+
+--- perl-5.20.1.orig/Configure
++++ perl-5.20.1/Configure
+@@ -5755,6 +5755,67 @@ case "$intsize" in
+ #ifdef I_STDLIB
+ #include <stdlib.h>
+ #endif
++int main() {
++	static int test[1 - 2 * (sizeof(int) < 0)];
++	return 0;
++}
++EOCP
++	set try
++	if eval $compile_ok; then
++		:
++	else
++		echo "Your integers are negatively sized."
++		exit 1
++	fi
++	intsize_lo=0
++	intsize_hi=1
++	while :; do
++		$cat >try.c <<EOCP
++#include <stdio.h>
++#$i_stdlib I_STDLIB
++#ifdef I_STDLIB
++#include <stdlib.h>
++#endif
++int main() {
++	static int test[1 - 2 * (sizeof(int) >= $intsize_hi)];
++	return 0;
++}
++EOCP
++		set try
++		eval $compile_ok && break
++		intsize_lo=$intsize_hi
++		intsize_hi=`expr $intsize_lo "*" 2`
++	done
++	while $test $intsize_lo -lt `expr $intsize_hi - 1`; do
++		intsize_mid=`expr $intsize_lo + $intsize_hi`
++		intsize_mid=`expr $intsize_mid / 2`
++		$cat >try.c <<EOCP
++#include <stdio.h>
++#$i_stdlib I_STDLIB
++#ifdef I_STDLIB
++#include <stdlib.h>
++#endif
++int main() {
++	static int test[1 - 2 * (sizeof(int) >= $intsize_mid)];
++	return 0;
++}
++EOCP
++		set try
++		if eval $compile_ok; then
++			intsize_hi=$intsize_mid
++		else
++			intsize_lo=$intsize_mid
++		fi
++	done
++	intsize=$intsize_lo
++	echo "Your integers are $intsize bytes long."
++
++	$cat >try.c <<EOCP
++#include <stdio.h>
++#$i_stdlib I_STDLIB
++#ifdef I_STDLIB
++#include <stdlib.h>
++#endif
+ int main()
+ {
+ 	printf("intsize=%d;\n", (int)sizeof(int));
+@@ -5766,7 +5827,6 @@ EOCP
+ 	set try
+ 	if eval $compile_ok && $run ./try > /dev/null; then
+ 		eval `$run ./try`
+-		echo "Your integers are $intsize bytes long."
+ 		echo "Your long integers are $longsize bytes long."
+ 		echo "Your short integers are $shortsize bytes long."
+ 	else
+@@ -5777,10 +5837,6 @@ Help! I can't compile and run the intsiz
+ you really ought to fix it.  Still, I'll try anyway.)
+ !
+ EOM
+-		dflt=4
+-		rp="What is the size of an integer (in bytes)?"
+-		. ./myread
+-		intsize="$ans"
+ 		dflt=$intsize
+ 		rp="What is the size of a long integer (in bytes)?"
+ 		. ./myread
diff -Nru perl-5.20.1/debian/patches/series perl-5.20.1/debian/patches/series
--- perl-5.20.1/debian/patches/series	2014-11-09 20:12:43.000000000 +0000
+++ perl-5.20.1/debian/patches/series	2015-01-21 06:55:23.000000000 +0000
@@ -37,3 +37,4 @@
 fixes/io_uncompress_gunzip_inmemory.diff
 fixes/socket_test_recv_fix.diff
 fixes/hurd_socket_recv_todo.diff
+fixes/intsize_cross.diff


More information about the Perl-maintainers mailing list