[U-Boot-Users] [PATCH] tools/envcrc.c: use the target sizeof rather than build
Wolfgang Denk
wd at denx.de
Sun Mar 30 23:07:59 CEST 2008
In message <1206908872-2141-1-git-send-email-vapier at gentoo.org> you wrote:
> The envcrc.c does sizeof(unsigned long) when calculating the crc, but this
> is done with the build toolchain instead of the target toolchain, so if
> the build is a 64bit system but the target is 32bits, the size will
> obviously be wrong. This introduces a sizeof.sh script to calculate the
> required sizeof() value of any type with any compiler.
It seems this script requires up to 64 runs of the C compiler. I
consider this pretty expensive. Isn't there a cheaper way to do that?
Consider the simple logic used to decide between 32 versus 64 bit
pointer types - shouldn't this be sufficient here, too?
> --- /dev/null
> +++ b/tools/sizeof.sh
> @@ -0,0 +1,35 @@
> +#!/bin/sh
> +# Get the sizeof(type) for a compiler
> +
> +type="$*"
> +CC=${CC:-gcc}
> +
> +if [ -z "$type" ] ; then
> + echo "Usage: sizeof.sh <type>" 1>&2
> + exit 1
> +fi
> +
> +test_size() {
> + cat <<-EOF > sizeof.c
> + typedef $type ac__type_sizeof_;
> + int main() {
> + static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $size)];
> + test_array [0] = 0;
> + return 0;
> + }
> + EOF
> + ${CC} -c sizeof.c >/dev/null 2>&1
> + ret=$?
> + rm -f sizeof.[co]
> + return $ret
> +}
Are there no Copyrights / License conditions attached to this code?
Where exactly is it coming from?
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
...when fits of creativity run strong, more than one programmer or
writer has been known to abandon the desktop for the more spacious
floor. - Fred Brooks, Jr.
More information about the U-Boot
mailing list