nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 227 lines 9.6 kB view raw
1commit a5cacb5ba7f1f18e7bb6f6709e42683eeb7e6470 2Author: Sterling Augustine <saugustine@google.com> 3Date: Tue Mar 19 20:01:59 2019 +0000 4 5 Add --unwindlib=[libgcc|compiler-rt] to parallel --rtlib= [take 2] 6 7 "clang++ hello.cc --rtlib=compiler-rt" 8 9 now can works without specifying additional unwind or exception 10 handling libraries. 11 12 This reworked version of the feature no longer modifies today's default 13 unwind library for compiler-rt: which is nothing. Rather, a user 14 can specify -DCLANG_DEFAULT_UNWINDLIB=libunwind when configuring 15 the compiler. 16 17 This should address the issues from the previous version. 18 19 Update tests for new --unwindlib semantics. 20 21 Differential Revision: https://reviews.llvm.org/D59109 22 23 llvm-svn: 356508 24 25diff --git clang/CMakeLists.txt clang/CMakeLists.txt 26index 52b881939499..2c3fb62f6e73 100644 27--- clang/CMakeLists.txt 28+++ clang/CMakeLists.txt 29@@ -244,6 +244,24 @@ if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR 30 "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)" FORCE) 31 endif() 32 33+set(CLANG_DEFAULT_UNWINDLIB "" CACHE STRING 34+ "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty to match runtime library.)") 35+if (CLANG_DEFAULT_UNWINDLIB STREQUAL "") 36+ if (CLANG_DEFAULT_RTLIB STREQUAL "libgcc") 37+ set (CLANG_DEFAULT_UNWINDLIB "libgcc" CACHE STRING "" FORCE) 38+ elseif (CLANG_DEFAULT_RTLIBS STREQUAL "libunwind") 39+ set (CLANG_DEFAULT_UNWINDLIB "none" CACHE STRING "" FORCE) 40+ endif() 41+endif() 42+ 43+if (NOT(CLANG_DEFAULT_UNWINDLIB STREQUAL "none" OR 44+ CLANG_DEFAULT_UNWINDLIB STREQUAL "libgcc" OR 45+ CLANG_DEFAULT_UNWINDLIB STREQUAL "libunwind")) 46+ message(WARNING "Resetting default unwindlib to use platform default") 47+ set(CLANG_DEFAULT_UNWINDLIB "" CACHE STRING 48+ "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty for none)" FORCE) 49+endif() 50+ 51 set(CLANG_DEFAULT_OBJCOPY "objcopy" CACHE STRING 52 "Default objcopy executable to use.") 53 54diff --git clang/include/clang/Basic/DiagnosticDriverKinds.td clang/include/clang/Basic/DiagnosticDriverKinds.td 55index 7f75f45c6578..7e1bb33b5cef 100644 56--- clang/include/clang/Basic/DiagnosticDriverKinds.td 57+++ clang/include/clang/Basic/DiagnosticDriverKinds.td 58@@ -52,6 +52,10 @@ def err_drv_invalid_rtlib_name : Error< 59 "invalid runtime library name in argument '%0'">; 60 def err_drv_unsupported_rtlib_for_platform : Error< 61 "unsupported runtime library '%0' for platform '%1'">; 62+def err_drv_invalid_unwindlib_name : Error< 63+ "invalid unwind library name in argument '%0'">; 64+def err_drv_incompatible_unwindlib : Error< 65+ "--rtlib=libgcc requires --unwindlib=libgcc">; 66 def err_drv_invalid_stdlib_name : Error< 67 "invalid library name in argument '%0'">; 68 def err_drv_invalid_output_with_multiple_archs : Error< 69diff --git clang/include/clang/Config/config.h.cmake clang/include/clang/Config/config.h.cmake 70index 1d624450b9d9..2d4cb747e87e 100644 71--- clang/include/clang/Config/config.h.cmake 72+++ clang/include/clang/Config/config.h.cmake 73@@ -23,6 +23,9 @@ 74 /* Default runtime library to use. */ 75 #define CLANG_DEFAULT_RTLIB "${CLANG_DEFAULT_RTLIB}" 76 77+/* Default unwind library to use. */ 78+#define CLANG_DEFAULT_UNWINDLIB "${CLANG_DEFAULT_UNWINDLIB}" 79+ 80 /* Default objcopy to use */ 81 #define CLANG_DEFAULT_OBJCOPY "${CLANG_DEFAULT_OBJCOPY}" 82 83diff --git clang/include/clang/Driver/Options.td clang/include/clang/Driver/Options.td 84index 601aa8744967..0e74a2d36dea 100644 85--- clang/include/clang/Driver/Options.td 86+++ clang/include/clang/Driver/Options.td 87@@ -2428,6 +2428,8 @@ def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>, 88 }]>; 89 def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>, 90 HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">; 91+def unwindlib_EQ : Joined<["-", "--"], "unwindlib=">, Flags<[CC1Option]>, 92+ HelpText<"Unwind library to use">, Values<"libgcc,unwindlib,platform">; 93 def sub__library : JoinedOrSeparate<["-"], "sub_library">; 94 def sub__umbrella : JoinedOrSeparate<["-"], "sub_umbrella">; 95 def system_header_prefix : Joined<["--"], "system-header-prefix=">, 96diff --git clang/include/clang/Driver/ToolChain.h clang/include/clang/Driver/ToolChain.h 97index 2f9c2c190e32..d5b131bcf112 100644 98--- clang/include/clang/Driver/ToolChain.h 99+++ clang/include/clang/Driver/ToolChain.h 100@@ -99,6 +99,12 @@ public: 101 RLT_Libgcc 102 }; 103 104+ enum UnwindLibType { 105+ UNW_None, 106+ UNW_CompilerRT, 107+ UNW_Libgcc 108+ }; 109+ 110 enum RTTIMode { 111 RM_Enabled, 112 RM_Disabled, 113@@ -352,6 +358,10 @@ public: 114 return ToolChain::CST_Libstdcxx; 115 } 116 117+ virtual UnwindLibType GetDefaultUnwindLibType() const { 118+ return ToolChain::UNW_None; 119+ } 120+ 121 virtual std::string getCompilerRTPath() const; 122 123 virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, 124@@ -484,6 +494,10 @@ public: 125 // given compilation arguments. 126 virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const; 127 128+ // GetUnwindLibType - Determine the unwind library type to use with the 129+ // given compilation arguments. 130+ virtual UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const; 131+ 132 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set 133 /// the include paths to use for the given C++ standard library type. 134 virtual void 135diff --git clang/lib/Driver/ToolChain.cpp clang/lib/Driver/ToolChain.cpp 136index cf3db34688df..d980dd5d23fb 100644 137--- clang/lib/Driver/ToolChain.cpp 138+++ clang/lib/Driver/ToolChain.cpp 139@@ -665,6 +665,33 @@ ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType( 140 return GetDefaultRuntimeLibType(); 141 } 142 143+ToolChain::UnwindLibType ToolChain::GetUnwindLibType( 144+ const ArgList &Args) const { 145+ const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ); 146+ StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB; 147+ 148+ if (LibName == "none") 149+ return ToolChain::UNW_None; 150+ else if (LibName == "platform" || LibName == "") { 151+ ToolChain::RuntimeLibType RtLibType = GetRuntimeLibType(Args); 152+ if (RtLibType == ToolChain::RLT_CompilerRT) 153+ return ToolChain::UNW_None; 154+ else if (RtLibType == ToolChain::RLT_Libgcc) 155+ return ToolChain::UNW_Libgcc; 156+ } else if (LibName == "libunwind") { 157+ if (GetRuntimeLibType(Args) == RLT_Libgcc) 158+ getDriver().Diag(diag::err_drv_incompatible_unwindlib); 159+ return ToolChain::UNW_CompilerRT; 160+ } else if (LibName == "libgcc") 161+ return ToolChain::UNW_Libgcc; 162+ 163+ if (A) 164+ getDriver().Diag(diag::err_drv_invalid_unwindlib_name) 165+ << A->getAsString(Args); 166+ 167+ return GetDefaultUnwindLibType(); 168+} 169+ 170 ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{ 171 const Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); 172 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_CXX_STDLIB; 173diff --git clang/test/Driver/compiler-rt-unwind.c clang/test/Driver/compiler-rt-unwind.c 174new file mode 100644 175index 000000000000..00024dfa7ed3 176--- /dev/null 177+++ clang/test/Driver/compiler-rt-unwind.c 178@@ -0,0 +1,49 @@ 179+// General tests that the driver handles combinations of --rtlib=XXX and 180+// --unwindlib=XXX properly. 181+// 182+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ 183+// RUN: --target=x86_64-unknown-linux \ 184+// RUN: --gcc-toolchain="" \ 185+// RUN: | FileCheck --check-prefix=RTLIB-EMPTY %s 186+// RTLIB-EMPTY: "{{.*}}lgcc" 187+// RTLIB-EMPTY: "{{.*}}-lgcc_s" 188+// 189+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ 190+// RUN: --target=x86_64-unknown-linux -rtlib=libgcc \ 191+// RUN: --gcc-toolchain="" \ 192+// RUN: | FileCheck --check-prefix=RTLIB-GCC %s 193+// RTLIB-GCC: "{{.*}}lgcc" 194+// RTLIB-GCC: "{{.*}}lgcc_s" 195+// 196+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ 197+// RUN: --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \ 198+// RUN: --gcc-toolchain="" \ 199+// RUN: | FileCheck --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER-RT %s 200+// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lgcc" 201+// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lunwind" 202+// 203+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ 204+// RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt \ 205+// RUN: --gcc-toolchain="" \ 206+// RUN: | FileCheck --check-prefix=RTLIB-COMPILER-RT %s 207+// RTLIB-COMPILER-RT: "{{.*}}libclang_rt.builtins-x86_64.a" 208+// 209+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ 210+// RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt --unwindlib=libgcc \ 211+// RUN: --gcc-toolchain="" \ 212+// RUN: | FileCheck --check-prefix=RTLIB-COMPILER-RT-UNWINDLIB-GCC %s 213+// RTLIB-COMPILER-RT-UNWINDLIB-GCC: "{{.*}}libclang_rt.builtins-x86_64.a" 214+// RTLIB-COMPILER-RT-UNWINDLIB-GCC: "{{.*}}lgcc_s" 215+// 216+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ 217+// RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt --unwindlib=libgcc \ 218+// RUN: -static --gcc-toolchain="" \ 219+// RUN: | FileCheck --check-prefix=RTLIB-COMPILER-RT-UNWINDLIB-GCC-STATIC %s 220+// RTLIB-COMPILER-RT-UNWINDLIB-GCC-STATIC: "{{.*}}libclang_rt.builtins-x86_64.a" 221+// RTLIB-COMPILER-RT-UNWINDLIB-GCC-STATIC: "{{.*}}lgcc_eh" 222+// 223+// RUN: not %clang -no-canonical-prefixes %s -o %t.o 2> %t.err \ 224+// RUN: --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \ 225+// RUN: --gcc-toolchain="" \ 226+// RUN: FileCheck --input-file=%t.err --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER_RT %s 227+// RTLIB-GCC-UNWINDLIB-COMPILER_RT: "{{[.|\\\n]*}}--rtlib=libgcc requires --unwindlib=libgcc"