Bug 51257 - Build failed when cross-compiling: ./gen_test_char: cannot execute binary file
Summary: Build failed when cross-compiling: ./gen_test_char: cannot execute binary file
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Build (show other bugs)
Version: 2.4.1
Hardware: Other Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-24 12:34 UTC by Henrik Strand
Modified: 2012-04-25 12:20 UTC (History)
3 users (show)



Attachments
Simple patch for defining the C compiler command to be used for compilation of programs that run on BUILD during cross-compiling, e.g. gen_test_char. (2.68 KB, patch)
2012-04-18 07:45 UTC, Henrik Strand
Details | Diff
Same patch as previous file but for httpd_trunk. (2.68 KB, patch)
2012-04-18 07:48 UTC, Henrik Strand
Details | Diff
Updated document patch. (2.15 KB, patch)
2012-04-25 12:07 UTC, Henrik Strand
Details | Diff
Updated document patch. (1.78 KB, patch)
2012-04-25 12:19 UTC, Henrik Strand
Details | Diff
Updated document patch. (1.78 KB, patch)
2012-04-25 12:20 UTC, Henrik Strand
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Henrik Strand 2011-05-24 12:34:33 UTC
When cross-compiling Apache httpd 2.2.19 "make" fails with the following error:

./dftables: ./dftables: cannot execute binary file

According to the README file in /srclib/pcre it should be possible to specify CC_FOR_BUILD when calling the "configure" command, but even when doing so "make" fails. 

A known workaround is to first build Apache httpd for local host and then copy the dftables binary to the other host build folder and run "make" again. However, since I would like to automate the build process the workaround is not sufficient for me. 


Also, the same type of error exists with the gen_test_char binary:

/bin/sh: ./gen_test_char: cannot execute binary file
Comment 1 Henrik Strand 2012-03-07 08:47:39 UTC
The build problem with gen_test_char still exists on Apache HTTP Server 2.4.1
Comment 2 Henrik Strand 2012-04-18 07:45:54 UTC
Created attachment 28632 [details]
Simple patch for defining the C compiler command to be used for compilation of programs that run on BUILD during cross-compiling, e.g. gen_test_char.

Verified on httpd_2.4.1
Comment 3 Henrik Strand 2012-04-18 07:48:55 UTC
Created attachment 28633 [details]
Same patch as previous file but for httpd_trunk.
Comment 4 Guenter Knauf 2012-04-19 12:03:01 UTC
Hi Henrik,
(In reply to comment #3)
> Created attachment 28633 [details]
> Same patch as previous file but for httpd_trunk.
I've just commited a slightly modified patch to trunk:
http://svn.apache.org/viewvc?rev=1327907&view=rev
this should work same way as with your patch provided that you export CC_FOR_BUILD=gcc. I hope that we can finally figure out how we can configure teach to set CC_FOR_BUILD automatically in case of detecting cross-compilation so that the export is then not needed. The CC_FOR_BUILD should appear in build/config_vars.mk because then server/Makefile can access it.
For 2.2.x you will then need in addition:
--- srclib/pcre/Makefile.in.orig        2005-02-11 13:00:41.000000000 +0100
+++ srclib/pcre/Makefile.in     2012-04-19 13:29:06.000000000 +0200
@@ -11,8 +11,13 @@

 $(LTLIBRARY_OBJECTS) dftables.lo: config.h

+ifdef CC_FOR_BUILD
+dftables: dftables.c
+       $(CC_FOR_BUILD) -o $@ $<
+else
 dftables: dftables.lo
        $(LINK) $(EXTRA_LDFLAGS) dftables.lo $(EXTRA_LIBS)
+endif

 $(srcdir)/chartables.c: dftables
        ./dftables $@
Comment 5 Guenter Knauf 2012-04-20 15:17:06 UTC
I've just committed a follow-up patch:
http://svn.apache.org/viewvc?view=revision&revision=1328390
it is *required* that you re-run buildconf so that configure gets re-created! After you've run configure with f.e.:
CC_FOR_BUILD=gcc ./configure --host=...
you can check ./build/config_vars.mk where CC_FOR_BUILD should appear now and ./server/Makefile should now see the var ...
Comment 6 Guenter Knauf 2012-04-21 18:23:14 UTC
Here's the summarize of all patches:
* cross-compile: allow to provide CC_FOR_BUILD so that gen_test_char will be
  compiled by the build compiler instead of the host compiler.
  Also set CC_FOR_BUILD to 'cc' when cross-compilation is detected.
  Trunk patches: http://svn.apache.org/viewvc?view=revision&revision=1327907
                 http://svn.apache.org/viewvc?view=revision&revision=1328390
                 http://svn.apache.org/viewvc?view=revision&revision=1328714

Backport proposal added for 2.4.x patch:
http://people.apache.org/~fuankg/diffs/httpd-2.4.x-cross_compile.diff
Backport proposal added for 2.2.x patch:
http://people.apache.org/~fuankg/diffs/httpd-2.2.x-cross_compile.diff
Since PCRE is included with 2.2.x this patch also takes care for dftables.

please test both with and without providing CC_FOR_BUILD - if not set and cross-compilation is detected then CC_FOR_BUILD defaults to 'cc'.
Comment 7 Henrik Strand 2012-04-25 12:07:35 UTC
Created attachment 28680 [details]
Updated document patch.
Comment 8 Henrik Strand 2012-04-25 12:19:24 UTC
Created attachment 28681 [details]
Updated document patch.
Comment 9 Henrik Strand 2012-04-25 12:20:26 UTC
Created attachment 28682 [details]
Updated document patch.