[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>
Fri, 24 Sep 2021 07:40:16 +0000 (00:40 -0700)
commit03142c5f67788bcc1573f76732d0fccd75c6b965
treebd342217b7c0155dde08864f9121fad1dcd6236c
parent9f773b17c2bc6916f12048a52ae271d1bf0edacf
[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