From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([69.77.167.62] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Ku0lg-0000K6-1n for garchives@archives.gentoo.org; Sun, 26 Oct 2008 08:14:36 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 359F9E0251; Sun, 26 Oct 2008 08:14:36 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id DD629E0251 for ; Sun, 26 Oct 2008 08:14:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id DB8BA646E0; Sun, 26 Oct 2008 08:14:33 +0000 (UTC) From: Mike Frysinger Organization: wh0rd.org To: gentoo-embedded@lists.gentoo.org Subject: Re: [gentoo-embedded] Auto Repair Cross Includes? Date: Sun, 26 Oct 2008 04:14:25 -0400 User-Agent: KMail/1.9.9 Cc: Ned Ludd References: <1222017153.9939.82.camel@media> In-Reply-To: <1222017153.9939.82.camel@media> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-embedded@lists.gentoo.org Reply-to: gentoo-embedded@lists.gentoo.org MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart5312979.9cq3APTu7J"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <200810260414.28321.vapier@gentoo.org> X-Archives-Salt: 8587874d-b5b1-41e1-af9b-83860db2173b X-Archives-Hash: 08aceab0dacfbda76c341b3c032447e9 --nextPart5312979.9cq3APTu7J Content-Type: text/plain; charset="iso-8859-6" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Sunday 21 September 2008, Ned Ludd wrote: > I've been toying with an idea after seeing a patch which would abort() > when it detected host includes for cross compiles. I did not like the > idea of aborting as it prevented me from building pkgs that had the same > headers in $ROOT as /. I did like the fact there was a little QA I could > slip in there. After thinking about it a while. I said fsck the QA and > just fixed the problem. Here is what I came up with for gcc-4.2.4.. > > While in my testing I'm finding this works beautifully. However I'd like > some input from others on what they think of such an idea. > Good/Bad/Other? > > Basic goal detect ^/usr/include and rewrite it to $ROOT/usr/include if > using a cross compiler and ROOT is set. add it to gcc already and be done. you nicely protect it with CROSS_COMPIL= E,=20 so it wont damage native users. > +#ifdef CROSS_COMPILE > +/* Rewrite the include paths for cross compiles */ > +char *cross_fixup_path(char *path); > +char *cross_fixup_path(char *path) { should be marked static right ? > + char *name, *root, *ptr; > + int len; > + > + root =3D getenv("ROOT"); > + if (root =3D=3D NULL) > + return name; perhaps you mean to return path ? "name" is uninitialized here ... > + if (strstr(path, "/usr/include") !=3D path) > + return path; seems like a funky check and one that would throw false positives ... it's= =20 valid for people to have /some/crazy/path/usr/include/ ... make it an array of bad paths and anchor the search to the start: /usr/local/include /usr/include /sw/include also, are paths "normalized" by this point by common code ? in other words= ,=20 if someone does "-I////usr////include////", does gcc normailize it for you= =20 already ? if not, should do so here ... > + name =3D xstrdup(path); umm, why ? you dont use the "name" storage at all ... in fact, you leak=20 it ... > + len =3D strlen(root) + strlen(name) + 2; > + ptr =3D (char *) xmalloc (len); pointless cast > + sprintf(ptr, "%s/%s", root, name); doesnt gcc (via libiberty) already provide asprintf() ? that'd make this c= ode=20 simpler ... > + fprintf(stderr, _("Autofixing Invalid Cross Include Path: %s -> > %s\n"), name, ptr); i think gcc already has a set of warn-type functions which you should use > + free(path);=20 > + path =3D ptr; > + name =3D path; > + return name; why not just drop this "name" variable altogether ? just hit up "path"=20 directly > +} > +#endif > + > /* Add PATH to the include chain CHAIN. PATH must be malloc-ed and > NUL-terminated. */ > void > @@ -359,6 +385,11 @@ > p->construct =3D 0; > p->user_supplied_p =3D user_supplied_p; > =20 > +#ifdef CROSS_COMPILE > + path =3D cross_fixup_path(path); > + p->name =3D path; > +#endif > + > add_cpp_dir_path (p, chain); > } seems kind of pointless to touch "path" here since ... i'm assuming it's=20 function local though (havent read the actual file) =2Dmike --nextPart5312979.9cq3APTu7J Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) iQIcBAABAgAGBQJJBCbkAAoJEEFjO5/oN/WBQ+kP/29/CW6FWTLAttxYwD4WcipC mpl0DRaM7Dpv3GggAtACg+lbdF/bKfPuYk1ZvND5iTlBscH/EXbyDOrm31m6J8uk H1nga1aaxu7zobWbPYURuerfc2IZNkWR2rJVLfIkba5pIddGQabB2nx5NwuB1Y1O lAFcvdAdHk3jiL0i69Mch57FTJ1vf4AC10tPnwZJds95Nv/j7Nxzb4cGZNl1q+5t QhF4ecn7MXwTEaV7+PlFxpv+Zl/dGxQj3cFv7vE2FbFz0WT+EH0MrCS6JGIEaGcS 2j2ssFUL7r+G6u1e04H6AztEl4xntIO9fxuBy9ipHjW5BLgOSuTf7ABChDctRGzA /QdJFs41rhgegsmW9gU8D3Lblsl+PcewS8A0PivbVpqX3At1/1IiyW7UwHXDiU1S OrdawuFlMO49qYCEHpQMxVyRTnSimswU8gtRpFB3l6uoVCzno58supMIJW6Y3daS Nr3wrDTmJAhkzdh92aJ2mQWQnEf7YTJJIi82lyuuupYgbGzd9MK0SiRNWR8G+84O kppcLJdRb1n/SMTpxfQWRf7Etakwj9PoLPolvjpU5OxEdAF0/4QferTdWy19RWRm uF4qpDT0eobNT38cGkUgdqzOPKwjc1eidMYbBHqlq9Q2DXXqSRaik48s8vT3tXc0 +qncsB8NrpY/3FV2l0rG =h+oL -----END PGP SIGNATURE----- --nextPart5312979.9cq3APTu7J--