diff mbox series

Don't remove /usr/lib and /lib from when passing to the linker [PR97304/104707]

Message ID 20240822211726.513334-1-quic_apinski@quicinc.com
State New
Headers show
Series Don't remove /usr/lib and /lib from when passing to the linker [PR97304/104707] | expand

Commit Message

Andrew Pinski Aug. 22, 2024, 9:17 p.m. UTC
With newer ld, the default search library path does not include /usr/lib nor /lib
but the driver decides to not pass -L down to the link for these and then in some/most
cases libc is not found.
This code dates from at least 1992 and it is done in a way which is not safe and
does not make sense. So let's remove it.

Bootstrapped and tested on x86_64-linux-gnu (which defaults to being a multilib).

gcc/ChangeLog:

	PR driver/104707
	PR driver/97304

	* gcc.cc (is_directory): Don't not include /usr/lib and /lib
	for library directory pathes. Remove library argument.
	(add_to_obstack): Update call to is_directory.
	(driver_handle_option): Likewise.
	(spec_path): Likewise.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
---
 gcc/gcc.cc | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

Comments

Gerald Pfeifer Aug. 23, 2024, 7:17 a.m. UTC | #1
On Thu, 22 Aug 2024, Andrew Pinski wrote:
> With newer ld, the default search library path does not include /usr/lib 
> nor /lib but the driver decides to not pass -L down to the link for 
> these and then in some/most cases libc is not found.
> This code dates from at least 1992 and it is done in a way which is not 
> safe and does not make sense. So let's remove it.
> 
> Bootstrapped and tested on x86_64-linux-gnu (which defaults to being a 
> multilib).

Also bootstrapped on x86_64-unknown-freebsd13.3 (this was originally 
reported against the earlier x86_64-unknown-freebsd12.1) on a system 
where I also ran into this in April.

> gcc/ChangeLog:
> 
> 	PR driver/104707
> 	PR driver/97304
> 
> 	* gcc.cc (is_directory): Don't not include /usr/lib and /lib
> 	for library directory pathes. Remove library argument.
> 	(add_to_obstack): Update call to is_directory.
> 	(driver_handle_option): Likewise.
> 	(spec_path): Likewise.

For the ChangeLog, maybe use "Don't remove /usr/lib and /lib from library 
directory paths" similar to the subject?

(My brain originally "autocorrected" and contracted "Don't not"...)


Thank you for tackling this longer standing issue which has been rearing 
its head again and again!

Gerald
Richard Biener Aug. 23, 2024, 11:01 a.m. UTC | #2
On Fri, Aug 23, 2024 at 9:18 AM Gerald Pfeifer <gerald@pfeifer.com> wrote:
>
> On Thu, 22 Aug 2024, Andrew Pinski wrote:
> > With newer ld, the default search library path does not include /usr/lib
> > nor /lib but the driver decides to not pass -L down to the link for
> > these and then in some/most cases libc is not found.
> > This code dates from at least 1992 and it is done in a way which is not
> > safe and does not make sense. So let's remove it.
> >
> > Bootstrapped and tested on x86_64-linux-gnu (which defaults to being a
> > multilib).
>
> Also bootstrapped on x86_64-unknown-freebsd13.3 (this was originally
> reported against the earlier x86_64-unknown-freebsd12.1) on a system
> where I also ran into this in April.

OK if there are no objections until next week.

Thanks,
Richard.

> > gcc/ChangeLog:
> >
> >       PR driver/104707
> >       PR driver/97304
> >
> >       * gcc.cc (is_directory): Don't not include /usr/lib and /lib
> >       for library directory pathes. Remove library argument.
> >       (add_to_obstack): Update call to is_directory.
> >       (driver_handle_option): Likewise.
> >       (spec_path): Likewise.
>
> For the ChangeLog, maybe use "Don't remove /usr/lib and /lib from library
> directory paths" similar to the subject?
>
> (My brain originally "autocorrected" and contracted "Don't not"...)
>
>
> Thank you for tackling this longer standing issue which has been rearing
> its head again and again!
>
> Gerald
diff mbox series

Patch

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index abdb40bfe6e..a02af80ec6e 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -408,7 +408,7 @@  static int do_spec_2 (const char *, const char *);
 static void do_option_spec (const char *, const char *);
 static void do_self_spec (const char *);
 static const char *find_file (const char *);
-static int is_directory (const char *, bool);
+static int is_directory (const char *);
 static const char *validate_switches (const char *, bool, bool);
 static void validate_all_switches (void);
 static inline void validate_switches_from_spec (const char *, bool);
@@ -2940,7 +2940,7 @@  add_to_obstack (char *path, void *data)
 {
   struct add_to_obstack_info *info = (struct add_to_obstack_info *) data;
 
-  if (info->check_dir && !is_directory (path, false))
+  if (info->check_dir && !is_directory (path))
     return NULL;
 
   if (!info->first_time)
@@ -4576,7 +4576,7 @@  driver_handle_option (struct gcc_options *opts,
 	   if appending a directory separator actually makes a
 	   valid directory name.  */
 	if (!IS_DIR_SEPARATOR (arg[len - 1])
-	    && is_directory (arg, false))
+	    && is_directory (arg))
 	  {
 	    char *tmp = XNEWVEC (char, len + 2);
 	    strcpy (tmp, arg);
@@ -6019,7 +6019,7 @@  spec_path (char *path, void *data)
       memcpy (path + len, info->append, info->append_len + 1);
     }
 
-  if (!is_directory (path, true))
+  if (!is_directory (path))
     return NULL;
 
   do_spec_1 (info->option, 1, NULL);
@@ -8041,11 +8041,10 @@  find_file (const char *name)
   return newname ? newname : name;
 }
 
-/* Determine whether a directory exists.  If LINKER, return 0 for
-   certain fixed names not needed by the linker.  */
+/* Determine whether a directory exists.  */
 
 static int
-is_directory (const char *path1, bool linker)
+is_directory (const char *path1)
 {
   int len1;
   char *path;
@@ -8063,17 +8062,6 @@  is_directory (const char *path1, bool linker)
   *cp++ = '.';
   *cp = '\0';
 
-  /* Exclude directories that the linker is known to search.  */
-  if (linker
-      && IS_DIR_SEPARATOR (path[0])
-      && ((cp - path == 6
-	   && filename_ncmp (path + 1, "lib", 3) == 0)
-	  || (cp - path == 10
-	      && filename_ncmp (path + 1, "usr", 3) == 0
-	      && IS_DIR_SEPARATOR (path[4])
-	      && filename_ncmp (path + 5, "lib", 3) == 0)))
-    return 0;
-
   return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
 }