[Driver] Correctly handle static C++ standard library
authorPetr Hosek <phosek@google.com>
Tue, 21 Sep 2021 06:25:21 +0000 (23:25 -0700)
committerPetr Hosek <phosek@google.com>
Thu, 23 Sep 2021 08:00:11 +0000 (01:00 -0700)
commit5e28c892d06f95600f8b6290ad4de38bfe142637
treea20c7e7492c25659f2887765324b42087ef388c6
parent6cef28ed2df19c197790ca777423fc1c2572c138
[Driver] Correctly handle static C++ standard library

When statically linking C++ standard library, we shouldn't add -Bdynamic
after including the library on the link line because that might override
user settings like -static and -static-pie. Rather, we should surround
the library with --push-state/--pop-state to make sure that -Bstatic
only applies to C++ standard library and nothing else. This has been
supported since GNU ld 2.25 (2014) so backwards compatibility should
no longer be a concern.

Differential Revision: https://reviews.llvm.org/D110128
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/fuchsia.cpp
clang/test/Driver/linux-ld.c