emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.89k stars 3.32k forks source link

Asan crashes on malloc #12125

Closed avaer closed 3 years ago

avaer commented 4 years ago

I am getting this stack on calling a WASM function; the error comes from ASAN:

Uncaught (in promise) RuntimeError: memory access out of bounds
  | __sanitizer::ReportFile::Write(char const*, unsigned long) | @ | PsAssert.cpp:69
-- | -- | -- | --
  | __sanitizer::RawWrite(char const*) | @ | PsAssert.cpp:69
  | __sanitizer::MmapNoReserveOrDie(unsigned long, char const*) | @ | PsAssert.cpp:69
  | __asan::FakeStack::Create(unsigned long) | @ | PsAssert.cpp:69
  | __asan::AsanThread::AsyncSignalSafeLazyInitFakeStack() | @ | PsAssert.cpp:69
  | __asan_stack_malloc_0 | @ | PsAssert.cpp:69
  | sleep | @ | PsAssert.cpp:69
  | __sanitizer::SleepForSeconds(int) | @ | PsAssert.cpp:69
  | __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) | @ | PsAssert.cpp:69
  | __sanitizer::LargeMmapAllocator<__asan::AsanMapUnmapCallback, __sanitizer::LargeMmapAllocatorPtrArrayStatic, __sanitizer::LocalAddressSpaceView>::Allocate(__sanitizer::AllocatorStats*, unsigned long, unsigned long) | @ | PsAssert.cpp:69
  | __sanitizer::CombinedAllocator<__sanitizer::SizeClassAllocator32<__asan::AP32<__sanitizer::LocalAddressSpaceView> >, __sanitizer::LargeMmapAllocatorPtrArrayStatic>::Allocate(__sanitizer::SizeClassAllocator32LocalCache<__sanitizer::SizeClassAllocator32<__asan::AP32<__sanitizer::LocalAddressSpaceView> > >*, unsigned long, unsigned long) | @ | PsAssert.cpp:69
  | __asan::Allocator::Allocate(unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType, bool) | @ | PsAssert.cpp:69
  | __asan::asan_malloc(unsigned long, __sanitizer::BufferedStackTrace*) | @ | PsAssert.cpp:69
  | malloc | @ | PsAssert.cpp:69
  | ArenaAllocator::ArenaAllocator(unsigned int) | @ | subparcel.cc:44
  | makeArenaAllocator

Build command:

emcc -s WASM=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=599982080 -s MODULARIZE=0 -O3 -g3 -s ASSERTIONS=1 -fsanitize=address -s DETERMINISTIC=1 -s FORCE_FILESYSTEM=1 -s INVOKE_RUN=0 \
  -IPhysX/physx/include -IPhysX/pxshared/include \
  -IPhysX/physx/source/foundation/include \
  -IPhysX/physx/source/pvd/include \
  -IPhysX/physx/source/simulationcontroller/include -IPhysX/physx/source/lowlevel/api/include \
  -IPhysX/physx/source/geomutils/include \
  -IPhysX/physx/source/scenequery/include \
  -IPhysX/physx/source/lowleveldynamics/include \
  -IPhysX/physx/source/lowlevel/software/include \
  -IPhysX/physx/source/lowlevelaabb/include \
  -IPhysX/physx/source/lowlevel/common/include/pipeline \
  -IPhysX/physx/source/lowlevel/common/include/utils \
  -IPhysX/physx/source/lowlevel/common/include/collision \
  -IPhysX/physx/source/geomutils/src -IPhysX/physx/source/geomutils/src/common -IPhysX/physx/source/geomutils/src/mesh -IPhysX/physx/source/geomutils/src/hf -IPhysX/physx/source/geomutils/src/convex -IPhysX/physx/source/geomutils/src/gjk \
  -IPhysX/physx/source/common/src \
  -IPhysX/physx/source/physx/src/buffering \
  -IPhysX/physx/source/physx/src \
  -IPhysX/physx/source/physxcooking/src/convex \
  -IPhysX/physx/source/physxcooking/src/mesh \
  -IPhysX/physx/source/physxextensions/src/serialization/File \
  -IPhysX/physx/source/physxcooking/src \
  -IPhysX/physx/source/simulationcontroller/src \
  -IPhysX/physx/source/geomutils/src/intersection \
  -IPhysX//physx/source/geomutils/src/ccd \
  -IPhysX/physx/source/geomutils/src/contact \
  -IPhysX/physx/source/geomutils/src/pcm \
  -IPhysX/physx/source/geomutils/src/distance \
  -IPhysX/physx/source/geomutils/src/sweep \
  -Iearcut \
  -IRectBinPack/include \
  -Iconcaveman \
  objectize.cc vector.cc subparcel.cc geometry.cc collide.cc \
  FastNoise.cpp noise.cc march.cc biomes.cc \
  draco.o physx.o concaveman.o \
  -DNDEBUG -DPX_SIMD_DISABLED -DPX_EMSCRIPTEN=1 -DPX_COOKING \
  -I. \
  -o bin/geometry.js
avaer commented 4 years ago

I might have blown the memory limits; this seems to make a difference:

-s ASAN_SHADOW_SIZE=134217728

It should probably still not crash like this though.

tlively commented 4 years ago

I'll take a look at how the default ASan shadow size is computed to see if we can make it better or have it output some sort of diagnostic.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

tlively commented 3 years ago

It looks like we fixed this in #12249.