[PATCH] D41937: [WebAssembly] supports -stdlib=libc++ switch
This revision was automatically updated to reflect the committed changes. Closed by commit rC322382: [WebAssembly] Support -stdlib=libc++ switch (authored by sbc, committed by ). Changed prior to commit: https://reviews.llvm.org/D41937?vs=129572&id=129649#toc Repository: rC Clang https://reviews.llvm.org/D41937 Files: lib/Driver/ToolChains/WebAssembly.cpp lib/Driver/ToolChains/WebAssembly.h test/Driver/wasm-toolchain.cpp Index: lib/Driver/ToolChains/WebAssembly.cpp === --- lib/Driver/ToolChains/WebAssembly.cpp +++ lib/Driver/ToolChains/WebAssembly.cpp @@ -11,6 +11,7 @@ #include "CommonArgs.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" +#include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "llvm/Option/ArgList.h" @@ -117,6 +118,12 @@ } ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList &Args) const { + if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { +StringRef Value = A->getValue(); +if (Value != "libc++") + getDriver().Diag(diag::err_drv_invalid_stdlib_name) + << A->getAsString(Args); + } return ToolChain::CST_Libcxx; } @@ -134,6 +141,19 @@ getDriver().SysRoot + "/include/c++/v1"); } +void WebAssembly::AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const { + + switch (GetCXXStdlibType(Args)) { + case ToolChain::CST_Libcxx: +CmdArgs.push_back("-lc++"); +CmdArgs.push_back("-lc++abi"); +break; + case ToolChain::CST_Libstdcxx: +llvm_unreachable("invalid stdlib name"); + } +} + std::string WebAssembly::getThreadModel() const { // The WebAssembly MVP does not yet support threads; for now, use the // "single" threading model, which lowers atomics to non-atomic operations. Index: lib/Driver/ToolChains/WebAssembly.h === --- lib/Driver/ToolChains/WebAssembly.h +++ lib/Driver/ToolChains/WebAssembly.h @@ -62,6 +62,8 @@ void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; + void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const override; std::string getThreadModel() const override; const char *getDefaultLinker() const override { Index: test/Driver/wasm-toolchain.cpp === --- test/Driver/wasm-toolchain.cpp +++ test/Driver/wasm-toolchain.cpp @@ -0,0 +1,36 @@ +// A basic clang -cc1 command-line. WebAssembly is somewhat special in +// enabling -ffunction-sections, -fdata-sections, and -fvisibility=hidden by +// default. + +// RUN: %clang++ %s -### -no-canonical-prefixes -target wasm32-unknown-unknown 2>&1 | FileCheck -check-prefix=CC1 %s +// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} "-fvisibility" "hidden" {{.*}} "-ffunction-sections" "-fdata-sections" + +// Ditto, but ensure that a user -fno-function-sections disables the +// default -ffunction-sections. + +// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fno-function-sections 2>&1 | FileCheck -check-prefix=NO_FUNCTION_SECTIONS %s +// NO_FUNCTION_SECTIONS-NOT: function-sections + +// Ditto, but ensure that a user -fno-data-sections disables the +// default -fdata-sections. + +// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fno-data-sections 2>&1 | FileCheck -check-prefix=NO_DATA_SECTIONS %s +// NO_DATA_SECTIONS-NOT: data-sections + +// Ditto, but ensure that a user -fvisibility=default disables the default +// -fvisibility=hidden. + +// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fvisibility=default 2>&1 | FileCheck -check-prefix=FVISIBILITY_DEFAULT %s +// FVISIBILITY_DEFAULT-NOT: hidden + +// A basic C++ link command-line. + +// RUN: %clang++ -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=LINK %s +// LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" +// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" + +// A basic C++ link command-line with optimization. + +// RUN: %clang++ -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s --stdlib=c++ 2>&1 | FileCheck -check-prefix=LINK_OPT %s +// LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" +// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" Index: lib/Driver/ToolChains/WebAssembly.cpp === --- lib/Driver/ToolChains/WebAssembly.cpp +++ lib/Driver/ToolChains/WebAssemb
[PATCH] D41937: [WebAssembly] supports -stdlib=libc++ switch
patcheng added a comment. Thanks @sbc100. BTW I don't have commit access. When it's ready to be committed, I would need help with that. Thanks https://reviews.llvm.org/D41937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41937: [WebAssembly] supports -stdlib=libc++ switch
sbc100 added a comment. lgtm https://reviews.llvm.org/D41937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41937: [WebAssembly] supports -stdlib=libc++ switch
patcheng updated this revision to Diff 129572. patcheng edited the summary of this revision. patcheng added a comment. Added -lc++abi per @sbc100 's suggestion https://reviews.llvm.org/D41937 Files: lib/Driver/ToolChains/WebAssembly.cpp lib/Driver/ToolChains/WebAssembly.h test/Driver/wasm-toolchain.cpp Index: test/Driver/wasm-toolchain.cpp === --- /dev/null +++ test/Driver/wasm-toolchain.cpp @@ -0,0 +1,37 @@ +// A basic clang -cc1 command-line. WebAssembly is somewhat special in +// enabling -ffunction-sections, -fdata-sections, and -fvisibility=hidden by +// default. + +// RUN: %clang++ %s -### -no-canonical-prefixes -target wasm32-unknown-unknown 2>&1 | FileCheck -check-prefix=CC1 %s +// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} "-fvisibility" "hidden" {{.*}} "-ffunction-sections" "-fdata-sections" + +// Ditto, but ensure that a user -fno-function-sections disables the +// default -ffunction-sections. + +// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fno-function-sections 2>&1 | FileCheck -check-prefix=NO_FUNCTION_SECTIONS %s +// NO_FUNCTION_SECTIONS-NOT: function-sections + +// Ditto, but ensure that a user -fno-data-sections disables the +// default -fdata-sections. + +// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fno-data-sections 2>&1 | FileCheck -check-prefix=NO_DATA_SECTIONS %s +// NO_DATA_SECTIONS-NOT: data-sections + +// Ditto, but ensure that a user -fvisibility=default disables the default +// -fvisibility=hidden. + +// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fvisibility=default 2>&1 | FileCheck -check-prefix=FVISIBILITY_DEFAULT %s +// FVISIBILITY_DEFAULT-NOT: hidden + +// A basic C++ link command-line. + +// RUN: %clang++ -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=LINK %s +// LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" +// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc++" "-lc++abi" "-allow-undefined-file" "wasm.syms" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" + +// A basic C++ link command-line with optimization. + +// RUN: %clang++ -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s --stdlib=c++ 2>&1 | FileCheck -check-prefix=LINK_OPT %s +// LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" +// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc++" "-lc++abi" "-allow-undefined-file" "wasm.syms" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" + Index: lib/Driver/ToolChains/WebAssembly.h === --- lib/Driver/ToolChains/WebAssembly.h +++ lib/Driver/ToolChains/WebAssembly.h @@ -62,6 +62,8 @@ void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; + void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const override; std::string getThreadModel() const override; const char *getDefaultLinker() const override { Index: lib/Driver/ToolChains/WebAssembly.cpp === --- lib/Driver/ToolChains/WebAssembly.cpp +++ lib/Driver/ToolChains/WebAssembly.cpp @@ -11,6 +11,7 @@ #include "CommonArgs.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" +#include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "llvm/Option/ArgList.h" @@ -119,6 +120,12 @@ } ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList &Args) const { + if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { +StringRef Value = A->getValue(); +if (Value != "libc++") + getDriver().Diag(diag::err_drv_invalid_stdlib_name) +<< A->getAsString(Args); + } return ToolChain::CST_Libcxx; } @@ -136,6 +143,19 @@ getDriver().SysRoot + "/include/c++/v1"); } +void WebAssembly::AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const { + + switch (GetCXXStdlibType(Args)) { + case ToolChain::CST_Libcxx: +CmdArgs.push_back("-lc++"); +CmdArgs.push_back("-lc++abi"); +break; + case ToolChain::CST_Libstdcxx: +llvm_unreachable("invalid stdlib name"); + } +} + std::string WebAssembly::getThreadModel() const { // The WebAssembly MVP does not yet support threads; for now, use the // "single" threading model, which lowers atomics to non-atomic operations. Index: test/Driver/wasm-toolchain.cpp === --- /dev/null +++ test/Driver/wasm-toolchain.cpp @@ -0,0 +1,37 @@ +// A basic clang -cc1 command-line. WebAssembly is somewhat special in +// enabling -ffunction-section
[PATCH] D41937: [WebAssembly] supports -stdlib=libc++ switch
patcheng added inline comments. Comment at: lib/Driver/ToolChains/WebAssembly.cpp:151 + case ToolChain::CST_Libcxx: +CmdArgs.push_back("-lc++"); +break; sbc100 wrote: > Can you add -lc++abi too? Then I can drop D41966 Sure, but I am not in front of a computer with the code at the moment. I should be able to get this done later this evening (PST). Repository: rC Clang https://reviews.llvm.org/D41937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41937: [WebAssembly] supports -stdlib=libc++ switch
sbc100 added inline comments. Comment at: lib/Driver/ToolChains/WebAssembly.cpp:151 + case ToolChain::CST_Libcxx: +CmdArgs.push_back("-lc++"); +break; Can you add -lc++abi too? Then I can drop D41966 Repository: rC Clang https://reviews.llvm.org/D41937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41937: [WebAssembly] supports -stdlib=libc++ switch
dschuff accepted this revision. dschuff added a comment. LGTM, but does it need to be rebased after the `-allow-undefined-file` change? Repository: rC Clang https://reviews.llvm.org/D41937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41937: [WebAssembly] supports -stdlib=libc++ switch
sbc100 accepted this revision. sbc100 added a comment. This revision is now accepted and ready to land. Nice. I happened to just upload a similar (but orthogonal) patch: https://reviews.llvm.org/D41966 Repository: rC Clang https://reviews.llvm.org/D41937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41937: [WebAssembly] supports -stdlib=libc++ switch
patcheng created this revision. Herald added subscribers: cfe-commits, sunfish, aheejin, jgravelle-google, sbc100, dschuff, jfb. Herald added a reviewer: EricWF. Referenced implementation from Fuchsia and Darwin Toolchain. Still only support CST_Libcxx. Now checks that the argument is really '-stdlib=libc++', and display error. Also, now will pass -lc++ to the linker. Repository: rC Clang https://reviews.llvm.org/D41937 Files: lib/Driver/ToolChains/WebAssembly.cpp lib/Driver/ToolChains/WebAssembly.h test/Driver/wasm-toolchain.cpp Index: test/Driver/wasm-toolchain.cpp === --- /dev/null +++ test/Driver/wasm-toolchain.cpp @@ -0,0 +1,37 @@ +// A basic clang -cc1 command-line. WebAssembly is somewhat special in +// enabling -ffunction-sections, -fdata-sections, and -fvisibility=hidden by +// default. + +// RUN: %clang++ %s -### -no-canonical-prefixes -target wasm32-unknown-unknown 2>&1 | FileCheck -check-prefix=CC1 %s +// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} "-fvisibility" "hidden" {{.*}} "-ffunction-sections" "-fdata-sections" + +// Ditto, but ensure that a user -fno-function-sections disables the +// default -ffunction-sections. + +// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fno-function-sections 2>&1 | FileCheck -check-prefix=NO_FUNCTION_SECTIONS %s +// NO_FUNCTION_SECTIONS-NOT: function-sections + +// Ditto, but ensure that a user -fno-data-sections disables the +// default -fdata-sections. + +// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fno-data-sections 2>&1 | FileCheck -check-prefix=NO_DATA_SECTIONS %s +// NO_DATA_SECTIONS-NOT: data-sections + +// Ditto, but ensure that a user -fvisibility=default disables the default +// -fvisibility=hidden. + +// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fvisibility=default 2>&1 | FileCheck -check-prefix=FVISIBILITY_DEFAULT %s +// FVISIBILITY_DEFAULT-NOT: hidden + +// A basic C++ link command-line. + +// RUN: %clang++ -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=LINK %s +// LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" +// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc++" "-allow-undefined-file" "wasm.syms" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" + +// A basic C++ link command-line with optimization. + +// RUN: %clang++ -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s --stdlib=c++ 2>&1 | FileCheck -check-prefix=LINK_OPT %s +// LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" +// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc++" "-allow-undefined-file" "wasm.syms" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" + Index: lib/Driver/ToolChains/WebAssembly.h === --- lib/Driver/ToolChains/WebAssembly.h +++ lib/Driver/ToolChains/WebAssembly.h @@ -62,6 +62,8 @@ void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; + void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const override; std::string getThreadModel() const override; const char *getDefaultLinker() const override { Index: lib/Driver/ToolChains/WebAssembly.cpp === --- lib/Driver/ToolChains/WebAssembly.cpp +++ lib/Driver/ToolChains/WebAssembly.cpp @@ -11,6 +11,7 @@ #include "CommonArgs.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" +#include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "llvm/Option/ArgList.h" @@ -119,6 +120,12 @@ } ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList &Args) const { + if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { +StringRef Value = A->getValue(); +if (Value != "libc++") + getDriver().Diag(diag::err_drv_invalid_stdlib_name) +<< A->getAsString(Args); + } return ToolChain::CST_Libcxx; } @@ -136,6 +143,18 @@ getDriver().SysRoot + "/include/c++/v1"); } +void WebAssembly::AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const { + + switch (GetCXXStdlibType(Args)) { + case ToolChain::CST_Libcxx: +CmdArgs.push_back("-lc++"); +break; + case ToolChain::CST_Libstdcxx: +llvm_unreachable("invalid stdlib name"); + } +} + std::string WebAssembly::getThreadModel() const { // The WebAssembly MVP does not yet support threads; for now, use the // "single" threading model, which lowers atomics to non-atomic operations. Index: test/Driver/wasm-toolchain.cpp