public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch]: Fix argv[0] for dos based filesystem
@ 2008-05-18 13:27 Kai Tietz
  2008-05-18 16:33 ` Kai Tietz
  2008-05-22 17:23 ` [patch]: " Tom Tromey
  0 siblings, 2 replies; 6+ messages in thread
From: Kai Tietz @ 2008-05-18 13:27 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 728 bytes --]

Hi,

this patch is a work-a-round for the problem in spec-file parsing for
dos based file system in gcc.c (and additionally fix this for
cc1,cc1plus,...). The spec-file parser eats backslashes, because it
assumes, that they are escape sequences. For environment variables the
pre-escape by back-slashes is done, but for the relative targets on
dos based file systems the argv[0] isn't escaped.

ChangeLog

2008-05-18  Kai Tietz  <kai.tietz@onevision.com>

	* gcc.c (main): Replace backslashes by slashes
	for dos based file systems.
	* main.c (main): Likewise.

Is this patch ok for apply?

Cheers,
  Kai

-- 
| (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

[-- Attachment #2: dosbase.txt --]
[-- Type: text/plain, Size: 593 bytes --]

Index: gcc/gcc/gcc.c
===================================================================
--- gcc.orig/gcc/gcc.c
+++ gcc/gcc/gcc.c
@@ -6207,6 +6207,16 @@ main (int argc, char **argv)
   struct user_specs *uptr;
   char **old_argv = argv;
 
+#if HAVE_DOS_BASED_FILE_SYSTEM
+   if (argc > 0)
+     {
+	   char *pp;
+	   argv[0]=xstrdup (argv[0]);
+	   while ((pp = strchr (argv[0], '\\')) != NULL)
+		 *pp = '/';
+     }
+#endif
+
   /* Initialize here, not in definition.  The IRIX 6 O32 cc sometimes chokes
      on ?: in file-scope variable initializations.  */
   asm_debug = ASM_DEBUG_SPEC;

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch]: Fix argv[0] for dos based filesystem
  2008-05-18 13:27 [patch]: Fix argv[0] for dos based filesystem Kai Tietz
@ 2008-05-18 16:33 ` Kai Tietz
  2008-05-21  7:42   ` [ping patch]: " Kai Tietz
  2008-05-22 17:23 ` [patch]: " Tom Tromey
  1 sibling, 1 reply; 6+ messages in thread
From: Kai Tietz @ 2008-05-18 16:33 UTC (permalink / raw)
  To: GCC Patches; +Cc: ghazi

2008/5/18 Kai Tietz <ktietz70@googlemail.com>:
> Hi,
>
> this patch is a work-a-round for the problem in spec-file parsing for
> dos based file system in gcc.c (and additionally fix this for
> cc1,cc1plus,...). The spec-file parser eats backslashes, because it
> assumes, that they are escape sequences. For environment variables the
> pre-escape by back-slashes is done, but for the relative targets on
> dos based file systems the argv[0] isn't escaped.
>
> ChangeLog
>
> 2008-05-18  Kai Tietz  <kai.tietz@onevision.com>
>
>        * gcc.c (main): Replace backslashes by slashes
>        for dos based file systems.
>        * main.c (main): Likewise.
>
> Is this patch ok for apply?
>
> Cheers,
>  Kai
>
> --
> | (\_/) This is Bunny. Copy and paste
> | (='.'=) Bunny into your signature to help
> | (")_(") him gain world domination
>

As note:

This change of behaviourwas introduced on revision 128051+ (IIUC),
while the port to use const types in gcc.

Cheers,
  Kai

-- 
| (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ping patch]: Fix argv[0] for dos based filesystem
  2008-05-18 16:33 ` Kai Tietz
@ 2008-05-21  7:42   ` Kai Tietz
  0 siblings, 0 replies; 6+ messages in thread
From: Kai Tietz @ 2008-05-21  7:42 UTC (permalink / raw)
  To: GCC Patches

> 2008/5/18 Kai Tietz <ktietz70@googlemail.com>:
> > Hi,
> >
> > this patch is a work-a-round for the problem in spec-file parsing for
> > dos based file system in gcc.c (and additionally fix this for
> > cc1,cc1plus,...). The spec-file parser eats backslashes, because it
> > assumes, that they are escape sequences. For environment variables the
> > pre-escape by back-slashes is done, but for the relative targets on
> > dos based file systems the argv[0] isn't escaped.
> >
> > ChangeLog
> >
> > 2008-05-18  Kai Tietz  <kai.tietz@onevision.com>
> >
> >        * gcc.c (main): Replace backslashes by slashes
> >        for dos based file systems.
> >        * main.c (main): Likewise.
> >
> > Is this patch ok for apply?
> 
> As note:
> 
> This change of behaviourwas introduced on revision 128051+ (IIUC),
> while the port to use const types in gcc.

Cheers,
  Kai

|  (\_/)  This is Bunny. Copy and paste Bunny
| (='.'=) into your signature to help him gain
| (")_(") world domination.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch]: Fix argv[0] for dos based filesystem
  2008-05-18 13:27 [patch]: Fix argv[0] for dos based filesystem Kai Tietz
  2008-05-18 16:33 ` Kai Tietz
@ 2008-05-22 17:23 ` Tom Tromey
  2008-05-22 17:37   ` Kai Tietz
  1 sibling, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2008-05-22 17:23 UTC (permalink / raw)
  To: Kai Tietz; +Cc: GCC Patches

>>>>> "Kai" == Kai Tietz <ktietz70@googlemail.com> writes:

Kai> 2008-05-18  Kai Tietz  <kai.tietz@onevision.com>
Kai> 	* gcc.c (main): Replace backslashes by slashes
Kai> 	for dos based file systems.
Kai> 	* main.c (main): Likewise.
Kai> Is this patch ok for apply?

This is not ok as-is.  There are some coding standards violations.

Kai> +#if HAVE_DOS_BASED_FILE_SYSTEM
Kai> +   if (argc > 0)
Kai> +     {
Kai> +	   char *pp;
Kai> +	   argv[0]=xstrdup (argv[0]);

Spaces around '='.
Also, why make a copy of argv[0] here?

Kai> +	   while ((pp = strchr (argv[0], '\\')) != NULL)
Kai> +		 *pp = '/';

Usually GNU style doesn't allow assignments in conditions.

Kai> This change of behaviourwas introduced on revision 128051+
Kai> (IIUC), while the port to use const types in gcc.

I looked at that diff to gcc.c but I don't see how it could cause a
problem.

Actually I don't really understand the bug this patch is fixing.
Could you explain more?

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch]: Fix argv[0] for dos based filesystem
  2008-05-22 17:23 ` [patch]: " Tom Tromey
@ 2008-05-22 17:37   ` Kai Tietz
  2008-05-23 19:18     ` Mark Mitchell
  0 siblings, 1 reply; 6+ messages in thread
From: Kai Tietz @ 2008-05-22 17:37 UTC (permalink / raw)
  To: tromey; +Cc: GCC Patches

2008/5/22 Tom Tromey <tromey@redhat.com>:
>>>>>> "Kai" == Kai Tietz <ktietz70@googlemail.com> writes:
>
> Kai> 2008-05-18  Kai Tietz  <kai.tietz@onevision.com>
> Kai>    * gcc.c (main): Replace backslashes by slashes
> Kai>    for dos based file systems.
> Kai>    * main.c (main): Likewise.
> Kai> Is this patch ok for apply?
>
> This is not ok as-is.  There are some coding standards violations.
>
> Kai> +#if HAVE_DOS_BASED_FILE_SYSTEM
> Kai> +   if (argc > 0)
> Kai> +     {
> Kai> +     char *pp;
> Kai> +     argv[0]=xstrdup (argv[0]);
>
> Spaces around '='.
> Also, why make a copy of argv[0] here?
>
> Kai> +     while ((pp = strchr (argv[0], '\\')) != NULL)
> Kai> +           *pp = '/';
>
> Usually GNU style doesn't allow assignments in conditions.
>
> Kai> This change of behaviourwas introduced on revision 128051+
> Kai> (IIUC), while the port to use const types in gcc.
>
> I looked at that diff to gcc.c but I don't see how it could cause a
> problem.
>
> Actually I don't really understand the bug this patch is fixing.
> Could you explain more?
>
> Tom
>

The problem fixed here is related to the backslashes in argv[0] on dos
based file systems. If you build gcc with option --prefix and
--with-sysroot, gcc uses argv[0] to find the location of the exec_dir.
This path is used within spec parser to relocate the tools, but it
additional eats the backslashes from the path, because they are not
quoted.

I hope I could explain the problem,

Cheers,
  Kai

-- 
| (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch]: Fix argv[0] for dos based filesystem
  2008-05-22 17:37   ` Kai Tietz
@ 2008-05-23 19:18     ` Mark Mitchell
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Mitchell @ 2008-05-23 19:18 UTC (permalink / raw)
  To: Kai Tietz; +Cc: tromey, GCC Patches

Kai Tietz wrote:

> The problem fixed here is related to the backslashes in argv[0] on dos
> based file systems. If you build gcc with option --prefix and
> --with-sysroot, gcc uses argv[0] to find the location of the exec_dir.
> This path is used within spec parser to relocate the tools, but it
> additional eats the backslashes from the path, because they are not
> quoted.
> 
> I hope I could explain the problem,

In that case, it sounds like the fix is to escape the backslashes in 
argv[0] -- probably on *all* systems -- before passing it to the specs 
system.  A directory named "x\y" (that's a literal backslash!) is 
perfectly valid on a UNIX system, and we need to escape that string 
there too.

IIRC, changing backslashes to forward slashes on Windows is not in 
general safe; at least on some older versions of the OS, some system 
functions don't work correctly.  And, you certainly confuse users; if I 
use "C:\foo\bar" as the name of a file, that's what I expect an 
application to call it too.

Thanks,

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-05-23 18:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-18 13:27 [patch]: Fix argv[0] for dos based filesystem Kai Tietz
2008-05-18 16:33 ` Kai Tietz
2008-05-21  7:42   ` [ping patch]: " Kai Tietz
2008-05-22 17:23 ` [patch]: " Tom Tromey
2008-05-22 17:37   ` Kai Tietz
2008-05-23 19:18     ` Mark Mitchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).