[PATCH] D128841: [Driver] Always use --as-needed with libunwind

Petr Hosek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 29 11:14:58 PDT 2022


phosek created this revision.
phosek added reviewers: mcgrathr, saugustine.
Herald added a project: All.
phosek requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

With libgcc, we follow the behavior of GCC for backwards compatibility,
only using --as-needed in the non-C++ mode.

      

With libunwind, there are no backward compatibility requirements so we
can use it always.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128841

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/compiler-rt-unwind.c


Index: clang/test/Driver/compiler-rt-unwind.c
===================================================================
--- clang/test/Driver/compiler-rt-unwind.c
+++ clang/test/Driver/compiler-rt-unwind.c
@@ -5,15 +5,32 @@
 // RUN:     --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=platform \
 // RUN:     --gcc-toolchain="" -resource-dir=%S/Inputs/resource_dir \
 // RUN:   | FileCheck --check-prefix=RTLIB-GCC %s
-// RTLIB-GCC: "{{.*}}lgcc"
-// RTLIB-GCC: "{{.*}}lgcc_s"
+// RTLIB-GCC: "-lgcc"
+// RTLIB-GCC-SAME: "--as-needed"
+// RTLIB-GCC-SAME: "-lgcc_s"
+// RTLIB-GCC-SAME: "--no-as-needed"
+//
+// RUN: %clangxx -### %s 2>&1 \
+// RUN:     --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=platform \
+// RUN:     --gcc-toolchain="" -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck --check-prefix=RTLIB-GXX %s
+// RTLIB-GXX: "-lgcc"
+// RTLIB-GXX-NOT: "--as-needed"
+// RTLIB-GXX-SAME: "-lgcc_s"
+// RTLIB-GXX-NOT: "--no-as-needed"
 //
 // RUN: %clang -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \
 // RUN:     --gcc-toolchain="" -resource-dir=%S/Inputs/resource_dir \
 // RUN:   | FileCheck --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER-RT %s
-// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lgcc"
-// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lunwind"
+// RUN: %clangxx -### %s 2>&1 \
+// RUN:     --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \
+// RUN:     --gcc-toolchain="" -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER-RT %s
+// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "-lgcc"
+// RTLIB-GCC-UNWINDLIB-COMPILER-RT-SAME: "--as-needed"
+// RTLIB-GCC-UNWINDLIB-COMPILER-RT-SAME: "-lunwind"
+// RTLIB-GCC-UNWINDLIB-COMPILER-RT-SAME: "--no-as-needed"
 //
 // RUN: %clang -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \
@@ -37,6 +54,19 @@
 // RUN:   | FileCheck --check-prefix=RTLIB-COMPILER-RT %s
 // RTLIB-COMPILER-RT: "{{.*}}libclang_rt.builtins-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN:     --target=x86_64-unknown-linux -rtlib=compiler-rt --unwindlib=libunwind \
+// RUN:     --gcc-toolchain="" -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck --check-prefix=RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT %s
+// RUN: %clangxx -### %s 2>&1 \
+// RUN:     --target=x86_64-unknown-linux -rtlib=compiler-rt --unwindlib=libunwind \
+// RUN:     --gcc-toolchain="" -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck --check-prefix=RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT %s
+// RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT: "{{.*}}libclang_rt.builtins-x86_64.a"
+// RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT-SAME: "--as-needed"
+// RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT-SAME: "-lunwind"
+// RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT-SAME: "--no-as-needed"
+//
 // RUN: %clang -### %s 2>&1   \
 // RUN:     --target=x86_64-unknown-linux -rtlib=compiler-rt --unwindlib=libgcc \
 // RUN:     --gcc-toolchain="" -resource-dir=%S/Inputs/resource_dir \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1510,7 +1510,8 @@
     return;
 
   LibGccType LGT = getLibGccType(TC, D, Args);
-  bool AsNeeded = LGT == LibGccType::UnspecifiedLibGcc && !D.CCCIsCXX() &&
+  bool AsNeeded = LGT == LibGccType::UnspecifiedLibGcc &&
+                  (UNW == ToolChain::UNW_CompilerRT || !D.CCCIsCXX()) &&
                   !TC.getTriple().isAndroid() &&
                   !TC.getTriple().isOSCygMing() && !TC.getTriple().isOSAIX();
   if (AsNeeded)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128841.441093.patch
Type: text/x-patch
Size: 3714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220629/b16c2b38/attachment-0001.bin>


More information about the cfe-commits mailing list