Skip to content

ASan error inside pthread_create and malloc #15762

Closed
@tlively

Description

@tlively

Using tot installed just now:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.0.1-git (ad05649111fa61c653b11adf86fe418782ecbf06)
clang version 14.0.0 (https://github.com/llvm/llvm-project 9cbab13282fe59885b6f9c2411eddbdd452c36e7)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/local/google/home/tlively/code/emsdk/upstream/bin

Reproducer:

// test.c
#include <pthread.h>

pthread_t other_thread;

static void* thread_main(void* arg) {
  return NULL;
}

int main(int argc, char* argv[]) {
  pthread_create(&other_thread, NULL, thread_main, NULL);
}

Compile and run:

 ~/code/emsdk/upstream/emscripten/emcc test.c -o test.js -pthread -fsanitize=address -sPTHREAD_POOL_SIZE=2 --profiling-funcs && node --experimental-wasm-threads test.js

Output:

exiting due to exception: RuntimeError: memory access out of bounds,RuntimeError: memory access out of bounds
    at __sanitizer::StackDepotBase<__sanitizer::StackDepotNode, 1, 20>::Put(__sanitizer::StackTrace, bool*) (<anonymous>:wasm-function[861]:0x2805d)
    at __sanitizer::StackDepotPut(__sanitizer::StackTrace) (<anonymous>:wasm-function[860]:0x27f7d)
    at __asan::Allocator::Allocate(unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType, bool) (<anonymous>:wasm-function[389]:0x13383)
    at __asan::asan_malloc(unsigned long, __sanitizer::BufferedStackTrace*) (<anonymous>:wasm-function[388]:0x13059)
    at malloc (<anonymous>:wasm-function[477]:0x18fe6)
    at __pthread_create (<anonymous>:wasm-function[83]:0x58c6)
    at pthread_create (<anonymous>:wasm-function[348]:0x11815)
    at main (<anonymous>:wasm-function[51]:0x130e)
    at /usr/local/google/home/tlively/code/emscripten/test.js:1378:20
    at callMain (/usr/local/google/home/tlively/code/emscripten/test.js:6950:13)

Notes: Adding -g makes the problem go away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions