Re: Help needed to cross-build gcl27
Hi Nilesh,
thanks for sending cross build patches!
On Sun, Aug 03, 2025 at 10:14:55AM +0530, Nilesh Patra wrote:
> The next failure is:
>
> | checking for setjmp.h... yes
> | checking sizeof jmp_buf... configure: error: in '/build/reproducible-path/gcl27-2.7.1':
> | configure: error: cannot run test program while cross compiling
> | See 'config.log' for more details
> | make: *** [debian/rules:65: configure-stamp] Error 1
>
> The configure script runs several tiny test programs to get info in bits and pieces. The above
> is to get sizeof jmp. And the configure script has a hard fail if its cross building.
>
> This is a pattern that I've seen in a few other packages as well that I looked at in the
> past days. Is there a way around it?
This kind of failure tends to require elaborate work. Typically, you can
identify the causing code by looking for AC_RUN_IFELSE or AC_TRY_RUN.
Roughly speaking, all of such uses are problematic to cross building one
way or another and what to do about them is fairly individual.
Rather than coming up with a general recipe, allow me to work by example
on gcl27.
In https://sources.debian.org/src/gcl27/2.7.1-7/configure.ac/#L178, it
is being used with an empty program. There is nothing being checked here
at runtime. If this test succeeds linking, it'll also succeed running
(unless cross compiling). So this should be using AC_LINK_IFELSE
instead.
https://sources.debian.org/src/gcl27/2.7.1-7/configure.ac/#L206
likewise.
https://sources.debian.org/src/gcl27/2.7.1-7/configure.ac/#L551 is an
open coded sizeof test. It should be converted to AC_CHECK_SIZEOF. When
building natively, that'll result in a very similar execution to
determine the value, but for cross compilation it'll use bisection to
narrow down the value without running a program. The more general macro
backing this functionality is AC_COMPUTE_INT and it is applicable to
quite a lot of cases.
https://sources.debian.org/src/gcl27/2.7.1-7/configure.ac/#L574 is
querying sysconf(_SC_CLK_TCK). This is one of the things we really
cannot do during cross compilation. It also may change from one build
environment to another, so it really should be a runtime check of the
program rather than a build time check. I'm not sure that's possible,
but consider trying that first. Failing that, such checks usually should
be wrapped in AC_CACHE_CHECK. Then a builder (or even debian/rules) can
supply the value for the particular host architecture in question
bypassing the check.
https://sources.debian.org/src/gcl27/2.7.1-7/configure.ac/#L593 does not
gain anything from running the program. One of the branches can be
turned into #error and the AC_COMPILE_IFELSE is sufficient.
I'll stop here as things appear to be repeating from here. There will be
more non-trivial cases not covered here, but this configure.ac contains
very many AC_RUN_IFELSE and fixing it will take a lot of effort.
As a way forward here, I recommend starting with low hanging fruit and
working with upstream. For instance, identifying all checks that really
should be AC_CHECK_SIZEOF and converting them should remove a lot of
open coded checking code resulting in a significant reduction of
configure.ac length while at the same time increasing portability.
That's a change I expect upstream (in general, not this particular
upstream) to welcome even if it does not fix all of cross build
problems. Then identify another class of checks (e.g. those where
AC_LINK_IFELSE suffices) and trying those working your way up to the
harder ones.
If you tackle this, be prepared for a longer journey. Also keep in mind
that this kind of work poses benefits beyond Debian. Buildroot, PtxDist
and Yocto will all benefit from such work. Consider checking those
projects for patches that failed to go upstream thus far.
Hope this helps
Helmut
Reply to: