Currently, gcc delibrately filters out default library paths "/lib/" and
"/usr/lib/", causing some linkers like mold fails to find libraries.

This behavior was introduced at least 31 years ago in the initial
revision of the git repo, personally I think it's obsolete because:
 1. The less than 20 bytes of saving is negligible compares to the command
    line argument space of most hosts today.
 2. The driver program should provide adequate information for workers

There might be some hosts with such a small argv space that the 20-byte
saving really matters. If so, we can make this filter compiles conditionally in
these targets.

Related issue:
https://github.com/rui314/mold/issues/358

---
 gcc/gcc.cc | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 16bb07f2cdc..1beb23ba279 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -7904,17 +7904,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.40.0

Reply via email to