<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/101661>101661</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            lld/ELF does not look in <sysroot>/usr/local/lib by default, while BFD ld does
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          nico
      </td>
    </tr>
</table>

<pre>
    Prep: Put a library in /usr/local/lib:

```
debian@debian:~$ touch empty.c
debian@debian:~$ clang -c empty.c
debian@debian:~$ ar rcs libempty.a empty.o
debian@debian:~$ sudo cp libempty.a /usr/local/lib/
```

BFD LD finds it:

```
debian@debian:~$ clang main.c -lempty 
```

LLD doesn't:

```
debian@debian:~$ clang main.c -lempty -fuse-ld=lld
ld.lld: error: unable to find library -lempty
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

BFD LD gets it from the built-in linker script:

```
debian@debian:~$ clang main.c -Wl,--verbose | grep local
SEARCH_DIR("=/usr/local/lib/aarch64-linux-gnu"); SEARCH_DIR("=/lib/aarch64-linux-gnu"); SEARCH_DIR("=/usr/lib/aarch64-linux-gnu"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib"); SEARCH_DIR("=/usr/aarch64-linux-gnu/lib");
  .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVc-PozYU_mvM5QkEDxLIgUMmDGqlOay2hx4rY7-Au8aO_CO7ufRvryCZdqZKp9F2JbCN_L7vvc_-jLn3ajRELds8sU2X8Bgm61qjhE0GKy_tJ0cnVu7hUwzAQavBcXcBZYBhH71j2GsruF56NbByz_KO5a_tNr8966ekQXHDqvw2KPd_MKwg2CgmoPkULpn4MFJobkZIxUPB3IETfqn4Gs1vKPshykdpQZzewu4Kxf6uxGv71Hfw0sFRGelBhe9alavWmSuTCUj1Wgx8kPPlpQNpyRuG9Q_MmB6jp1RLVnZayytey2wZl3sg56xbBtHwQRMEu4r-yyY3lits5X-H0sp8IQfCzjM3Eo5caZLwVYUJ6JsKIKwkKIBhEz1Bel74PREoc7aCB2UNw91_78NIYdkGODo7Q5gIhqh0SJV5LcALp04_YtF-1QwPaXomN1hPwOoDjI5OcHXOyvPL8_7z4affup8_M2wYIiu7fzEY505M2yrVysRv6WjiEo07Vj7BfZLvhN1y_y_w28IfKPLhgh4JvFPzO_B13QEyyQPPHOnMWVjsx-onYLhn2Lydym5i9pCNJmaLRawRlMl389kK3N3Bv8uTfcDzylB3_zBcIttS7sodT6gtasRtXmDVJFNbyk3JG1Hny3s8Sk5VWdMg66ZAUe3qRLWYY5U3ORaIebXJhkJUm6bIj0Wz2eRNyaqcZq50pvV5zqwbE-V9pLbIi-22SDQfSPv1LkBczjjicim4dglPhzh6VuVa-eD_JggqaGrX4P75pV9_QmBsAG3tl_WiKA_-4p21gZXP9ywDwwUkHXnUgeEBvk5KEyxnV8uVLYlOt1MIJ78cUewZ9qMKUxwyYeeFQp9fu_Tk7O8kAsN-FeYZ9jdt5xb_DAAA__-THAjv">