Bug 11891 - 4.4.3 fails to cross compile
4.4.3 fails to cross compile
Status: NEW
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Build
All All
: P5 normal
: ---
Assigned To: Samba QA Contact
Samba QA Contact
Depends on:
  Show dependency treegraph
Reported: 2016-05-03 15:36 UTC by Enno Boland
Modified: 2018-01-07 18:01 UTC (History)
5 users (show)

See Also:

samba-4.4.3/bin/config.log (gzipped) (297.39 KB, application/gzip)
2016-05-03 15:36 UTC, Enno Boland
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Enno Boland 2016-05-03 15:36:05 UTC
Created attachment 12058 [details]
samba-4.4.3/bin/config.log (gzipped)

After some tweaking, I got samba configuring correctly for cross compile using --cross-answers. 

Unfortunately samba fails to compile correctly and fails with 

/bin/sh: /builddir/samba-4.4.3/bin/asn1_compile: cannot execute binary file: Exec format error
/bin/sh: /builddir/samba-4.4.3/bin/asn1_compile: cannot execute binary file: Exec format error
/bin/sh: /builddir/samba-4.4.3/bin/asn1_compile: cannot execute binary file: Exec format error
Waf: Leaving directory `/builddir/samba-4.4.3/bin'
Build failed:
 -> task failed (err #126): 
	{task: HEIMDAL_KX509_ASN1_ASN1 kx509.asn1 -> asn1_kx509_asn1.x,kx509_asn1.hx,kx509_asn1-priv.hx}
 -> task failed (err #126): 
	{task: HEIMDAL_DIGEST_ASN1_ASN1 digest.asn1 -> asn1_digest_asn1.x,digest_asn1.hx,digest_asn1-priv.hx}
 -> task failed (err #126): 
	{task: HEIMDAL_HDB_ASN1_ASN1 hdb.asn1 -> asn1_hdb_asn1.x,hdb_asn1.hx,hdb_asn1-priv.hx}
 -> task failed (err #126): 
	{task: HEIMDAL_GSSAPI_ASN1_ASN1 gssapi.asn1 -> asn1_gssapi_asn1.x,gssapi_asn1.hx,gssapi_asn1-priv.hx}

If I understand correctly in source4/heimdal_build/wscript_build line 914 the build system is told to build ans1_compile with "use_hostcc" but it looks like this option is ignored.

-- Enno Boland
Comment 1 trenta 2016-05-07 23:05:30 UTC
Trying to compile samba 4.4.3 with Debian 8 jessie and all test are OK, but first fails 
# smbclient -L localhost -U%
Domain=[SAMDOM] OS=[Windows 6.1] Server=[Samba 4.4.3]

With 4.4.2 seems to work

How can I solve?
Comment 3 Enno Boland 2016-05-07 23:16:04 UTC
That's a different issue, this is about _cross_ compiling
Comment 4 trenta 2016-05-08 08:10:36 UTC
Ok, created a new bug https://bugzilla.samba.org/show_bug.cgi?id=11910
Comment 5 Christian Kujau 2018-01-07 08:00:46 UTC
I too needed to cross-compile Samba for aarch64 (ARM64) and was unable to do so because of exactly the same issue. Unable (or just too stupid) to wrap my head around that insane Waf machinery, I replaced asn1_compile (and compile_et) with wrapper scripts. The whole procedure, in short:

CC=aarch64-linux-gnu-gcc buildtools/bin/waf configure \
  --prefix=/opt/sambax --disable-python --without-ad-dc --without-ads \
  --without-ldap --without-acl-support --without-pam --cross-compile \
  --cross-execute="/usr/bin/qemu-aarch64 /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 --library-path /usr/aarch64-linux-gnu/lib/"

Note: I needed to disable both PAM and ACL support, as it was unable to find both libraries during the build (although development headers were installed!).
And that --disable-python switch has been introduced after samba-4.6.9, but is only usable in the 4.7 releases. Let's try to build samba-4.7.4 now:

 CC=aarch64-linux-gnu-gcc buildtools/bin/waf build --cross-compile \
   --cross-execute="/usr/bin/qemu-aarch64 /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 --library-path /usr/aarch64-linux-gnu/lib/"

And this breaks of course with the error mentioned in this bug. Install the wrapper scripts:

 $ mv bin/default/source4/heimdal_build/asn1_compile{,.orig}
 $ mv bin/default/source4/heimdal_build/compile_et{,.orig}
 $ ln -s /usr/local/bin/asn1_compile bin/default/source4/heimdal_build/asn1_compile
 $ ln -s /usr/local/bin/compile_et   bin/default/source4/heimdal_build/compile_et
The wrapper scripts basically do this:

 $ cat /usr/local/bin/asn1_compile
 /usr/bin/qemu-aarch64 /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 --library-path /usr/aarch64-linux-gnu/lib/ \
     /usr/local/src/samba-git/bin/default/source4/heimdal_build/asn1_compile.orig  $@

With that in place, the next call to "build" should work:

 CC=aarch64-linux-gnu-gcc buildtools/bin/waf build --cross-compile \
   --cross-execute="/usr/bin/qemu-aarch64 /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 --library-path /usr/aarch64-linux-gnu/lib/"

Note: the build still broke because of two unrelated PAM compilation errors but with two patches applied[0] (resp. reverted[1]), the samba-4.7.4 build completed.

[0] https://lists.samba.org/archive/samba-technical/2011-September/079270.html
[1] https://lists.samba.org/archive/samba/2017-December/212930.html
Comment 6 Andrew Bartlett 2018-01-07 18:01:10 UTC
We should probably just fail to compile with the internal Heimdal for the cross-compile and suggest --with-system-mitkrb5 as this is likely what the caller wants anyway.
Comment 7 Andrew Bartlett 2018-01-07 18:01:47 UTC
(naturally patches to fix this are also most welcome)