From: Wolfgang Denk Date: Sun, 30 Mar 2008 23:07:59 +0200 Subject: [U-Boot-Users] [PATCH] tools/envcrc.c: use the target sizeof rather than build In-Reply-To: Your message of "Sun, 30 Mar 2008 16:27:52 EDT." <1206908872-2141-1-git-send-email-vapier@gentoo.org> Message-ID: <20080330210759.AA079248BE@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de In message <1206908872-2141-1-git-send-email-vapier@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 " 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.