Skip to content

Commit

Permalink
Add DWARF debugging information to all artifacts by default (#422)
Browse files Browse the repository at this point in the history
* 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.

* Pass extra cflags to wasi-libc

* 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.
  • Loading branch information
alexcrichton authored May 22, 2024
1 parent af429ed commit 307694b
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 42 deletions.
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down Expand Up @@ -138,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
Expand Down Expand Up @@ -166,7 +172,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)/ \
Expand Down Expand Up @@ -225,8 +231,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" \
Expand Down
3 changes: 2 additions & 1 deletion tests/general/abort.c.stderr.expected
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/general/abort.c.stderr.expected.filter
Original file line number Diff line number Diff line change
Expand Up @@ -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'
6 changes: 0 additions & 6 deletions tests/general/abort.c.wasm32-wasi-preview2.stderr.expected

This file was deleted.

6 changes: 0 additions & 6 deletions tests/general/abort.c.wasm32-wasi.stderr.expected

This file was deleted.

6 changes: 0 additions & 6 deletions tests/general/abort.c.wasm32-wasip2.stderr.expected

This file was deleted.

3 changes: 2 additions & 1 deletion tests/general/assert-fail.c.stderr.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/general/assert-fail.c.stderr.expected.filter
Original file line number Diff line number Diff line change
Expand Up @@ -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'

This file was deleted.

7 changes: 0 additions & 7 deletions tests/general/assert-fail.c.wasm32-wasip2.stderr.expected

This file was deleted.

18 changes: 14 additions & 4 deletions tests/general/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 307694b

Please sign in to comment.