Dealing with "Maximum call stack size exceeded" on fsanitize=undefined

45 views
Skip to first unread message

Maksim Ivanov

unread,
Jan 20, 2021, 2:58:15 PM1/20/21
to emscripten-discuss
Hello, does anyone have a tip on how to work around the "Maximum call stack size exceeded" error when running a UBsan-sanitized Emscripten program under Node?

The error is:

"RangeError: Maximum call stack size exceeded
    at _emscripten_return_address (a.out.js:6788:35)
    at __ubsan_handle_dynamic_type_cache_miss (wasm-function[8220]:0x210eb3)
    at std::type_info::operator==(std::type_info const&) const (wasm-function[938]:0x648b3)
    at is_equal(std::type_info const*, std::type_info const*, bool) (wasm-function[8154]:0x20a911)
    at __dynamic_cast (wasm-function[8156]:0x20aa48)
    at __ubsan::checkDynamicType(void*, void*, unsigned long) (wasm-function[8196]:0x20f1b9)
    at HandleDynamicTypeCacheMiss(__ubsan::DynamicTypeCacheMissData*, unsigned long, unsigned long, __ubsan::ReportOptions) (wasm-function[8221]:0x210f03)
    at __ubsan_handle_dynamic_type_cache_miss (wasm-function[8220]:0x210ed7)
    at std::type_info::operator==(std::type_info const&) const (wasm-function[938]:0x648b3)
    at is_equal(std::type_info const*, std::type_info const*, bool) (wasm-function[8154]:0x20a911)"

I'm not 100% sure, but it seems that the error doesn't indicate a bug in the program, because it doesn't appear when compiling a small program (e.g., a Googletest binary with 0 tests) and begins to appear even after adding unused code (e.g., a bunch of disabled Googletest tests).

I tried passing "--stack_size=8192" to Node, but this didn't help; also, when increasing the number (e.g., to 131072) I'm starting to get a different error:

RuntimeError: memory access out of bounds
    at __dynamic_cast (wasm-function[8156]:0x20aa0f)
    at __ubsan::checkDynamicType(void*, void*, unsigned long) (wasm-function[8196]:0x20f1b9)
    at HandleDynamicTypeCacheMiss(__ubsan::DynamicTypeCacheMissData*, unsigned long, unsigned long, __ubsan::ReportOptions) (wasm-function[8221]:0x210f03)
    at __ubsan_handle_dynamic_type_cache_miss (wasm-function[8220]:0x210ed7)
    at std::type_info::operator==(std::type_info const&) const (wasm-function[938]:0x648b3)
    at is_equal(std::type_info const*, std::type_info const*, bool) (wasm-function[8154]:0x20a911)
    at __dynamic_cast (wasm-function[8156]:0x20aa48)
    at __ubsan::checkDynamicType(void*, void*, unsigned long) (wasm-function[8196]:0x20f1b9)
    at HandleDynamicTypeCacheMiss(__ubsan::DynamicTypeCacheMissData*, unsigned long, unsigned long, __ubsan::ReportOptions) (wasm-function[8221]:0x210f03)
    at __ubsan_handle_dynamic_type_cache_miss (wasm-function[8220]:0x210ed7)

Thanks.

Alon Zakai

unread,
Jan 21, 2021, 5:24:11 PM1/21/21
to emscripte...@googlegroups.com
Does the stack trace look like it's an infinite recursion? That could be a toolchain bug.


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/8c9c6b8b-a4b1-427c-965c-5828f8fa8fe9n%40googlegroups.com.

Thomas Lively

unread,
Jan 21, 2021, 5:49:21 PM1/21/21
to emscripte...@googlegroups.com
I've seen reports of infinite recursions involving __ubsan_handle_dynamic_type_cache_miss before, but I've never been able to reproduce them to investigate. Would you be able to share your reproducer?

Maksim Ivanov

unread,
Jan 21, 2021, 5:53:09 PM1/21/21
to emscripte...@googlegroups.com
@Alon: Hard to say whether it's an infinite recursion - the snippet I attached is all what's output. Can it be that something truncates the stack before printing, without leaving any trace of what was truncated?
My other hypothesis was that some code generated by UBSan allocates huge variables on stack; again, I don't know how to verify that.

@Thomas: Sure; I'll probably be able to do it in a couple of days, after minimizing the repro and removing irrelevant details from it.


Maksim


Alon Zakai

unread,
Jan 21, 2021, 6:06:20 PM1/21/21
to emscripte...@googlegroups.com
Different versions of node may truncate the stack to different defaults. But it is configurable, try

node --stack-trace-limit=1000

Maksim Ivanov

unread,
Jan 21, 2021, 7:07:43 PM1/21/21
to emscripte...@googlegroups.com
Thanks, Alon.
I added this flag and, indeed, it's an infinite recursion.

I'll update this thread once I have a minimized repro sample to share.


Maksim


Maksim Ivanov

unread,
Jan 21, 2021, 10:15:15 PM1/21/21
to emscripte...@googlegroups.com
The minimized repro is:

#include <gmock/gmock.h>
#include <gtest/gtest.h>
class A final {
 public:
  MOCK_METHOD0(Foo, void());
};
TEST(Some, DISABLED_Basic) {
  A a;
  EXPECT_CALL(a, Foo());
}

Googletest/mock are 1.10.0.


Maksim

Maksim Ivanov

Software Engineer

em...@google.com
+49 (0)176 65889070


Google Germany GmbH

Erika-Mann-Straße 33

80331 München


Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg


Diese E-Mail ist vertraulich. Wenn Sie nicht der richtige Adressat sind, leiten Sie diese bitte nicht weiter, informieren Sie den Absender und löschen Sie die E-Mail und alle Anhänge. Vielen Dank.

      

This e-mail is confidential. If you are not the right addressee please do not forward it, please inform the sender, and please erase this e-mail including any attachments. Thanks.

Thomas Lively

unread,
Jan 25, 2021, 2:58:05 PM1/25/21
to emscripte...@googlegroups.com
Thanks, I am able to reproduce the issue locally. Looking into it now.

Maksim Ivanov

unread,
Jan 26, 2021, 12:09:17 PM1/26/21
to emscripte...@googlegroups.com
Thanks, Thomas.

As this is a confirmed issue now, I went ahead and created an issue to track it: https://github.com/emscripten-core/emscripten/issues/13324


Maksim


Thomas Lively

unread,
Jan 28, 2021, 6:21:27 PM1/28/21
to emscripte...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages