diff mbox

[DRIVER] Wrong C++ include paths when configuring with "--with-sysroot=/"

Message ID 55353241.5020105@samsung.com
State New
Headers show

Commit Message

Pavel Kopyl April 20, 2015, 5:07 p.m. UTC
Hi all,


To build a GCC-4.9.2 ARM cross-compiler for my setting I need to 
configure it with  "--with-sysroot=/ 
--with-gxx-include-dir=/usr/include/c++/4.9.2".
But I found that gcc driver removes the leading slash from resulting paths:

`gcc -print-prog-name=cc1plus` -v
...
ignoring nonexistent directory "usr/include/c++/4.9.2"   <- HERE
ignoring nonexistent directory 
"usr/include/c++/4.9.2/armv7l-tizen-linux-gnueabi"   <- AND HERE
ignoring nonexistent directory "usr/include/c++/4.9.2/backward" <- AND HERE
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/armv7l-tizen-linux-gnueabi/4.9.2/include
/usr/local/include
/usr/lib/gcc/armv7l-tizen-linux-gnueabi/4.9.2/include-fixed
/usr/include

It's also reproducible on trunk.

Attached patch fixes this bug.

Thanks,
Pavel.

Comments

Joseph Myers May 7, 2015, 10:07 p.m. UTC | #1
On Mon, 20 Apr 2015, Pavel Kopyl wrote:

> Hi all,
> 
> 
> To build a GCC-4.9.2 ARM cross-compiler for my setting I need to configure it
> with  "--with-sysroot=/ --with-gxx-include-dir=/usr/include/c++/4.9.2".
> But I found that gcc driver removes the leading slash from resulting paths:
> 
> `gcc -print-prog-name=cc1plus` -v
> ...
> ignoring nonexistent directory "usr/include/c++/4.9.2"   <- HERE
> ignoring nonexistent directory
> "usr/include/c++/4.9.2/armv7l-tizen-linux-gnueabi"   <- AND HERE
> ignoring nonexistent directory "usr/include/c++/4.9.2/backward" <- AND HERE
> #include "..." search starts here:
> #include <...> search starts here:
> /usr/lib/gcc/armv7l-tizen-linux-gnueabi/4.9.2/include
> /usr/local/include
> /usr/lib/gcc/armv7l-tizen-linux-gnueabi/4.9.2/include-fixed
> /usr/include
> 
> It's also reproducible on trunk.
> 
> Attached patch fixes this bug.

You don't explain the rationale for this patch, in terms of the logical 
semantics of the various variables involved, and why, in terms of those 
logical semantics, this patch is the correct approach for fixing the 
observed problems.

As I read the code, it's not the driver that removes the leading slash.  
Rather, it's the code in configure.ac:

gcc_gxx_include_dir_add_sysroot=0
if test "${with_sysroot+set}" = set; then
  gcc_gxx_without_sysroot=`expr "${gcc_gxx_include_dir}" : "${with_sysroot}"'\(.*\)'`
  if test "${gcc_gxx_without_sysroot}"; then
    gcc_gxx_include_dir="${gcc_gxx_without_sysroot}"
    gcc_gxx_include_dir_add_sysroot=1
  fi
fi

What I'd say is that this code is mishandling the case of a --with-sysroot 
path that ends with '/' (or, I suppose, '\', on hosts where that's a 
directory separator).  That is, it's producing a gcc_gxx_include_dir 
setting with no leading '/'.  I think it would be more appropriate for 
this configure.ac code to remove (sysroot minus trailing directory 
separator), so that the gcc_gxx_include_dir setting after this code still 
has a leading directory separator whether or not the --with-sysroot 
setting ended with such a separator.  Given such a configure.ac change, I 
wouldn't then expect changes elsewhere in the compiler to be needed.  But 
if that doesn't work to fix the bug, I think you need to elaborate further 
on the semantics of the various variables involved (in configure.ac and in 
the compiler).
Yvan Roux May 21, 2015, 6:30 a.m. UTC | #2
Hi,

On 8 May 2015 at 00:07, Joseph Myers <joseph@codesourcery.com> wrote:
> On Mon, 20 Apr 2015, Pavel Kopyl wrote:
>
>> Hi all,
>>
>>
>> To build a GCC-4.9.2 ARM cross-compiler for my setting I need to configure it
>> with  "--with-sysroot=/ --with-gxx-include-dir=/usr/include/c++/4.9.2".
>> But I found that gcc driver removes the leading slash from resulting paths:
>>
>> `gcc -print-prog-name=cc1plus` -v
>> ...
>> ignoring nonexistent directory "usr/include/c++/4.9.2"   <- HERE
>> ignoring nonexistent directory
>> "usr/include/c++/4.9.2/armv7l-tizen-linux-gnueabi"   <- AND HERE
>> ignoring nonexistent directory "usr/include/c++/4.9.2/backward" <- AND HERE
>> #include "..." search starts here:
>> #include <...> search starts here:
>> /usr/lib/gcc/armv7l-tizen-linux-gnueabi/4.9.2/include
>> /usr/local/include
>> /usr/lib/gcc/armv7l-tizen-linux-gnueabi/4.9.2/include-fixed
>> /usr/include
>>
>> It's also reproducible on trunk.
>>
>> Attached patch fixes this bug.
>
> You don't explain the rationale for this patch, in terms of the logical
> semantics of the various variables involved, and why, in terms of those
> logical semantics, this patch is the correct approach for fixing the
> observed problems.
>
> As I read the code, it's not the driver that removes the leading slash.
> Rather, it's the code in configure.ac:
>
> gcc_gxx_include_dir_add_sysroot=0
> if test "${with_sysroot+set}" = set; then
>   gcc_gxx_without_sysroot=`expr "${gcc_gxx_include_dir}" : "${with_sysroot}"'\(.*\)'`
>   if test "${gcc_gxx_without_sysroot}"; then
>     gcc_gxx_include_dir="${gcc_gxx_without_sysroot}"
>     gcc_gxx_include_dir_add_sysroot=1
>   fi
> fi
>
> What I'd say is that this code is mishandling the case of a --with-sysroot
> path that ends with '/' (or, I suppose, '\', on hosts where that's a
> directory separator).  That is, it's producing a gcc_gxx_include_dir
> setting with no leading '/'.  I think it would be more appropriate for
> this configure.ac code to remove (sysroot minus trailing directory
> separator), so that the gcc_gxx_include_dir setting after this code still
> has a leading directory separator whether or not the --with-sysroot
> setting ended with such a separator.  Given such a configure.ac change, I
> wouldn't then expect changes elsewhere in the compiler to be needed.  But
> if that doesn't work to fix the bug, I think you need to elaborate further
> on the semantics of the various variables involved (in configure.ac and in
> the compiler).

There is this old patch submitted by Matthias on that same issue, if
its logic is the right one for you Joseph I can rebase/validate it
Joseph.

https://gcc.gnu.org/ml/gcc-patches/2012-02/msg00320.html

Cheers,
Yvan

> --
> Joseph S. Myers
> joseph@codesourcery.com
Joseph Myers May 21, 2015, 4:58 p.m. UTC | #3
On Thu, 21 May 2015, Yvan Roux wrote:

> There is this old patch submitted by Matthias on that same issue, if
> its logic is the right one for you Joseph I can rebase/validate it
> Joseph.
> 
> https://gcc.gnu.org/ml/gcc-patches/2012-02/msg00320.html

Yes, that seems better.
diff mbox

Patch

gcc/Changelog

2015-04-20  Pavel Kopyl  <p.kopyl@samsung.com>

    	* gcc.c (add_sysrooted_prefix): Add new variable 'real_sysroot'.
    	Pass it to 'concat()' instead of 'sysroot_no_trailing_dir_separator'.
    	* incpath.c (add_standard_paths): Likewise.

diff --git a/gcc/gcc.c b/gcc/gcc.c
index c3d44b1..b0b7515 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -2581,11 +2581,19 @@  add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix,
 	sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
 
       if (target_sysroot_suffix)
-	prefix = concat (sysroot_no_trailing_dir_separator,
-			 target_sysroot_suffix, prefix, NULL);
+	{
+	  const char *real_sysroot
+	     = ((target_sysroot_suffix[0] == DIR_SEPARATOR)
+		? sysroot_no_trailing_dir_separator : target_system_root);
+	  prefix = concat (real_sysroot, target_sysroot_suffix, prefix, NULL);
+	}
       else
-	prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL);
-
+	{
+	  const char *real_sysroot
+	    = ((prefix[0] == DIR_SEPARATOR)
+	       ? sysroot_no_trailing_dir_separator : target_system_root);
+	  prefix = concat (real_sysroot, prefix, NULL);
+	}
       free (sysroot_no_trailing_dir_separator);
 
       /* We have to override this because GCC's notion of sysroot
diff --git a/gcc/incpath.c b/gcc/incpath.c
index f495c0a..2387db6 100644
--- a/gcc/incpath.c
+++ b/gcc/incpath.c
@@ -178,10 +178,14 @@  add_standard_paths (const char *sysroot, const char *iprefix,
 	    {
 	      char *sysroot_no_trailing_dir_separator = xstrdup (sysroot);
 	      size_t sysroot_len = strlen (sysroot);
+	      const char *real_sysroot;
 
 	      if (sysroot_len > 0 && sysroot[sysroot_len - 1] == DIR_SEPARATOR)
 		sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
-	      str = concat (sysroot_no_trailing_dir_separator, p->fname, NULL);
+
+	      real_sysroot = ((p->fname[0] == DIR_SEPARATOR)
+			      ? sysroot_no_trailing_dir_separator : sysroot);
+	      str = concat (real_sysroot, p->fname, NULL);
 	      free (sysroot_no_trailing_dir_separator);
 	    }
 	  else if (!p->add_sysroot && relocated