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

    <tr>
        <th>Summary</th>
        <td>
            clang always wants to link `-lunwind`, `-unwindlib` doesnt seem to have an effect
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Consider this invocation with an existing gcc toolchain providing the libraries, test.cpp is a simple `int main() {return 0;}` function.

``` bash
/usr/bin/clang++ --gcc-install-dir=/opt/mycompiler/lib/gcc/arm-none-eabi/5.3.0/ --target=arm-none-eabi --sysroot=/opt/mycompiler/arm-none-eabi -mcpu=arm926ej-s -mfloat-abi=soft -stdlib=libstdc++ -L/opt/mycompiler/lib/gcc/arm-none-eabi/5.3.0 -rtlib=libgcc -unwindlib=none test.cpp -v
```

the clang driver seems to always add an dependency to libunwind, even if `-unwindlib`is set to `libgcc` or `none`:

```
Debian clang version 18.1.8 (1)
Target: arm-none-unknown-eabi
Thread model: posix
InstalledDir: /usr/bin
clang++: warning: argument unused during compilation: '--gcc-install-dir=/opt/mycompiler/lib/gcc/arm-none-eabi/5.3.0/' [-Wunused-command-line-argument]
clang++: warning: argument unused during compilation: '-unwindlib=none' [-Wunused-command-line-argument]
 "/usr/lib/llvm-18/bin/clang" -cc1 -triple armv5e-none-unknown-eabi -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -nostdsysteminc -target-cpu arm926ej-s -target-feature +soft-float -target-feature +soft-float-abi -target-feature -crc -target-feature +dsp -target-feature -ras -target-feature -sb -target-feature -i8mm -target-feature -lob -target-feature -cdecp0 -target-feature -cdecp1 -target-feature -cdecp2 -target-feature -cdecp3 -target-feature -cdecp4 -target-feature -cdecp5 -target-feature -cdecp6 -target-feature -cdecp7 -target-feature -pacbti -target-feature -hwdiv-arm -target-feature -hwdiv -target-feature -vfp2 -target-feature -vfp2sp -target-feature -vfp3 -target-feature -vfp3d16 -target-feature -vfp3d16sp -target-feature -vfp3sp -target-feature -fp16 -target-feature -vfp4 -target-feature -vfp4d16 -target-feature -vfp4d16sp -target-feature -vfp4sp -target-feature -fp-armv8 -target-feature -fp-armv8d16 -target-feature -fp-armv8d16sp -target-feature -fp-armv8sp -target-feature -fullfp16 -target-feature -fp64 -target-feature -d32 -target-feature -neon -target-feature -dotprod -target-feature -fp16fml -target-feature -bf16 -target-feature -mve -target-feature -mve.fp -target-feature -fpregs -target-feature -crypto -target-feature -sha2 -target-feature -aes -target-feature +strict-align -target-abi aapcs -msoft-float -mfloat-abi soft -Wunaligned-access -debugger-tuning=gdb -fdebug-compilation-dir=/tmp/lano/tmp_dir -v -fcoverage-compilation-dir=/tmp/lano/tmp_dir -resource-dir /usr/lib/llvm-18/lib/clang/18 -isysroot /opt/mycompiler/arm-none-eabi -internal-isystem /opt/mycompiler/arm-none-eabi/include/c++/5.3.0 -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /opt/mycompiler/arm-none-eabi/include -fdeprecated-macro -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-623597.o -x c++ test.cpp
clang -cc1 version 18.1.8 based upon LLVM 18.1.8 default target x86_64-pc-linux-gnu
ignoring duplicate directory "/usr/lib/llvm-18/lib/clang/18/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/mycompiler/arm-none-eabi/include/c++/5.3.0
 /usr/lib/llvm-18/lib/clang/18/include
 /opt/mycompiler/arm-none-eabi/include
End of search list.
 "/usr/bin/ld.lld" /tmp/test-623597.o -Bstatic -EL -L/opt/mycompiler/lib/gcc/arm-none-eabi/5.3.0 -L/opt/mycompiler/arm-none-eabi/lib -L/opt/mycompiler/arm-none-eabi/lib -L/usr/lib/llvm-18/lib/clang/18/lib/baremetal -lstdc++ -lsupc++ -lunwind -lc -lm -lgcc --target2=rel -o a.out
ld.lld: error: unable to find library -lunwind
clang++: error: ld.lld command failed with exit code 1 (use -v to see invocation)
```

FWIW, this are the linked files with the gcc toolchain, the crt startup is missing too:
`crtbegin.o crt0.o COMPILED_OBJECTS -lstdc++ -lm --start-group -lgcc -lc --end-group crtend.o crtn.o`

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysGF1v4zju17gvBA1_JGn6kIe2ae7mMIs93C52HgtZoh1NZcmQ5LT99wfaTpNpncHMzgJFEVMUv0mRFCHoxhJtkuVdstxeiT7und9YZ4Rt6Kpy6nVz72zQijzEvQ6g7cFJEbWz8KzjHoQFetEhattAIyVE54zcC22h8-6gFcPjnsDoyguvKSTFPUQKMZVdBzqAgKDbzhAkq0zbCK3QNinWSXEDyfWdp9h7C1lS3iXX22SVQd1byezTJNsm2e30f5WNf1CJsJ9gxa4PPil2FRPcSVYpKe6S4g4QGylR2xCFMai0T8ptUuxcF5Ni175K13baEN81ukqKXSNlUuyEb9E6S0ii0kmxW6ZlmiXFDhCj8A3FpNx-gwOI4TV45-JF-u_wW9n1I5WbYkVfMQC2tXEiIrMst8HVETBExXKVW6OrEJU8avX5b-oA6OMbQXYi9vZZ24kJo588hod3Fj93Azt6sDMorw_kIRC1AaIDYZ7FawChFEeMoo6sIitf-czoauTHoUEHsqBrjoYzKVaZDhAoMnqyykYx2d3O8zeLyKKUt7NBMX5uqdLCTvIdyAeO4Xyd5ukakmKdJ8XNiPjn5MxbeLNWb5-se7aj1UakvSehoHWKDKN2LuiX8ejTGFekthxYt_BNIA4YZ7HICM_CW22bkWPTt2Qj9LYPpED1njNo9OaQdiPF6382hJPiGpLlHX4Z2aJ0bSus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