Repository navigation
Allow emscripten to use the full ubsan runtime - #8651
Conversation
|
|
I will put in the LLVM version later. As for which parts of the sanitizers were modified, see here. |
|
|
The link will continue to work with new commits pushed, since it references the branch of this pull request. Unless we rebase the commits onto a different version of LLVM, of course. |
|
|
Okay, I'll make a PR that pulls in the latest LLVM release and base this on that. |
|
This won't work until https://reviews.llvm.org/D62210 has been merged into LLVM. |
These runtimes will be made to work in #8651.
| add_library(system_libs_map[d]) | ||
|
|
||
| for d in lib.js_deps: | ||
| shared.Settings.EXPORTED_FUNCTIONS.append('_%s' % d) |
There was a problem hiding this comment.
Can you explain this a litte? It looks like it just used for memalign? Is memalign implemented in JS? Why to do need js_deps now but we've managed to get away without them previously?
There was a problem hiding this comment.
This is __syscall192 (a JS function) depending on memalign (a C function), but we only add back dependencies to user code, not libraries.
Here, the sanitizer common library depends on __syscall192, but memalign is not pulled in because the user code doesn't use __syscall192.
I am not sure if this is the best approach, but I am doing this for now so that it at least works.
|
|
||
| if shared.Settings.UBSAN_RUNTIME == 1: | ||
| libs_to_link.append((shared.Cache.get('libubsan_minimal_rt_wasm.a', lambda: create_wasm_ubsan_minimal_rt('libubsan_minimal_rt_wasm.a')), False)) | ||
|
|
There was a problem hiding this comment.
How does ubsan work on regular systems? Presumably you need to add a linker flag otherwise you'll get undefined symbols? I guess we can use our dependency system to do one better but I think requiring the linker flag is also ok.
There was a problem hiding this comment.
clang automatically adds the ubsan library to the linker command line.
There was a problem hiding this comment.
But only if you specify the -fsanitize.. flag no?
There was a problem hiding this comment.
Yea. The code you commented on was the old code that parses the command line for -fsanitize, but @kripken wanted to use the dependency system, and so it's now doing that.
| -------- T _ZN11__sanitizer23internal_simple_strtollEPKcPS1_i | ||
|
|
||
| sanitizer_allocator.cc.o: | ||
| -------- d .L.str |
There was a problem hiding this comment.
I don't see these local symbols on the other .symbols file. Is there something we are doing differently here?
There was a problem hiding this comment.
I am not sure how these files are generated. I just did llvm-nm and replaced the addresses with - with perl.
Summary: After emscripten-core/emscripten#8651, Emscripten supports the full UBSan runtime. This includes the VPtr sanitizer. This diff allows clang to generate code that uses the VPtr sanitizer for Emscripten. Patch by Guanzhong Chen Reviewers: tlively, aheejin Reviewed By: aheejin Subscribers: dschuff, sbc100, jgravelle-google, sunfish, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62559 llvm-svn: 362004
Summary: After emscripten-core/emscripten#8651, Emscripten supports the full UBSan runtime. This includes the VPtr sanitizer. This diff allows clang to generate code that uses the VPtr sanitizer for Emscripten. Patch by Guanzhong Chen Reviewers: tlively, aheejin Reviewed By: aheejin Subscribers: dschuff, sbc100, jgravelle-google, sunfish, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62559 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362004 91177308-0d34-0410-b5e6-96231b3b80d8
Summary: After emscripten-core/emscripten#8651, Emscripten supports the full UBSan runtime. This includes the VPtr sanitizer. This diff allows clang to generate code that uses the VPtr sanitizer for Emscripten. Patch by Guanzhong Chen Reviewers: tlively, aheejin Reviewed By: aheejin Subscribers: dschuff, sbc100, jgravelle-google, sunfish, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62559 git-svn-id: http://llvm.org/svn/llvm-project/cfe/trunk@362004 91177308-0d34-0410-b5e6-96231b3b80d8
|
@sbc100 do you have any other concerns? |
| } | ||
|
|
||
| char **GetEnviron() { | ||
| return fake_envp; |
There was a problem hiding this comment.
Why fake this? Can't you use emscripten_get_env()?
There was a problem hiding this comment.
For some strange reason, the sanitizers want a function to get the entire environment block, as in a sequence of null-terminated strings going NAME=VALUE. It doesn't appear to be used anywhere that makes a difference yet, so I am stubbing it out.
| U abort | ||
| U emscripten_return_address | ||
| U strlen | ||
| U write |
There was a problem hiding this comment.
Again, I think if we revert to the old behavior of linking if and only if the user specific -fsantize we can avoid these extra symbols files. Maybe wait for @kripken to respond because I know he explicitly advised you to go this route.
|
I remove my objection to duplicating the sanitizer flags, if you and @sbc100 both think that's better. So can avoid using the undefined symbols. |
| @@ -1,1392 +0,0 @@ | |||
|
|
|||
There was a problem hiding this comment.
Can you delete these .symbols files now?
There was a problem hiding this comment.
They have been deleted.
| }, | ||
|
|
||
| emscripten_get_module_name: function(buf, length) { | ||
| return stringToUTF8(wasmBinaryFile, buf, length); |
There was a problem hiding this comment.
Sorry for the late review!
wasmBinaryFile will not exist in wasm2js mode, or if the wasm was embedded in the JS. But maybe it's not worth trying to support more cases than the common one.
There was a problem hiding this comment.
It appears to exist in wasm2js mode, which is why I did this:
$ emcc -fsanitize=null null-read.c -s WASM=0
emcc:WARNING: emcc: JS support in the upstream LLVM+wasm2js path is very experimental currently (best to use fastcomp for asm.js for now)
emscripten:WARNING: Wasm source map won't be usable in a browser without --source-map-base
$ grep wasmBinaryFile a.out.js
var wasmBinaryFile = 'a.out.wasm';
if (!isDataURI(wasmBinaryFile)) {
wasmBinaryFile = locateFile(wasmBinaryFile);
return Module['readBinary'](wasmBinaryFile);
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
!isDataURI(wasmBinaryFile) &&
return WebAssembly.instantiateStreaming(fetch(wasmBinaryFile, { credentials: 'same-origin' }), info)
return stringToUTF8(wasmBinaryFile, buf, length);
$ node a.out.js
null-read.c:3:9: runtime error: load of null pointer of type 'int'There was a problem hiding this comment.
I don't understand? The file doesn't exist, but the variable does, yes. Is just the variable name enough?
There was a problem hiding this comment.
Yes, it just wants a name.
…e#8654) These runtimes will be made to work in emscripten-core#8651.
Changes:
* Made `sanitizer_common` and `ubsan` runtimes work:
* Add `SANITIZER_EMSCRIPTEN` platform
* Add `sanitizer_emscripten.cc` for Emscripten-specific implementations of
helper and abstraction functions
* Stub out functions that do not work on Emscripten. Using these will be
abort the program. These will be implemented later.
* Add `emscripten_get_module_name` to get the WASM module name
* Changed `embuilder` to build `ubsan` and `sanitizer_common` runtimes
* Add `ubsan`-related unit tests
* Remove old JS-based `ubsan` hack and its unit tests
Known limitations:
* Stack traces do not work.
This helper was added when we implement sanitizes in emscripten-core#8651. It was never added to any public header file and should only have these two internal users. Instead of this function we can just use the existing internal `_emscripten_get_progname` function, which can in turn then be implemented in terms of the existing `getExecutableName` JavaScript function.
This helper was added when we implement sanitizes in emscripten-core#8651. It was never added to any public header file and should only have these two internal users. Instead of this function we can just use the existing internal `_emscripten_get_progname` function, which can in turn then be implemented in terms of the existing `getExecutableName` JavaScript function.
This helper was added when we implement sanitizes in emscripten-core#8651. It was never added to any public header file and should only have these two internal users. Instead of this function we can just use the existing internal `_emscripten_get_progname` function, which can in turn then be implemented in terms of the existing `getExecutableName` JavaScript function.
This helper was added when we implement sanitizes in emscripten-core#8651. It was never added to any public header file and should only have these two internal users. Instead of this function we can just use the existing internal `_emscripten_get_progname` function, which can in turn then be implemented in terms of the existing `getExecutableName` JavaScript function.
This helper was added when we implement sanitizes in emscripten-core#8651. It was never added to any public header file and should only have these two internal users. Instead of this function we can just use the existing internal `_emscripten_get_progname` function, which can in turn then be implemented in terms of the existing `getExecutableName` JavaScript function.
This helper was added when we implement sanitizes in #8651. It was never added to any public header file and should only have these two internal users. Instead of this function we can just use the existing internal `_emscripten_get_progname` function, which can in turn then be implemented in terms of the existing `getExecutableName` JavaScript function.
Changes:
sanitizer_commonandubsanruntimes work:SANITIZER_EMSCRIPTENplatformsanitizer_emscripten.ccfor Emscripten-specific implementations ofhelper and abstraction functions
abort the program. These will be implemented later.
emscripten_get_module_nameto get the WASM module nameembuilderto buildubsanandsanitizer_commonruntimesubsan-related unit testsubsanhack and its unit testsKnown limitations: