Bug 5170 - Cross compilation does not work
Summary: Cross compilation does not work
Status: CLOSED FIXED
Alias: None
Product: rsync
Classification: Unclassified
Component: core (show other bugs)
Version: 3.0.0
Hardware: x86 Linux
: P3 normal (vote)
Target Milestone: ---
Assignee: Wayne Davison
QA Contact: Rsync QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-01 07:29 UTC by Robert Schwebel
Modified: 2008-07-26 10:24 UTC (History)
0 users

See Also:


Attachments
[PATCH] Fix cross compilation, build mkrounding with CC_FOR_BUILD (1.47 KB, patch)
2008-01-01 07:33 UTC, Robert Schwebel
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Schwebel 2008-01-01 07:29:52 UTC
The makefiles try to build the "mkrounding" tool with the "host" compiler; however, this file is being executed later in the build, so it has to be compiled with the "build" compiler. Usually, autotoolized Makefiles solve this by using CC_FOR_BUILD and the related CFLAGS_FOR_BUILD and LDFLAGS_FOR_BUILD.

Error message, taken during a build for ARM here:

----------8<----------8<----------
arm-v4t-linux-gnueabi-gcc -std=gnu99 -g -O2 -DHAVE_CONFIG_H -Wall -W -I./popt -L/some/path/sysroot/arm-v4t-linux-gnueabi/lib -L/some/path/sysroot/arm-v4t-linux-gnueabi/usr/lib -Wl,-rpath-link -Wl,/some/path/sysroot/arm-v4t-linux-gnueabi/usr/lib -o mkrounding -I. ./mkrounding.c
./mkrounding >rounding.h
/bin/sh: ./mkrounding: cannot execute binary file
----------8<----------8<----------

Patch follows soon.
Comment 1 Robert Schwebel 2008-01-01 07:33:05 UTC
Created attachment 3083 [details]
[PATCH] Fix cross compilation, build mkrounding with CC_FOR_BUILD
Comment 2 Matt McCutchen 2008-01-01 09:14:13 UTC
That is not the right fix.  Running "mkrounding" is meant to give information about how the *cross compiler* aligns structures so rsync can adapt accordingly; building and running "mkrounding" for the build machine may give the wrong answer.

For cross compilation to work, we would need to find a way to get this information from the cross compiler itself without running an executable that it produces.  There is also the issue of the 11 configure tests that run things on the build machine (assumed to be the target machine).
Comment 3 Mike Frysinger 2008-01-01 10:33:11 UTC
autotools has a way of figuring out sizeof() by only cross-compiling by using array indexes ... i bet that could be adapted to do offsetof() which is what you're after, right ?
Comment 4 Wayne Davison 2008-01-01 11:09:39 UTC
I changed the makefile to output instructions for manually running mkrounding on the target machine when cross-compiling.

If someone wishes to automate a cross-compiler build, they should determine the rounding information (perhaps manually) and add their own build command (e.g. an echo) to create the rounding.h file before running "make" (or perhaps as a patch to Makefile.in).  The result of the mkrounding command is a simple define, such as this one:

#define EXTRA_ROUNDING 0
Comment 5 Robert Schwebel 2008-01-01 11:18:16 UTC
(In reply to comment #4)
> I changed the makefile to output instructions for manually running mkrounding
> on the target machine when cross-compiling.

Can you elaborate what mkrounding.c tries to achieve? It compares the size of n
'union file_extra's plus one 'struct file_struct' to the size of a struct
containing these all and checks if it is equal for n = 1, 2 or 4. But what's the
rationale behind this?

Maybe we find a better solution than throwing the file in manually (even
overwriting the test on the commandline with some ac_cv_* variable would be
better).
Comment 6 Wayne Davison 2008-01-01 11:30:57 UTC
Rsync has to determine the proper alignment for its internal struct when it manually aligns it after a leading array.  If this can be determined at configure time, that would obviously be preferable.
Comment 7 Wayne Davison 2008-01-01 12:26:55 UTC
OK, I took a clue from the configure sizeof check and changed the makefile to try one or more compilations of mkrounding.c with different rounding sizes.  This allows it to determine rounding without ever running the mkrounding program.
Comment 8 Matt McCutchen 2008-01-01 12:31:54 UTC
Cool!  It might be more natural to do the tests in the configure script.