[PATCH] D70416: [Driver] Make -static-libgcc imply static libunwind

2019-11-20 Thread Josh Kunz via Phabricator via cfe-commits
jkz added a comment.

In D70416#1750978 , @joerg wrote:

> This is normally done by using `-Bstatic`/`-Bdynamic` around the library. See 
> `tools::addOpenMPRuntime`.


`-Bstatic`/`-Bdynamic` wrapping does seem to be more common, but that will 
change the linkage for libraries that are added after the run-time libraries 

 (e.g., `-lpthread`). We would need something like `--push-state -Bstatic 
-lunwind --pop-state` to preserve the "mode" of the link. (IMO, the existing 
usages of `-Bstatic`, `-Bdynamic` wrapping are wrong). The current approach is 
simpler.

Additionally, I think saugustine's reasoning makes sense here, and we should 
match the libgcc behavior of requiring a `.a` or `.so` depending on the "mode". 
I'd prefer to keep this patch the way it is.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70416/new/

https://reviews.llvm.org/D70416



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70416: [Driver] Make -static-libgcc imply static libunwind

2019-11-18 Thread Josh Kunz via Phabricator via cfe-commits
jkz created this revision.
jkz added reviewers: saugustine, sivachandra.
Herald added a project: clang.

In the GNU toolchain, `-static-libgcc` implies that the unwindlib will be 
linked statically. However, when `--unwindlib=libunwind`, this flag is ignored, 
and a bare `-lunwind` is added to the linker args.  Unfortunately, this means 
that if both `libunwind.so`, and `libunwind.a` are present in the library path, 
`libunwind.so` will be chosen in all cases where `-static` is not set.

This change makes `-static-libgcc` affect the `-l` flag produced by 
`--unwindlib=libunwind`. After this patch, providing `-static-libgcc 
--unwindlib=libunwind` will cause the driver to explicitly emit 
`-l:libunwind.a` to statically link libunwind. For all other cases it will emit 
`-l:libunwind.so` matching current behavior with a more explicit link line.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70416

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
@@ -13,7 +13,15 @@
 // RUN: --gcc-toolchain="" \
 // RUN:   | FileCheck --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER-RT %s
 // RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lgcc"
-// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lunwind"
+// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}l:libunwind.so"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \
+// RUN: -static-libgcc \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=RTLIB-GCC-STATIC-UNWINDLIB-COMPILER-RT %s
+// RTLIB-GCC-STATIC-UNWINDLIB-COMPILER-RT: "{{.*}}lgcc"
+// RTLIB-GCC-STATIC-UNWINDLIB-COMPILER-RT: "{{.*}}l:libunwind.a"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1   \
 // RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1209,7 +1209,10 @@
 break;
   }
   case ToolChain::UNW_CompilerRT:
-CmdArgs.push_back("-lunwind");
+if (LGT == LibGccType::StaticLibGcc)
+  CmdArgs.push_back("-l:libunwind.a");
+else
+  CmdArgs.push_back("-l:libunwind.so");
 break;
   }
 


Index: clang/test/Driver/compiler-rt-unwind.c
===
--- clang/test/Driver/compiler-rt-unwind.c
+++ clang/test/Driver/compiler-rt-unwind.c
@@ -13,7 +13,15 @@
 // RUN: --gcc-toolchain="" \
 // RUN:   | FileCheck --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER-RT %s
 // RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lgcc"
-// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lunwind"
+// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}l:libunwind.so"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \
+// RUN: -static-libgcc \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=RTLIB-GCC-STATIC-UNWINDLIB-COMPILER-RT %s
+// RTLIB-GCC-STATIC-UNWINDLIB-COMPILER-RT: "{{.*}}lgcc"
+// RTLIB-GCC-STATIC-UNWINDLIB-COMPILER-RT: "{{.*}}l:libunwind.a"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1   \
 // RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1209,7 +1209,10 @@
 break;
   }
   case ToolChain::UNW_CompilerRT:
-CmdArgs.push_back("-lunwind");
+if (LGT == LibGccType::StaticLibGcc)
+  CmdArgs.push_back("-l:libunwind.a");
+else
+  CmdArgs.push_back("-l:libunwind.so");
 break;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits