[ntp:questions] Re: cross compiling ntp-4.2.0: ./ntpdc-layout: cannot execute binary file

Maciej W. Rozycki macro at ds2.pg.gda.pl
Fri Jan 23 21:17:01 UTC 2004


On Fri, 23 Jan 2004, David Wuertele wrote:

> I'm trying to cross-compile ntp.  But during the compile, the
> makefiles attempt to run one of the target executables.  This

 *Host executables*, please -- why is there so much confusion about that?  
Have you actually specified "--target=mipsel-linux" rather than
"--host=mipsel-linux"?  The notion of a target has any meaning only for
tools like compilers.

> executable ("ntpdc-layout") was compiled with the cross-compiler, so
> it obviously won't execute:
> 
>   mipsel-linux-gcc  -g -O2 -Wall -Wcast-qual -Wmissing-prototypes -Wpointer-arith -Wshadow -Wstrict-prototypes   -o ntpdc-layout  ntpdc-layout.o  
>   ./ntpdc-layout > layout.here
>   /bin/sh: line 1: ./ntpdc-layout: cannot execute binary file
>   make[3]: *** [layout.here] Error 126
>   make[3]: Leaving directory `/home/dave/C/perforce/thirdparty/www.ntp.org/ntp-4.2.0/ntpdc'
> 
> I couldn't find any documentation about ntpdc-layout.  Is there a way

 It looks like a validator for a structure layout established by the
compiler.  As such it's not usable when cross-compiling; perhaps an
approach similar to current autoconf's AC_CHECK_SIZEOF could be exploited,
but that might not actually be worth the hassle.

> to configure the ntp build so that it doesn't try to execute
> ntpdc-layout?  I'm not expert enough with autoconf to teach it how to
> use the native compiler for some programs and the cross compiler for
> others.

 With lone autoconf setting up CC_FOR_BUILD and CFLAGS_FOR_BUILD is fairly
easy and with automake, which ntp uses, it's next to trivial.  In this
particular case we simply want to disable the validator, so the patch is
yet smaller.  You need to run:

$ aclocal && autoconf && automake

after applying it and if the commands succeed (check with $?), which it
should if you have reasonably new tools (I use automake 1.8.2 and autoconf
2.59, but you needn't be that aggressive; just disregard warnings from
aclocal, if any), then just proceed as usual.  With it I've just
successfully built ntp 4.2.0 for the mipsel-linux host :-) using an
i386-linux build system.  Good luck.

 Can this patch please be applied?

 BTW, the current hackery for OpenSSL detection isn't the most fortunate
for cross-compiling -- whatever is found e.g. in /usr/lib and /usr/include
is likely inadequate for the host environment.  I think AC_CHECK_HEADER
and AC_TRY_LINK should be used first to check if the library is available
in a compiler-default location, before resorting to directory scans, and
then for each directory as well, to avoid configuring a
binary-incompatible library.  I can see if I can cook up something
appropriate if there's interest.

  Maciej

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro at ds2.pg.gda.pl, PGP key available        +

ntp-4.2.0-cross.patch
diff -up --recursive --new-file ntp-4.2.0.macro/configure.in ntp-4.2.0/configure.in
--- ntp-4.2.0.macro/configure.in	2003-10-15 08:52:44.000000000 +0000
+++ ntp-4.2.0/configure.in	2004-01-23 19:47:02.000000000 +0000
@@ -25,6 +25,8 @@ AC_PROG_CC
 AC_PROG_CC_STDC
 AC_PROG_CPP
 
+AM_CONDITIONAL(CROSS_COMPILING, [test "$cross_compiling" = yes])
+
 case "$host" in
  *-*-amigaos)
     CFLAGS="$CFLAGS -Dfork=vfork -DSYS_AMIGA"
diff -up --recursive --new-file ntp-4.2.0.macro/ntpdc/Makefile.am ntp-4.2.0/ntpdc/Makefile.am
--- ntp-4.2.0.macro/ntpdc/Makefile.am	2003-10-15 09:32:34.000000000 +0000
+++ ntp-4.2.0/ntpdc/Makefile.am	2004-01-23 20:03:51.000000000 +0000
@@ -1,9 +1,6 @@
 #AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies
 AUTOMAKE_OPTIONS = ../util/ansi2knr
 bin_PROGRAMS=	ntpdc
-EXTRA_PROGRAMS=	ntpdc-layout
-EXTRA_DATA=	check-layout
-BUILT_SOURCES=	maybe-layout
 INCLUDES=	-I$(top_srcdir)/include
 # LDADD might need RESLIB and ADJLIB
 ntpdc_LDADD=	version.o ../libntp/libntp.a @READLINE_LIBS@
@@ -17,6 +14,11 @@ ETAGS_ARGS= 	Makefile.am
 
 ntpdc_SOURCES = ntpdc.c ntpdc_ops.c
 
+if !CROSS_COMPILING
+EXTRA_PROGRAMS=	ntpdc-layout
+EXTRA_DATA=	check-layout
+BUILT_SOURCES=	maybe-layout
+
 maybe-layout:
 	@case "${PATH_PERL}" in \
 	    /*) ${MAKE} check-layout ;;	\
@@ -29,6 +31,7 @@ layout.here: ntpdc-layout
 
 check-layout: ntpdc-layout layout.std layout.here
 	cmp $(srcdir)/layout.std layout.here && echo stamp > $@
+endif
 
 $(PROGRAMS): $(LDADD)
 



More information about the questions mailing list