Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] Configure: Probe intsize with a compile-only test #14654

Open
p5pRT opened this issue Apr 17, 2015 · 8 comments
Open

[PATCH] Configure: Probe intsize with a compile-only test #14654

p5pRT opened this issue Apr 17, 2015 · 8 comments

Comments

@p5pRT
Copy link
Collaborator

@p5pRT p5pRT commented Apr 17, 2015

Migrated from rt.perl.org#124326 (status was 'open')

Searchable as RT124326$

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 17, 2015

From @ntyni

Forwarding this report by Helmut Grohne from <https://bugs.debian.org/775940>:

  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.

The patch is for 5.20.1 but it applies to current bleadperl with some
fuzz. I've tried it out on i386 and amd64 (aka. x86_64), and it correctly
determines intsize=4 there but outputs compiler messages like

  Checking to see how big your integers are...
  try.c​: In function ‘main’​:
  try.c​:7​:13​: error​: size of array ‘test’ is negative
  static int test[1 - 2 * (sizeof(int) >= 1)];
  ^
I assume that's trivially fixable.

If somebody could please add Helmut Grohne <helmut@​subdivi.de> to the
watchlist of this ticket, that would probably help discussion by removing
me as a middle-man.

Many thanks for your work on Perl,
--
Niko Tyni ntyni@​debian.org

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 17, 2015

From @ntyni

intsize_cross.diff
Description: do not run host arch code for determining sizeof(int)
Author: Helmut Grohne <helmut@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
@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented May 5, 2015

From @Tux

I'd like to discuss this once 5.22 has been released.

One of the reasons is that smoke-me branches are not covered by the "weird" OS's that this approach would affect, whereas core-smokes do.

I'll contact the maintainer of upriver meta/dist to acquire his opinion.

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented May 5, 2015

The RT System itself - Status changed from 'new' to 'open'

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented May 11, 2015

From @tonycoz

On Tue May 05 01​:27​:47 2015, hmbrand wrote​:

I'd like to discuss this once 5.22 has been released.

See​:

https://rt-archive.perl.org/perl5/Ticket/Display.html?id=125096#txn-1347825

which seems to belong to this ticket.

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Jun 2, 2015

From @jkeenan

On Tue May 05 01​:27​:47 2015, hmbrand wrote​:

I'd like to discuss this once 5.22 has been released.

Which occurred today!

One of the reasons is that smoke-me branches are not covered by the
"weird" OS's that this approach would affect, whereas core-smokes do.

I'll contact the maintainer of upriver meta/dist to acquire his
opinion.

[Tux] How should we proceed?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Jun 2, 2015

From @Tux

The answer from the author of dist/meta​:

--8<---
The current dist (SVN version, not yet found the time / inclination
to migrate to git) has switched to compile-time tests whenever
possible since 2008.

In particular, the current intsize.U unit uses "static asserts"
to detect through compile-time errors whether an assertion holds.
This allows to compute the size of all types via compile tests,
without having to run anything.

Even IEEE float endianness is now determined without running a program.
No static assert here however​: look at d_ieee754.U.

The rationale for moving out of run-tests is that it prevents
cross-compilation to occur. But when you cross-compile, you
always have a compiler handy... Since at some point I had to
cross-compile gtk-gnutella with MinGW, I had to move away from
run-tests as much as possible!
-->8---

So the answer is yes, but this will take way more time than I currently can free​: it involves matching every single unit that we (at perl5) use against the current checkout of meta/dist' keeping in mind that we might have diverged from the original path just for perl.

The bus factor for this refactor is 1.

I have done some one-to-one explanations of the process in the past, but it never lead to more people working on this code.

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Oct 30, 2016

From @jmdh

On Tue Jun 02 08​:08​:24 2015, hmbrand wrote​:

The answer from the author of dist/meta​:

--8<---
The current dist (SVN version, not yet found the time / inclination
to migrate to git) has switched to compile-time tests whenever
possible since 2008.

In particular, the current intsize.U unit uses "static asserts"
to detect through compile-time errors whether an assertion holds.
This allows to compute the size of all types via compile tests,
without having to run anything.

Even IEEE float endianness is now determined without running a
program.
No static assert here however​: look at d_ieee754.U.

The rationale for moving out of run-tests is that it prevents
cross-compilation to occur. But when you cross-compile, you
always have a compiler handy... Since at some point I had to
cross-compile gtk-gnutella with MinGW, I had to move away from
run-tests as much as possible!
-->8---

So the answer is yes, but this will take way more time than I
currently can free​: it involves matching every single unit that we (at
perl5) use against the current checkout of meta/dist' keeping in mind
that we might have diverged from the original path just for perl.

The bus factor for this refactor is 1.

I have done some one-to-one explanations of the process in the past,
but it never lead to more people working on this code.

Hello,

Thanks for this explanation which is understandable if unfortunate. I wonder if anything might have changed here since your last update? We're revisiting patching Configure directly in Debian again, as it would (eventually) make cross-building easier, but this is indeed makework if the real fix is tractable.

Thanks,
Dominic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.