* [gentoo-embedded] Auto Repair Cross Includes?
@ 2008-09-21 17:12 Ned Ludd
2008-09-22 8:45 ` Ahmed Ammar
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Ned Ludd @ 2008-09-21 17:12 UTC (permalink / raw
To: gentoo-embedded
[-- Attachment #1: Type: text/plain, Size: 699 bytes --]
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.
-solar
[-- Attachment #2: Type: text/x-patch, Size: 1069 bytes --]
--- gcc/c-incpath.c 2007-09-01 08:28:30.000000000 -0700
+++ gcc/c-incpath.c 2008-09-19 20:32:27.000000000 -0700
@@ -332,6 +332,32 @@
tails[chain] = p;
}
+#ifdef CROSS_COMPILE
+/* Rewrite the include paths for cross compiles */
+char *cross_fixup_path(char *path);
+char *cross_fixup_path(char *path) {
+ char *name, *root, *ptr;
+ int len;
+
+ root = getenv("ROOT");
+ if (root == NULL)
+ return name;
+
+ if (strstr(path, "/usr/include") != path)
+ return path;
+
+ name = xstrdup(path);
+ len = strlen(root) + strlen(name) + 2;
+ ptr = (char *) xmalloc (len);
+ sprintf(ptr, "%s/%s", root, name);
+ fprintf(stderr, _("Autofixing Invalid Cross Include Path: %s -> %s\n"), name, ptr);
+ free(path);
+ path = ptr;
+ name = path;
+ return name;
+}
+#endif
+
/* Add PATH to the include chain CHAIN. PATH must be malloc-ed and
NUL-terminated. */
void
@@ -359,6 +385,11 @@
p->construct = 0;
p->user_supplied_p = user_supplied_p;
+#ifdef CROSS_COMPILE
+ path = cross_fixup_path(path);
+ p->name = path;
+#endif
+
add_cpp_dir_path (p, chain);
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-embedded] Auto Repair Cross Includes?
2008-09-21 17:12 [gentoo-embedded] Auto Repair Cross Includes? Ned Ludd
@ 2008-09-22 8:45 ` Ahmed Ammar
2008-10-26 8:14 ` Mike Frysinger
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Ahmed Ammar @ 2008-09-22 8:45 UTC (permalink / raw
To: gentoo-embedded
On Sun, 2008-09-21 at 10:12 -0700, 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.
I really like this idea, seems clean and simple to do it from gcc. I
haven't tested this out yet though but I can't see why it wouldn't work.
--
Ahmed Ammar (b33fc0d3 [at] gentoo.org)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-embedded] Auto Repair Cross Includes?
2008-09-21 17:12 [gentoo-embedded] Auto Repair Cross Includes? Ned Ludd
2008-09-22 8:45 ` Ahmed Ammar
@ 2008-10-26 8:14 ` Mike Frysinger
2008-10-26 16:39 ` Ned Ludd
2008-11-15 5:22 ` Enrico Weigelt
2009-02-05 15:32 ` Christopher Friedt
3 siblings, 1 reply; 8+ messages in thread
From: Mike Frysinger @ 2008-10-26 8:14 UTC (permalink / raw
To: gentoo-embedded; +Cc: Ned Ludd
[-- Attachment #1: Type: text/plain, Size: 3095 bytes --]
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_COMPILE,
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 = getenv("ROOT");
> + if (root == NULL)
> + return name;
perhaps you mean to return path ? "name" is uninitialized here ...
> + if (strstr(path, "/usr/include") != path)
> + return path;
seems like a funky check and one that would throw false positives ... it's
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,
if someone does "-I////usr////include////", does gcc normailize it for you
already ? if not, should do so here ...
> + name = xstrdup(path);
umm, why ? you dont use the "name" storage at all ... in fact, you leak
it ...
> + len = strlen(root) + strlen(name) + 2;
> + ptr = (char *) xmalloc (len);
pointless cast
> + sprintf(ptr, "%s/%s", root, name);
doesnt gcc (via libiberty) already provide asprintf() ? that'd make this code
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);
> + path = ptr;
> + name = path;
> + return name;
why not just drop this "name" variable altogether ? just hit up "path"
directly
> +}
> +#endif
> +
> /* Add PATH to the include chain CHAIN. PATH must be malloc-ed and
> NUL-terminated. */
> void
> @@ -359,6 +385,11 @@
> p->construct = 0;
> p->user_supplied_p = user_supplied_p;
>
> +#ifdef CROSS_COMPILE
> + path = cross_fixup_path(path);
> + p->name = path;
> +#endif
> +
> add_cpp_dir_path (p, chain);
> }
seems kind of pointless to touch "path" here since ... i'm assuming it's
function local though (havent read the actual file)
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-embedded] Auto Repair Cross Includes?
2008-10-26 8:14 ` Mike Frysinger
@ 2008-10-26 16:39 ` Ned Ludd
2008-10-26 20:07 ` Mike Frysinger
0 siblings, 1 reply; 8+ messages in thread
From: Ned Ludd @ 2008-10-26 16:39 UTC (permalink / raw
To: gentoo-embedded
On Sun, 2008-10-26 at 04:14 -0400, Mike Frysinger wrote:
> On Sunday 21 September 2008, Ned Ludd wrote:
...
> seems kind of pointless to touch "path" here since ... i'm assuming it's
> function local though (havent read the actual file)
> -mike
Talk is cheap. Show me the code brother. :)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-embedded] Auto Repair Cross Includes?
2008-10-26 16:39 ` Ned Ludd
@ 2008-10-26 20:07 ` Mike Frysinger
0 siblings, 0 replies; 8+ messages in thread
From: Mike Frysinger @ 2008-10-26 20:07 UTC (permalink / raw
To: gentoo-embedded; +Cc: Ned Ludd
[-- Attachment #1: Type: text/plain, Size: 428 bytes --]
On Sunday 26 October 2008, Ned Ludd wrote:
> On Sun, 2008-10-26 at 04:14 -0400, Mike Frysinger wrote:
> > On Sunday 21 September 2008, Ned Ludd wrote:
>
> ...
>
> > seems kind of pointless to touch "path" here since ... i'm assuming it's
> > function local though (havent read the actual file)
>
> Talk is cheap. Show me the code brother. :)
i just reviewed your code ... i dont have time to actually test/develop it ...
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-embedded] Auto Repair Cross Includes?
2008-09-21 17:12 [gentoo-embedded] Auto Repair Cross Includes? Ned Ludd
2008-09-22 8:45 ` Ahmed Ammar
2008-10-26 8:14 ` Mike Frysinger
@ 2008-11-15 5:22 ` Enrico Weigelt
2009-02-05 15:32 ` Christopher Friedt
3 siblings, 0 replies; 8+ messages in thread
From: Enrico Weigelt @ 2008-11-15 5:22 UTC (permalink / raw
To: gentoo-embedded
* Ned Ludd <solar@gentoo.org> schrieb:
Hi,
> I've been toying with an idea after seeing a patch which would abort()
> when it detected host includes for cross compiles.
Funny idea, sorts out the dozens of crap makefiles easily (eg. written
by those mindless jerks who refuse to learn not to use absolute pathes
or explicitly add standard includes).
> I did not like the idea of aborting as it prevented me from building
> pkgs that had the same headers in $ROOT as /.
sucessfully shot yourself ? ;-o
> Basic goal detect ^/usr/include and rewrite it to $ROOT/usr/include if
> using a cross compiler and ROOT is set.
#1: why not using the more standard and well-known $SYSROOT variable ?
#2: why not just using the already existing '=' prefix ?
#3: WTH do you explicitly add an standard include path like
/usr/include ?! It's automatically done by gcc nothings an
individual application has to cope with.
cu
--
---------------------------------------------------------------------
Enrico Weigelt == metux IT service - http://www.metux.de/
---------------------------------------------------------------------
Please visit the OpenSource QM Taskforce:
http://wiki.metux.de/public/OpenSource_QM_Taskforce
Patches / Fixes for a lot dozens of packages in dozens of versions:
http://patches.metux.de/
---------------------------------------------------------------------
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-embedded] Auto Repair Cross Includes?
2008-09-21 17:12 [gentoo-embedded] Auto Repair Cross Includes? Ned Ludd
` (2 preceding siblings ...)
2008-11-15 5:22 ` Enrico Weigelt
@ 2009-02-05 15:32 ` Christopher Friedt
2009-02-05 22:26 ` Ned Ludd
3 siblings, 1 reply; 8+ messages in thread
From: Christopher Friedt @ 2009-02-05 15:32 UTC (permalink / raw
To: gentoo-embedded
Hi Ned,
I like the patch - there are probably many cases where a package does
not cross compile properly when include paths are not fixed. In those
cases, it would be necessary to patch the source on an
ebuild-by-ebuild basis. This would eliminate the need to fix the files
at an ebuild level with a relatively inexpensive check.
Mike has a couple of good points too - unless it's necessary to use
thee function from outside gcc or whatever library it ends up in, it
may as well be marked static. Path vs name ? I think path. Regarding
arbitrary non-standard include paths that could generate false
positives, i have no comment.
Regarding path normalization ( "//" => "/" ) - in my opinion, if gcc
doesn't already do it, then forget about it - otherwise one would be
obliged to fix it for the rest of gcc, no? Keep it short and simple.
Depending on the level of community feedback you want, I could help
test for a while, or you could just include it in an unstable ~ gcc
version and see how the universe reacts to it :)
Regards,
Chris
On Sun, Sep 21, 2008 at 12:12 PM, Ned Ludd <solar@gentoo.org> 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.
>
>
> -solar
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-embedded] Auto Repair Cross Includes?
2009-02-05 15:32 ` Christopher Friedt
@ 2009-02-05 22:26 ` Ned Ludd
0 siblings, 0 replies; 8+ messages in thread
From: Ned Ludd @ 2009-02-05 22:26 UTC (permalink / raw
To: gentoo-embedded
On Thu, 2009-02-05 at 10:32 -0500, Christopher Friedt wrote:
> Hi Ned,
>
> I like the patch - there are probably many cases where a package does
> not cross compile properly when include paths are not fixed. In those
> cases, it would be necessary to patch the source on an
> ebuild-by-ebuild basis. This would eliminate the need to fix the files
> at an ebuild level with a relatively inexpensive check.
>
> Mike has a couple of good points too - unless it's necessary to use
> thee function from outside gcc or whatever library it ends up in, it
> may as well be marked static. Path vs name ? I think path. Regarding
> arbitrary non-standard include paths that could generate false
> positives, i have no comment.
>
> Regarding path normalization ( "//" => "/" ) - in my opinion, if gcc
> doesn't already do it, then forget about it - otherwise one would be
> obliged to fix it for the rest of gcc, no? Keep it short and simple.
>
> Depending on the level of community feedback you want, I could help
> test for a while, or you could just include it in an unstable ~ gcc
> version and see how the universe reacts to it :)
I'm all for these things. But to be honest time is limited and I've not
been having too much trouble simply using -I${ROOT}/usr/include. Every
so often a I'll need to add a non standard python include path. But it's
been easy enough to work around.
Anyway feel free to recode up a better patch to address the points you
and others have pointed out.
--
Ned Ludd <solar@gentoo.org>
Gentoo Linux
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-02-05 22:26 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-21 17:12 [gentoo-embedded] Auto Repair Cross Includes? Ned Ludd
2008-09-22 8:45 ` Ahmed Ammar
2008-10-26 8:14 ` Mike Frysinger
2008-10-26 16:39 ` Ned Ludd
2008-10-26 20:07 ` Mike Frysinger
2008-11-15 5:22 ` Enrico Weigelt
2009-02-05 15:32 ` Christopher Friedt
2009-02-05 22:26 ` Ned Ludd
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox