diff mbox

avoid '//' prefixes when sysroot is set to '/'

Message ID 4F2024FC.8060200@ubuntu.com
State New
Headers show

Commit Message

Matthias Klose Jan. 25, 2012, 3:51 p.m. UTC
when setting sysroot to / (for whatever reason), then search directories and 
headers start with a double-slash, as seen with gcc -v.

#include "..." search starts here:
#include <...> search starts here:
  /usr/lib/gcc/x86_64-linux-gnu/4.6/include
  //usr/local/include
  /usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
  //usr/include/x86_64-linux-gnu
  //usr/include
End of search list.

LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/://lib/x86_64-linux-gnu/://lib/../lib/://usr/lib/x86_64-linux-gnu/://usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../://lib/://usr/lib/

This can end up in generation for dependency files, and other files parsing the 
output. The solution I came up with is to check for sysroot set to '/' and 
special case this in two places. Afaics, there are no other places.

With the patch, both the include paths and the library paths start with a single 
slash. No regressions seen running the testsuite on x86_64-linux-gnu.

   Matthias
2012-01-24  Matthias Klose  <doko@ubuntu.com>

	* gcc.c (add_sysrooted_prefix): Don't prefix with the system root,
	  if it is the root directory.
	* incpath.c (add_standard_paths): Likewise.

Comments

Joseph Myers Jan. 25, 2012, 4:45 p.m. UTC | #1
On Wed, 25 Jan 2012, Matthias Klose wrote:

> This can end up in generation for dependency files, and other files parsing
> the output. The solution I came up with is to check for sysroot set to '/' and
> special case this in two places. Afaics, there are no other places.

I could imagine a sysroot path that isn't just '/' but ends with '/' 
resulting in duplicate '/' in the middle of the path - although that's not 
a correctness issue in the way that '//' at the start could be, maybe the 
best check is actually for '/' at end of sysroot (in which case skip the 
'/' at the start of the path within the sysroot)?  Or remove such a '/' at 
end of sysroot at configure time rather than checking for it later....
diff mbox

Patch

Index: gcc/incpath.c
===================================================================
--- gcc/incpath.c	(revision 183421)
+++ gcc/incpath.c	(working copy)
@@ -166,7 +166,10 @@ 
 
 	  /* Should this directory start with the sysroot?  */
 	  if (sysroot && p->add_sysroot)
-	    str = concat (sysroot, p->fname, NULL);
+	    if (IS_DIR_SEPARATOR (*sysroot) && sysroot[1] == '\0')
+	      str = concat (p->fname, NULL);
+	    else
+	      str = concat (sysroot, p->fname, NULL);
 	  else if (!p->add_sysroot && relocated
 		   && !filename_ncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len))
 	    {
Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c	(revision 183421)
+++ gcc/gcc.c	(working copy)
@@ -2443,7 +2443,9 @@ 
   if (!IS_ABSOLUTE_PATH (prefix))
     fatal_error ("system path %qs is not absolute", prefix);
 
-  if (target_system_root)
+  if (target_system_root 
+      && !IS_DIR_SEPARATOR (*target_system_root)
+      && target_system_root[1] != '\0')
     {
       if (target_sysroot_suffix)
 	  prefix = concat (target_sysroot_suffix, prefix, NULL);