From e91a49e7c832bf0d2c69007321f616ee86b2b574 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 23 Nov 2019 13:38:41 -0800 Subject: [PATCH 1/4] wasi-sdk support for full LTO. Add support for building libcxx and libcxxabi in LTO mode, along aside the regular non-LTO builds. Pass CLANG_VERSION to the wasi-libc build so that it can build itself in LTO and non-LTO modes. And drop the explicit -O1 from the compiler-rt build, and just go with the default optimization settings. --- Makefile | 33 ++++++++++++++++++++++++++------- src/wasi-libc | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 45e22f784..c1e8c188b 100644 --- a/Makefile +++ b/Makefile @@ -54,11 +54,12 @@ build/llvm.BUILT: build/wasi-libc.BUILT: build/llvm.BUILT $(MAKE) -C $(ROOT_DIR)/src/wasi-libc \ WASM_CC=$(PREFIX)/bin/clang \ - SYSROOT=$(PREFIX)/share/wasi-sysroot + SYSROOT=$(PREFIX)/share/wasi-sysroot \ + CLANG_VERSION=$(CLANG_VERSION) touch build/wasi-libc.BUILT build/compiler-rt.BUILT: build/llvm.BUILT - # Do the build, and install it. + # Do the conventional build, and install it. mkdir -p build/compiler-rt cmake -B build/compiler-rt -G Ninja \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ @@ -70,7 +71,7 @@ build/compiler-rt.BUILT: build/llvm.BUILT -DCOMPILER_RT_ENABLE_IOS=OFF \ -DCOMPILER_RT_DEFAULT_TARGET_ONLY=On \ -DWASI_SDK_PREFIX=$(PREFIX) \ - -DCMAKE_C_FLAGS="-O1 $(DEBUG_PREFIX_MAP)" \ + -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \ -DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \ -DCOMPILER_RT_OS_DIR=wasi \ -DCMAKE_INSTALL_PREFIX=$(PREFIX)/lib/clang/$(CLANG_VERSION)/ \ @@ -81,7 +82,7 @@ build/compiler-rt.BUILT: build/llvm.BUILT cp -R $(ROOT_DIR)/build/llvm/lib/clang $(PREFIX)/lib/ touch build/compiler-rt.BUILT -# Flags for libcxx. +# Flags common to both the non-LTO and LTO builds of libcxx. LIBCXX_CMAKE_FLAGS = \ -DCMAKE_TOOLCHAIN_FILE=$(ROOT_DIR)/wasi-sdk.cmake \ -DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \ @@ -104,7 +105,7 @@ LIBCXX_CMAKE_FLAGS = \ --debug-trycompile build/libcxx.BUILT: build/llvm.BUILT build/compiler-rt.BUILT build/wasi-libc.BUILT - # Do the build. + # Do the conventional build. mkdir -p build/libcxx cmake -B build/libcxx -G Ninja $(LIBCXX_CMAKE_FLAGS) \ -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \ @@ -112,11 +113,20 @@ build/libcxx.BUILT: build/llvm.BUILT build/compiler-rt.BUILT build/wasi-libc.BUI -DLIBCXX_LIBDIR_SUFFIX=/wasm32-wasi \ $(LLVM_PROJ_DIR)/libcxx ninja $(NINJA_FLAGS) -v -C build/libcxx + # Now build the same thing but with LTO enabled. + mkdir -p build/libcxx.llvm-lto + cmake -B build/libcxx.llvm-lto -G Ninja $(LIBCXX_CMAKE_FLAGS) \ + -DCMAKE_C_FLAGS="-flto $(DEBUG_PREFIX_MAP)" \ + -DCMAKE_CXX_FLAGS="-flto $(DEBUG_PREFIX_MAP)" \ + -DLIBCXX_LIBDIR_SUFFIX=/wasm32-wasi/llvm-lto/$(CLANG_VERSION) \ + $(LLVM_PROJ_DIR)/libcxx + ninja $(NINJA_FLAGS) -v -C build/libcxx.llvm-lto # Do the install. ninja $(NINJA_FLAGS) -v -C build/libcxx install + ninja $(NINJA_FLAGS) -v -C build/libcxx.llvm-lto install touch build/libcxx.BUILT -# Flags for libcxxabi. +# Flags common to both the non-LTO and LTO builds of libcxxabi. LIBCXXABI_CMAKE_FLAGS = \ -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ -DCMAKE_CXX_COMPILER_WORKS=ON \ @@ -142,7 +152,7 @@ LIBCXXABI_CMAKE_FLAGS = \ --debug-trycompile build/libcxxabi.BUILT: build/libcxx.BUILT build/llvm.BUILT - # Do the build. + # Do the conventional build. mkdir -p build/libcxxabi cmake -B build/libcxxabi -G Ninja $(LIBCXXABI_CMAKE_FLAGS) \ -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \ @@ -150,8 +160,17 @@ build/libcxxabi.BUILT: build/libcxx.BUILT build/llvm.BUILT -DLIBCXXABI_LIBDIR_SUFFIX=/wasm32-wasi \ $(LLVM_PROJ_DIR)/libcxxabi ninja $(NINJA_FLAGS) -v -C build/libcxxabi + # Now build the same thing but with LTO enabled. + mkdir -p build/libcxxabi.llvm-lto + cmake -B build/libcxxabi.llvm-lto -G Ninja $(LIBCXXABI_CMAKE_FLAGS) \ + -DCMAKE_C_FLAGS="-flto $(DEBUG_PREFIX_MAP)" \ + -DCMAKE_CXX_FLAGS="-flto $(DEBUG_PREFIX_MAP)" \ + -DLIBCXXABI_LIBDIR_SUFFIX=/wasm32-wasi/llvm-lto/$(CLANG_VERSION) \ + $(LLVM_PROJ_DIR)/libcxxabi + ninja $(NINJA_FLAGS) -v -C build/libcxxabi.llvm-lto # Do the install. ninja $(NINJA_FLAGS) -v -C build/libcxxabi install + ninja $(NINJA_FLAGS) -v -C build/libcxxabi.llvm-lto install touch build/libcxxabi.BUILT build/config.BUILT: diff --git a/src/wasi-libc b/src/wasi-libc index 5933c205d..7b390e2a7 160000 --- a/src/wasi-libc +++ b/src/wasi-libc @@ -1 +1 @@ -Subproject commit 5933c205df976a9da0468802f164e5bb4f061b11 +Subproject commit 7b390e2a72be17fcd491c8c877232a53e2b4ecc3 From cee61283e78ca533e99e32f70d34314df8d38d66 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 24 Mar 2020 11:12:28 -0700 Subject: [PATCH 2/4] Add beginner-level documentation for installation and use --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 53d8340a0..cef66161f 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,24 @@ One could also use a standard Clang installation, build a sysroot from the sources mentioned above, and compile with "--target=wasm32-wasi --sysroot=/path/to/sysroot". +## Install + +A typical installation from the release binaries might look like the following: +```shell script +wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-[VERSION]/wasi-sdk-[VERSION]-linux.tar.gz +tar xvf wasi-sdk-[VERSION]-linux.tar.gz +``` + +## Use + +Use the clang installed in the wasi-sdk directory: +```shell script +CC="[WASI_SDK_PATH]/bin/clang --sysroot=[WASI_SDK_PATH]/share/wasi-sysroot" +$CC foo.c -o foo.wasm +``` +Note: `[WASI_SDK_PATH]/share/wasi-sysroot` contains the WASI-specific includes/libraries/etc. The `--sysroot=...` option +is not necessary if `WASI_SDK_PATH` is `/opt/wasi-sdk`. + ## Notes for Autoconf Upstream autoconf now From 25b4e3e3fa3c524d50fa6aec7920b1687d484b5a Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 24 Mar 2020 14:57:04 -0700 Subject: [PATCH 3/4] Strip symbols of all binaries generated in /bin --- Makefile | 2 +- strip_symbols.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100755 strip_symbols.sh diff --git a/Makefile b/Makefile index b9a3ea2ca..96cf059a3 100644 --- a/Makefile +++ b/Makefile @@ -164,7 +164,7 @@ build/config.BUILT: build: build/llvm.BUILT build/wasi-libc.BUILT build/compiler-rt.BUILT build/libcxxabi.BUILT build/libcxx.BUILT build/config.BUILT strip: build/llvm.BUILT - cd $(PREFIX)/bin; strip clang-* clang++-* lld llvm-ar + ./strip_symbols.sh $(PREFIX) package: build/package.BUILT diff --git a/strip_symbols.sh b/strip_symbols.sh new file mode 100755 index 000000000..b85350164 --- /dev/null +++ b/strip_symbols.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh +set -e + +DIRECTORY=${1:-/opt/wasi-sdk/bin} +EXECUTABLES=$(find ${DIRECTORY} -type f -executable) +for e in ${EXECUTABLES}; do + echo "Stripping symbols: ${e}" + strip ${e} || echo "Failed to strip symbols for ${e}; continuing on." +done From bf3835f216cde1ad99d4ad3c9d36dba04728c14a Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Fri, 3 Apr 2020 16:22:42 -0700 Subject: [PATCH 4/4] DEBUG: turn make down to -j1 so error is more obvious?? --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ab9a132a6..b92cff691 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,7 @@ jobs: run: sudo apt install ninja-build if: matrix.os == 'ubuntu-latest' - name: Build - run: sudo make -j4 package + run: sudo make -j1 package - name: Run the testsuite run: make check if: matrix.os == 'ubuntu-latest'