https://gcc.gnu.org/g:3fb90724cec7e76b60fb910fa98b4ebec9912a31
commit r15-3321-g3fb90724cec7e76b60fb910fa98b4ebec9912a31 Author: Andrew Pinski <quic_apin...@quicinc.com> Date: Tue Apr 16 12:06:51 2024 -0700 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_apin...@quicinc.com> Diff: --- gcc/gcc.cc | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index d07a8e172a47..ae1d80fe00a2 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -409,7 +409,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); @@ -2941,7 +2941,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) @@ -4577,7 +4577,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); @@ -6020,7 +6020,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); @@ -8042,11 +8042,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; @@ -8064,17 +8063,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)); }