From 8fbfe1875dec7980a9c6a952924f9b3912a57ebc Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 20 May 2024 12:36:57 -0700 Subject: [PATCH 1/3] Add DWARF debugging information to all artifacts by default This commit adds DWARF debugging information with the `-g` compiler flag to all WASI artifacts for wasi-sdk. The LLVM build itself does not have debugging information, only the sysroot artifacts. This is intended to assist with debugging. The main downside to this is binary size of generated artifacts will, by default, be larger. Stripping debug information from an artifact though involves removing custom sections which is generally pretty easy to do through wasm tooling. --- Makefile | 11 ++++++++--- src/wasi-libc | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index eeac2dbff..15f2c78b8 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,11 @@ CLANG_VERSION=$(shell $(VERSION_SCRIPT) llvm-major --llvm-dir=$(LLVM_PROJ_DIR)) VERSION:=$(shell $(VERSION_SCRIPT)) DEBUG_PREFIX_MAP=-fdebug-prefix-map=$(ROOT_DIR)=wasisdk://v$(VERSION) +# Generate debuginfo by default for wasi-sdk since it's easily strippable and +# otherwise quite useful for debugging. +WASI_SDK_CFLAGS := $(DEBUG_PREFIX_MAP) -g +WASI_SDK_CXXFLAGS := $(WASI_SDK_CFLAGS) + default: build @echo "Use -fdebug-prefix-map=$(ROOT_DIR)=wasisdk://v$(VERSION)" @@ -166,7 +171,7 @@ build/compiler-rt.BUILT: build/llvm.BUILT -DCOMPILER_RT_ENABLE_IOS=OFF \ -DCOMPILER_RT_DEFAULT_TARGET_ONLY=On \ -DWASI_SDK_PREFIX=$(BUILD_PREFIX) \ - -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \ + -DCMAKE_C_FLAGS="$(WASI_SDK_CFLAGS)" \ -DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \ -DCOMPILER_RT_OS_DIR=wasi \ -DCMAKE_INSTALL_PREFIX=$(PREFIX)/lib/clang/$(CLANG_VERSION)/ \ @@ -225,8 +230,8 @@ LIBCXX_CMAKE_FLAGS = \ -DUNIX:BOOL=ON \ --debug-trycompile \ -DCMAKE_SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \ - -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) $(EXTRA_CFLAGS) $(4) --target=$(3)" \ - -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) $(EXTRA_CXXFLAGS) $(4) --target=$(3)" \ + -DCMAKE_C_FLAGS="$(WASI_SDK_CFLAGS) $(EXTRA_CFLAGS) $(4) --target=$(3)" \ + -DCMAKE_CXX_FLAGS="$(WASI_SDK_CXXFLAGS) $(EXTRA_CXXFLAGS) $(4) --target=$(3)" \ -DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/$(3) \ -DLIBCXXABI_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/$(3) \ -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \ diff --git a/src/wasi-libc b/src/wasi-libc index 9e8c54231..44c4b1e3a 160000 --- a/src/wasi-libc +++ b/src/wasi-libc @@ -1 +1 @@ -Subproject commit 9e8c542319242a5e536e14e6046de5968d298038 +Subproject commit 44c4b1e3a58f5c3042fa26dff9c1b29b6fc695b2 From 22cd38fffae4a21699dae85be181f1b289c5c97e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 21 May 2024 13:30:55 -0700 Subject: [PATCH 2/3] Pass extra cflags to wasi-libc --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 15f2c78b8..04fb23fa4 100644 --- a/Makefile +++ b/Makefile @@ -143,6 +143,7 @@ WASI_LIBC_MAKEFLAGS = \ AR=$(BUILD_PREFIX)/bin/llvm-ar \ NM=$(BUILD_PREFIX)/bin/llvm-nm \ SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \ + EXTRA_CFLAGS="$(WASI_SDK_CFLAGS)" \ TARGET_TRIPLE=$(1) build/wasi-libc.BUILT: build/compiler-rt.BUILT build/wasm-component-ld.BUILT From f0f64bd0a0a0002a6cb080bdb8406c3d71a41b6c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 22 May 2024 07:50:11 -0700 Subject: [PATCH 3/3] Fix tests from previous commit * Update some expected error messages and remove some files with duplicate error messages that are no longer needed. * Remove undefined behavior in `stat.c` where padding bytes were being compared. --- tests/general/abort.c.stderr.expected | 3 ++- tests/general/abort.c.stderr.expected.filter | 1 + ...bort.c.wasm32-wasi-preview2.stderr.expected | 6 ------ .../abort.c.wasm32-wasi.stderr.expected | 6 ------ .../abort.c.wasm32-wasip2.stderr.expected | 6 ------ tests/general/assert-fail.c.stderr.expected | 3 ++- .../assert-fail.c.stderr.expected.filter | 1 + ...fail.c.wasm32-wasi-preview2.stderr.expected | 7 ------- ...assert-fail.c.wasm32-wasip2.stderr.expected | 7 ------- tests/general/stat.c | 18 ++++++++++++++---- 10 files changed, 20 insertions(+), 38 deletions(-) delete mode 100644 tests/general/abort.c.wasm32-wasi-preview2.stderr.expected delete mode 100644 tests/general/abort.c.wasm32-wasi.stderr.expected delete mode 100644 tests/general/abort.c.wasm32-wasip2.stderr.expected delete mode 100644 tests/general/assert-fail.c.wasm32-wasi-preview2.stderr.expected delete mode 100644 tests/general/assert-fail.c.wasm32-wasip2.stderr.expected diff --git a/tests/general/abort.c.stderr.expected b/tests/general/abort.c.stderr.expected index c6ecf6a93..d533e582f 100644 --- a/tests/general/abort.c.stderr.expected +++ b/tests/general/abort.c.stderr.expected @@ -1,6 +1,7 @@ Error: failed to run main module `abort.c.---.wasm` Caused by: - 0: failed to invoke command default + 0: failed to invoke --- 1: error while executing at wasm backtrace: + note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information 2: wasm trap: wasm `unreachable` instruction executed diff --git a/tests/general/abort.c.stderr.expected.filter b/tests/general/abort.c.stderr.expected.filter index 742503a5c..ecd16c053 100755 --- a/tests/general/abort.c.stderr.expected.filter +++ b/tests/general/abort.c.stderr.expected.filter @@ -3,4 +3,5 @@ set -euo pipefail cat \ | sed -e 's/main module `abort\.c\.[^`]*\.wasm`/main module `abort.c.---.wasm`/' \ + | sed -e 's/failed to invoke.*/failed to invoke ---/' \ | sed -E '/0x[[:xdigit:]]+/d' diff --git a/tests/general/abort.c.wasm32-wasi-preview2.stderr.expected b/tests/general/abort.c.wasm32-wasi-preview2.stderr.expected deleted file mode 100644 index 26fe376cf..000000000 --- a/tests/general/abort.c.wasm32-wasi-preview2.stderr.expected +++ /dev/null @@ -1,6 +0,0 @@ -Error: failed to run main module `abort.c.---.wasm` - -Caused by: - 0: failed to invoke `run` function - 1: error while executing at wasm backtrace: - 2: wasm trap: wasm `unreachable` instruction executed diff --git a/tests/general/abort.c.wasm32-wasi.stderr.expected b/tests/general/abort.c.wasm32-wasi.stderr.expected deleted file mode 100644 index c6ecf6a93..000000000 --- a/tests/general/abort.c.wasm32-wasi.stderr.expected +++ /dev/null @@ -1,6 +0,0 @@ -Error: failed to run main module `abort.c.---.wasm` - -Caused by: - 0: failed to invoke command default - 1: error while executing at wasm backtrace: - 2: wasm trap: wasm `unreachable` instruction executed diff --git a/tests/general/abort.c.wasm32-wasip2.stderr.expected b/tests/general/abort.c.wasm32-wasip2.stderr.expected deleted file mode 100644 index 26fe376cf..000000000 --- a/tests/general/abort.c.wasm32-wasip2.stderr.expected +++ /dev/null @@ -1,6 +0,0 @@ -Error: failed to run main module `abort.c.---.wasm` - -Caused by: - 0: failed to invoke `run` function - 1: error while executing at wasm backtrace: - 2: wasm trap: wasm `unreachable` instruction executed diff --git a/tests/general/assert-fail.c.stderr.expected b/tests/general/assert-fail.c.stderr.expected index c179f09ad..9e0f44c5a 100644 --- a/tests/general/assert-fail.c.stderr.expected +++ b/tests/general/assert-fail.c.stderr.expected @@ -2,6 +2,7 @@ Assertion failed: false (assert-fail.c: main: 5) Error: failed to run main module `assert-fail.c.---.wasm` Caused by: - 0: failed to invoke command default + 0: failed to invoke --- 1: error while executing at wasm backtrace: + note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information 2: wasm trap: wasm `unreachable` instruction executed diff --git a/tests/general/assert-fail.c.stderr.expected.filter b/tests/general/assert-fail.c.stderr.expected.filter index d2213dd6b..a1d649de0 100755 --- a/tests/general/assert-fail.c.stderr.expected.filter +++ b/tests/general/assert-fail.c.stderr.expected.filter @@ -3,4 +3,5 @@ set -euo pipefail cat \ | sed -e 's/main module `assert-fail\.c\.[^`]*\.wasm`/main module `assert-fail.c.---.wasm`/' \ + | sed -e 's/failed to invoke.*/failed to invoke ---/' \ | sed -E '/0x[[:xdigit:]]+/d' diff --git a/tests/general/assert-fail.c.wasm32-wasi-preview2.stderr.expected b/tests/general/assert-fail.c.wasm32-wasi-preview2.stderr.expected deleted file mode 100644 index 3702431bd..000000000 --- a/tests/general/assert-fail.c.wasm32-wasi-preview2.stderr.expected +++ /dev/null @@ -1,7 +0,0 @@ -Assertion failed: false (assert-fail.c: main: 5) -Error: failed to run main module `assert-fail.c.---.wasm` - -Caused by: - 0: failed to invoke `run` function - 1: error while executing at wasm backtrace: - 2: wasm trap: wasm `unreachable` instruction executed diff --git a/tests/general/assert-fail.c.wasm32-wasip2.stderr.expected b/tests/general/assert-fail.c.wasm32-wasip2.stderr.expected deleted file mode 100644 index 3702431bd..000000000 --- a/tests/general/assert-fail.c.wasm32-wasip2.stderr.expected +++ /dev/null @@ -1,7 +0,0 @@ -Assertion failed: false (assert-fail.c: main: 5) -Error: failed to run main module `assert-fail.c.---.wasm` - -Caused by: - 0: failed to invoke `run` function - 1: error while executing at wasm backtrace: - 2: wasm trap: wasm `unreachable` instruction executed diff --git a/tests/general/stat.c b/tests/general/stat.c index dc007c120..393921f70 100644 --- a/tests/general/stat.c +++ b/tests/general/stat.c @@ -43,10 +43,20 @@ int main(int argc, char *argv[]) { assert(file_statbuf.st_dev == link_statbuf.st_dev); - // Clear out the access time fields, and they should be the same. - memset(&file_statbuf.st_atim, 0, sizeof(struct timespec)); - memset(&link_statbuf.st_atim, 0, sizeof(struct timespec)); - assert(memcmp(&file_statbuf, &link_statbuf, sizeof(struct stat)) == 0); + assert(file_statbuf.st_dev == link_statbuf.st_dev); + assert(file_statbuf.st_ino == link_statbuf.st_ino); + assert(file_statbuf.st_mode == link_statbuf.st_mode); + assert(file_statbuf.st_uid == link_statbuf.st_uid); + assert(file_statbuf.st_gid == link_statbuf.st_gid); + assert(file_statbuf.st_rdev == link_statbuf.st_rdev); + assert(file_statbuf.st_size == link_statbuf.st_size); + assert(file_statbuf.st_blksize == link_statbuf.st_blksize); + assert(file_statbuf.st_blocks == link_statbuf.st_blocks); + // NB: `atim` is explicitly not compared here + assert(file_statbuf.st_mtim.tv_sec == link_statbuf.st_mtim.tv_sec); + assert(file_statbuf.st_mtim.tv_nsec == link_statbuf.st_mtim.tv_nsec); + assert(file_statbuf.st_ctim.tv_sec == link_statbuf.st_ctim.tv_sec); + assert(file_statbuf.st_ctim.tv_nsec == link_statbuf.st_ctim.tv_nsec); // Test lstat.