This means, we might search for: - path/$machine/$version/prog - path/$machine/prog - path/$machine-prog
But not - path/$machine/$version/$machine-prog because disambiguating $machine twice is unnecessary. This does mean we less liberal in what we accept than LLVM, but that's OK. (The down side of always following Postel's law is that everyone converges on accepting all sorts of garbage, which makes debugging end-to-end hard when mistakes are not caught early.) In plainer language: while I am citing LLVM as precedent, I am conservatively only adopting the parts of LLVM's behavior that I actually need, and which I think is the most justifiable. It is easier to further liberalize the search behavior later (always look for prefixed and unprefixed, lets say), than tighten it up (creating a breaking change). * gcc.cc (program_at_path): Use the boolean parameter added in the previous commit to implement the above logic. Signed-off-by: John Ericson <g...@johnericson.me> --- gcc/gcc.cc | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 81025d4fafe..e98a67fdaec 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -3097,15 +3097,9 @@ program_at_path (char *path, bool machine_specific, void *data) struct file_at_path_info *info = (struct file_at_path_info *) data; size_t path_len = strlen (path); - for (auto prefix : { just_machine_prefix, "" }) + auto search = [=](size_t len) -> void * { - auto len = path_len; - - auto prefix_len = strlen(prefix); - memcpy (path + len, prefix, prefix_len); - len += prefix_len; - - memcpy (path + len, info->name, info->name_len); + memcpy (path + len, info->name, info->name_len + 1); len += info->name_len; /* Some systems have a suffix for executable files. @@ -3120,9 +3114,22 @@ program_at_path (char *path, bool machine_specific, void *data) path[len] = '\0'; if (access_check (path, info->mode) == 0) return path; + + return NULL; + }; + + /* Additionally search for $target-prog in machine-agnostic dirs, as an + additional way to disambiguate targets. Do not do this in machine-specific + dirs because so further disambiguation is needed. */ + if (!machine_specific) + { + auto prefix_len = strlen(just_machine_prefix); + memcpy (path + path_len, just_machine_prefix, prefix_len); + auto res = search(path_len + prefix_len); + if (res) return res; } - return NULL; + return search(path_len); } /* Specialization of find_a_file for programs that also takes into account -- 2.49.0