[Driver] Fix linking with -lm on Solaris (#65632)
authorRainer Orth <ro@gcc.gnu.org>
Thu, 7 Sep 2023 17:14:55 +0000 (19:14 +0200)
committerTobias Hieta <tobias@hieta.se>
Mon, 13 Nov 2023 07:27:47 +0000 (08:27 +0100)
commit05422e1dcf94d2f5178818450ff0fce816755a7e
treefe9844bc5e23444f6d3f585d2104cfc2f7af6e0f
parent910748f4ec5a73b6c4c1f5aa433fbe71b0b2b315
[Driver] Fix linking with -lm on Solaris (#65632)

As noticed in D158846, the Solaris driver deviates from other targets in
that it links every executable with `-lm`, but doesn't for shared
objects. For C code, this is unnecessary, while for C++ `libm` is always
needed, even for shared objects.

This patch fixes this by following the `Gnu.cpp` precedent. It adjusts
the `solaris-ld.c` test accordingly, adding some more tests.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.

(cherry picked from commit 1e6b0df3503567488e7df2d574c90f8f31a001a2)
clang/lib/Driver/ToolChains/Solaris.cpp
clang/test/Driver/solaris-ld.c