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

    <tr>
        <th>Summary</th>
        <td>
            Failed to build gprofng in binutils with lld
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          5c4lar
      </td>
    </tr>
</table>

<pre>
    ld.lld cannot build gprofng in binutils successfully
```
/bin/bash ./libtool --tag=CC   --mode=link /usr/bin/clang -Wall -Wno-nonnull-compare -g -O2 -module -avoid-version -Wl,--version-script,../../../gprofng/libcollector/libgprofng.ver -Wl,--no-as-needed -Wl,-lrt -Wl,-ldl  -o libgp-collector.la -rpath /usr/local/lib/gprofng libgp_collector_la-gethrtime.lo libgp_collector_la-dispatcher.lo libgp_collector_la-iolib.lo libgp_collector_la-mmaptrace.lo libgp_collector_la-memmgr.lo libgp_collector_la-tsd.lo libgp_collector_la-profile.lo libgp_collector_la-envmgmt.lo libgp_collector_la-linetrace.lo libgp_collector_la-libcol_hwcdrv.lo libgp_collector_la-libcol_hwcfuncs.lo libgp_collector_la-libcol-i386-dis.lo libgp_collector_la-hwprofile.lo libgp_collector_la-jprofile.lo libgp_collector_la-unwind.lo libgp_collector_la-libcol_util.lo libgp_collector_la-collector.lo 
libtool: link: /usr/bin/clang -shared  -fPIC -DPIC .libs/libgp_collector_la-gethrtime.o .libs/libgp_collector_la-dispatcher.o .libs/libgp_collector_la-iolib.o .libs/libgp_collector_la-mmaptrace.o .libs/libgp_collector_la-memmgr.o .libs/libgp_collector_la-tsd.o .libs/libgp_collector_la-profile.o .libs/libgp_collector_la-envmgmt.o .libs/libgp_collector_la-linetrace.o .libs/libgp_collector_la-libcol_hwcdrv.o .libs/libgp_collector_la-libcol_hwcfuncs.o .libs/libgp_collector_la-libcol-i386-dis.o .libs/libgp_collector_la-hwprofile.o .libs/libgp_collector_la-jprofile.o .libs/libgp_collector_la-unwind.o .libs/libgp_collector_la-libcol_util.o .libs/libgp_collector_la-collector.o    -Wl,--version-script -Wl,../../../gprofng/libcollector/libgprofng.ver -Wl,--no-as-needed -Wl,-lrt -Wl,-ldl   -Wl,-soname -Wl,libgp-collector.so -o .libs/libgp-collector.so
ld: error: version script assignment of 'GLIBC_2.0' to symbol 'fclose' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.0' to symbol 'fdopen' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.0' to symbol 'fgetpos' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.0' to symbol 'fopen' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.0' to symbol 'fsetpos' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.0' to symbol 'pthread_cond_timedwait' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.0' to symbol 'pthread_cond_wait' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.0' to symbol 'pthread_join' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.0' to symbol 'sem_wait' failed: symbol not defined
ld: warning: attempt to reassign symbol 'dlopen' of version 'GLIBC_2.0' to version 'GLIBC_2.1'
ld: error: version script assignment of 'GLIBC_2.1' to symbol 'fclose' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.1' to symbol 'fdopen' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.1' to symbol 'fgetpos64' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.1' to symbol 'fopen' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.1' to symbol 'fsetpos64' failed: symbol not defined
ld: warning: attempt to reassign symbol 'popen' of version 'GLIBC_2.0' to version 'GLIBC_2.1'
ld: warning: attempt to reassign symbol 'pthread_create' of version 'GLIBC_2.0' to version 'GLIBC_2.1'
ld: error: version script assignment of 'GLIBC_2.1' to symbol 'sem_wait' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.2' to symbol 'fgetpos' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.2' to symbol 'fgetpos64' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.2' to symbol 'fsetpos' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.2' to symbol 'fsetpos64' failed: symbol not defined
ld: error: version script assignment of 'GLIBC_2.2' to symbol 'open64' failed: symbol not defined
ld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [Makefile:567: libgp-collector.la] Error 1
```
Steps to Reproduce:
- Download binutils-2.42
- Configure and build
```
mkdir build
 ../configure CC=/usr/bin/clang CXX=/usr/bin/clang++ --with-ld=/usr/bin/ld.lld
cd build
make
```
Both the latest 18.1.2 and previous version 14.0.0 shipped with ubuntu have this problem.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWF2Po7gS_TXOS8kITD4f8tBJbl-NdK92tfsw89YyuALuNjayTbL971cGknSPAtMzO5OsFBGgjutU4VNl2dw5WWjENZltyGw34Y0vjV3P8qnidpIZ8bpWIlJKQM61Nh6yRioBRW3NXhcgNWRSN14qB67Jc3Ru3yj1SuIdiR_IPO5_3SN7zKQOV-5KiAh7VDLzxiig1POCpLvtFgAorYxAku6U1C9A2GPj7HlorrgugH7mSgH9rA3VRutGKZqbquYWgRZAf2MQfDQKgfKDkYIe0DppNNDPirAtPT1Tl1tZe8K2UQjncunz60LMjVKYe2O7x94WHdCe_WlDuaMaUaA4vVTWn2-FAqAG2tH07C9SHKituS8vaSqTc9URXeLoBj6dBz4pTgv0pfWywkiZa3YhXc19XqIdAEijZDZgqypee8vzIecVVlUx5Ng7MWAJ2Ug15BT1oSoqP2BVUuNYSN1EPZXHXNjDNzH7RuduFEVlupyHrziAKo_j2TyPmxt9lHroO_VxhroaQLzRkIGuvPpiIukDhMoJ_9eLx5XcogCg-98_bYHuwjVSMnMnfQ8JzYzB3uhtFNfJbh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