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:
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
/bin/sh: ./mkrounding: cannot execute binary file
Patch follows soon.
Created attachment 3083 [details]
[PATCH] Fix cross compilation, build mkrounding with CC_FOR_BUILD
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).
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 ?
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
(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
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.
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.
Cool! It might be more natural to do the tests in the configure script.