public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Andrew Pinski (QUIC)" <quic_apinski@quicinc.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: "iains.gcc@gmail.com" <iains.gcc@gmail.com>,
	"dje.gcc@gmail.com" <dje.gcc@gmail.com>
Subject: Request for testing on non-Linux targets; remove special casing of /usr/lib and /lib from the driver
Date: Tue, 16 Apr 2024 23:47:53 +0000	[thread overview]
Message-ID: <DM6PR02MB4058D4FAE319F0F9B10BFC82B8082@DM6PR02MB4058.namprd02.prod.outlook.com> (raw)

[-- 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


             reply	other threads:[~2024-04-16 23:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16 23:47 Andrew Pinski (QUIC) [this message]
2024-04-17 13:59 ` Rainer Orth
2024-04-17 14:33   ` Iain Sandoe
2024-04-19 17:01 ` David Edelsohn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DM6PR02MB4058D4FAE319F0F9B10BFC82B8082@DM6PR02MB4058.namprd02.prod.outlook.com \
    --to=quic_apinski@quicinc.com \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=iains.gcc@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).