From 64e0742e65241bcc708909052e426950c8324e14 Mon Sep 17 00:00:00 2001 From: Andy Fiddaman Date: Mon, 11 Jan 2021 14:09:40 +0000 Subject: [PATCH 31/39] -zassert-deflib depends on default library paths being elided --- gcc/gcc.cc | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 4fd87f2c4a1..4da60ea2b4e 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -415,7 +415,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 *); +static int is_directory (const char *, bool); 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); @@ -2947,7 +2947,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)) + if (info->check_dir && !is_directory (path, false)) return NULL; if (!info->first_time) @@ -4599,7 +4599,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)) + && is_directory (arg, false)) { char *tmp = XNEWVEC (char, len + 2); strcpy (tmp, arg); @@ -6042,7 +6042,7 @@ spec_path (char *path, void *data) memcpy (path + len, info->append, info->append_len + 1); } - if (!is_directory (path)) + if (!is_directory (path, true)) return NULL; do_spec_1 (info->option, 1, NULL); @@ -8071,10 +8071,11 @@ find_file (const char *name) return newname ? newname : name; } -/* Determine whether a directory exists. */ +/* Determine whether a directory exists. If LINKER, return 0 for + certain fixed names not needed by the linker. */ static int -is_directory (const char *path1) +is_directory (const char *path1, bool linker) { int len1; char *path; @@ -8092,6 +8093,36 @@ is_directory (const char *path1) *cp++ = '.'; *cp = '\0'; + /* Exclude directories that the linker is known to search. */ + if (linker && IS_DIR_SEPARATOR (path[0])) { + size_t len = cp - path; + + if (len >= 6 && filename_ncmp (path + 1, "lib", 3) == 0) { + if (len == 6) + return 0; + if (multilib_os_dir != NULL + && len == 6 + strlen(multilib_os_dir) + 1 + && filename_ncmp(path + 5, multilib_os_dir, + strlen(multilib_os_dir)) == 0) { + return 0; + } + } + + if (len >= 10 + && filename_ncmp (path + 1, "usr", 3) == 0 + && IS_DIR_SEPARATOR (path[4]) + && filename_ncmp (path + 5, "lib", 3) == 0) { + if (len == 10) + return 0; + if (multilib_os_dir != NULL + && len == 10 + strlen(multilib_os_dir) + 1 + && filename_ncmp(path + 9, multilib_os_dir, + strlen(multilib_os_dir)) == 0) { + return 0; + } + } + } + return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode)); } -- 2.53.0