Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-sSINGLE_FILE and -fsanitize=address,undefined #23257

Open
bottle2 opened this issue Dec 27, 2024 · 3 comments · May be fixed by #23292
Open

-sSINGLE_FILE and -fsanitize=address,undefined #23257

bottle2 opened this issue Dec 27, 2024 · 3 comments · May be fixed by #23292

Comments

@bottle2
Copy link

bottle2 commented Dec 27, 2024

Version of emscripten/emsdk:

$ emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.74-git (1092ec30a3fb1d46b
1782ff1b4db5094d3d06ae5)
clang version 20.0.0git
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:/msys64/clang64/opt/emscripten-llvm/bin
$ emcc -gsource-map -g3 -Og -sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=655360000 -sSINGLE_FILE -fsanitize=address,undefined $$(find . -name '*.c' ! -name batch.c ! -name simple.c) --use-port=sdl2 -o index.html --shell-file=shell.html

this compiles and runs fine!!

THE PROBLEM: sanitizer works fine with -sSINGLE_FILE, but when it catches an error, it displays offsets in hex :(
I "solved" by removing -sSINGLE_FILE, then it shows line in source code correctly when it catches an error!!

some solutions:

  1. add a warning that -sSINGLE_FILE and -fsanitize= should not go together
  2. make it an error that makes build fail, rather than warning
  3. make them work™ together

a warning is enough for me <3

@kripken
Copy link
Member

kripken commented Jan 2, 2025

THE PROBLEM: sanitizer works fine with -sSINGLE_FILE, but when it catches an error, it displays offsets in hex :(

Perhaps paste the output you are concerned about, as I may not be understanding what you are referring to. I think hex offsets are expected. For example,

#include <string.h>
int main(int argc, char *argv[]) {
  strcpy(argv[1], argv[0]);
  return 0;
}

With or without SINGLE_FILE, with ASan (and no argv provided on the commandline) that errors with

=================================================================
==42==ERROR: AddressSanitizer: null-pointer-dereference on address 0x00000000 at pc 0x00000f3b bp 0x12956580 sp 0x1295658c
WRITE of size 1 at 0x00000000 thread T0
    #0 0x00000f3b in wasm-function[32]+0xf3b (/home/azakai/Dev/emscripten/a.out.js+0xf3b)

Address 0x00000000 is located in the shadow gap area.
SUMMARY: AddressSanitizer: null-pointer-dereference (/home/azakai/Dev/emscripten/a.out.js+0xf37) in wasm-function[32]+0xf37
==42==ABORTING

Those hex offsets are expected, and SINGLE_FILE can't affect them (it just affects how we store the binary, not offsets in it).

@bottle2
Copy link
Author

bottle2 commented Jan 3, 2025

sorry for the hasty report. my problem is that -sSINGLE_FILE inhibits the behavior of -gsource-map me thinks.

here is a detailed session that I hope elucidates:

$ emcc --version
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.74-git (1092ec30a3fb1d46b1782ff1b4db5094d3d06ae5)
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ node --version
v23.1.0
$ cat test.c
int main(void)
{
    (void)*(char *)999;
    return 0;
}
$ emcc -gsource-map -fsanitize=address,undefined test.c
$ ls
a.out.js  a.out.wasm  a.out.wasm.map  test.c
$ node a.out.js
=================================================================
==42==ERROR: AddressSanitizer: null-pointer-dereference on address 0x000003e7 at pc 0x00000e5a bp 0x12957480 sp 0x1295748c
READ of size 1 at 0x000003e7 thread T0
    #0 0xe5a in __original_main test.c:3:11

Address 0x000003e7 is located in the shadow gap area.
SUMMARY: AddressSanitizer: null-pointer-dereference test.c:3:11 in __original_main
==42==ABORTING
$ rm a*
$ emcc -gsource-map -fsanitize=address,undefined -sSINGLE_FILE test.c
$ ls
a.out.js  test.c
$ node a.out.js
=================================================================
==42==ERROR: AddressSanitizer: null-pointer-dereference on address 0x000003e7 at pc 0x00000e5a bp 0x12957480 sp 0x1295748c
READ of size 1 at 0x000003e7 thread T0
    #0 0xe5a in __original_main+0xe5a (D:/Projetos/raytracing/sample/a.out.js+0xe5a)

Address 0x000003e7 is located in the shadow gap area.
SUMMARY: AddressSanitizer: null-pointer-dereference (D:/Projetos/raytracing/sample/a.out.js+0xe56) in __original_main+0xe56
==42==ABORTING

notice that the first compilation reports the file and line that caused the error, while the second compilation is missing this file a.out.wasm.map, and when run, it only shows the not so helpful hex offset

@kripken
Copy link
Member

kripken commented Jan 3, 2025

I see now, thanks. Yes, source maps are disabled by SINGLE_FILE as they require a file on the side, and I agree it's confusing not to warn on that. #23292 will add a warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants