public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Request for testing on non-Linux targets; remove special casing of /usr/lib and /lib from the driver
@ 2024-04-16 23:47 Andrew Pinski (QUIC)
  2024-04-17 13:59 ` Rainer Orth
  2024-04-19 17:01 ` David Edelsohn
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Pinski (QUIC) @ 2024-04-16 23:47 UTC (permalink / raw)
  To: gcc-patches; +Cc: iains.gcc, dje.gcc

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

Hi all,
  The driver currently will remove "/lib" and "/usr/lib" from the library path that gets passed to the linker because it considers them as paths that the linker will already known to search. But this is not true for newer linkers, mold and lld for an example don't have a default search path.
This patch removes the special casing to fix FreeBSD building where lld is used by default and also fix riscv-linux-gnu when used in combination with mold. 
I have tested it on x86_64-linux-gnu and it works there but since the code in the driver has been around since 1992, I request some folks to test it on AIX, Mac OS (Darwin) and solaris where the ld is not GNU bfd ld as I don't have access to those targets currently.

Thanks,
Andrew Pinski

[-- Attachment #2: 0001-Don-t-remove-usr-lib-and-lib-from-when-passing-to-th.patch --]
[-- Type: application/octet-stream, Size: 3500 bytes --]

From f26a10ca1b9c03b3340b7076d370ea439db549ce Mon Sep 17 00:00:00 2001
From: Andrew Pinski <quic_apinski@quicinc.com>
Date: Tue, 16 Apr 2024 12:06:51 -0700
Subject: [PATCH] Don't remove /usr/lib and /lib from when passing to the
 linker [PR97304/104707]

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(-)

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 728332b8153..90b613f355d 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);
@@ -2936,7 +2936,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)
@@ -4561,7 +4561,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);
@@ -6004,7 +6004,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);
@@ -8026,11 +8026,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;
@@ -8048,17 +8047,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));
 }
 
-- 
2.43.0


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

* Re: Request for testing on non-Linux targets; remove special casing of /usr/lib and /lib from the driver
  2024-04-16 23:47 Request for testing on non-Linux targets; remove special casing of /usr/lib and /lib from the driver Andrew Pinski (QUIC)
@ 2024-04-17 13:59 ` Rainer Orth
  2024-04-17 14:33   ` Iain Sandoe
  2024-04-19 17:01 ` David Edelsohn
  1 sibling, 1 reply; 4+ messages in thread
From: Rainer Orth @ 2024-04-17 13:59 UTC (permalink / raw)
  To: Andrew Pinski (QUIC); +Cc: gcc-patches, iains.gcc, dje.gcc

Hi Andrew,

>   The driver currently will remove "/lib" and "/usr/lib" from the library
> path that gets passed to the linker because it considers them as paths that
> the linker will already known to search. But this is not true for newer
> linkers, mold and lld for an example don't have a default search path.
> This patch removes the special casing to fix FreeBSD building where lld is
> used by default and also fix riscv-linux-gnu when used in combination with
> mold.
> I have tested it on x86_64-linux-gnu and it works there but since the code
> in the driver has been around since 1992, I request some folks to test it
> on AIX, Mac OS (Darwin) and solaris where the ld is not GNU bfd ld as I
> don't have access to those targets currently.

actually, you do: all of those are availble inside the cfarm.

I've also tested the patch on i386-pc-solaris2.11 and
sparc-sun-solaris2.11 with the native ld: no regressions in either case.

From what I can see, the handling of -Y P,* in gcc/config/sol2.h
(LINK_ARCH{32,64}_SPEC_BASE) can go as well.  I'll test this, but this
is almost certainly GCC 15 material.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

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

* Re: Request for testing on non-Linux targets; remove special casing of /usr/lib and /lib from the driver
  2024-04-17 13:59 ` Rainer Orth
@ 2024-04-17 14:33   ` Iain Sandoe
  0 siblings, 0 replies; 4+ messages in thread
From: Iain Sandoe @ 2024-04-17 14:33 UTC (permalink / raw)
  Cc: Andrew Pinski (QUIC), GCC Patches, David Edelsohn, Rainer Orth

Hi Andrew,

> On 17 Apr 2024, at 14:59, Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> wrote:

>>  The driver currently will remove "/lib" and "/usr/lib" from the library
>> path that gets passed to the linker because it considers them as paths that
>> the linker will already known to search. But this is not true for newer
>> linkers, mold and lld for an example don't have a default search path.
>> This patch removes the special casing to fix FreeBSD building where lld is
>> used by default and also fix riscv-linux-gnu when used in combination with
>> mold.
>> I have tested it on x86_64-linux-gnu and it works there but since the code
>> in the driver has been around since 1992, I request some folks to test it
>> on AIX, Mac OS (Darwin) and solaris where the ld is not GNU bfd ld as I
>> don't have access to those targets currently.
> 
> actually, you do: all of those are availble inside the cfarm.
> 
> I've also tested the patch on i386-pc-solaris2.11 and
> sparc-sun-solaris2.11 with the native ld: no regressions in either case.

I tested so far on x86_64 darwin, but the behaviour of collect2 is the same
for all arches.  Actually, I do not see any difference in behaviour when looking
at the -Wl,-v output (it seems that somehow those paths are not currently
pruned for Darwin; if I add -L /lib to the command line on a GCC build without
this patch it is passed through despite that it’s non-existent).  However, that’s
a separate bug, perhaps.

So - as far as this patch is concerned it seems OK for Darwin,
Iain


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

* Re: Request for testing on non-Linux targets; remove special casing of /usr/lib and /lib from the driver
  2024-04-16 23:47 Request for testing on non-Linux targets; remove special casing of /usr/lib and /lib from the driver Andrew Pinski (QUIC)
  2024-04-17 13:59 ` Rainer Orth
@ 2024-04-19 17:01 ` David Edelsohn
  1 sibling, 0 replies; 4+ messages in thread
From: David Edelsohn @ 2024-04-19 17:01 UTC (permalink / raw)
  To: Andrew Pinski (QUIC); +Cc: gcc-patches, iains.gcc

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

The patch does not cause failures on AIX.  Is it removing explicit
references to /lib and /usr/lib?

It seems more appropriate for GCC 15.

Thanks for alerting me to the patch to test on AIX.  AIX is in CFarm.

Thanks David

On Tue, Apr 16, 2024 at 7:49 PM Andrew Pinski (QUIC) <
quic_apinski@quicinc.com> wrote:

> Hi all,
>   The driver currently will remove "/lib" and "/usr/lib" from the library
> path that gets passed to the linker because it considers them as paths that
> the linker will already known to search. But this is not true for newer
> linkers, mold and lld for an example don't have a default search path.
> This patch removes the special casing to fix FreeBSD building where lld is
> used by default and also fix riscv-linux-gnu when used in combination with
> mold.
> I have tested it on x86_64-linux-gnu and it works there but since the code
> in the driver has been around since 1992, I request some folks to test it
> on AIX, Mac OS (Darwin) and solaris where the ld is not GNU bfd ld as I
> don't have access to those targets currently.
>
> Thanks,
> Andrew Pinski
>

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

end of thread, other threads:[~2024-04-19 17:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-16 23:47 Request for testing on non-Linux targets; remove special casing of /usr/lib and /lib from the driver Andrew Pinski (QUIC)
2024-04-17 13:59 ` Rainer Orth
2024-04-17 14:33   ` Iain Sandoe
2024-04-19 17:01 ` David Edelsohn

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).