Skip to content

Commit 1b48188

Browse files
committed
Enable libc++ error message in debug builds
Fixes: #24541
1 parent c08fbb0 commit 1b48188

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

embuilder.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
'libc++-wasmexcept',
5555
'libc++-noexcept',
5656
'libc++-ww-noexcept',
57+
'libc++-debug',
58+
'libc++-debug-wasmexcept',
59+
'libc++-debug-legacyexcept',
60+
'libc++-debug-noexcept',
61+
'libc++-debug-ww-noexcept',
5762
'libal',
5863
'libdlmalloc',
5964
'libdlmalloc-tracing',
@@ -106,6 +111,8 @@
106111
'libc++abi-debug-mt-noexcept',
107112
'libc++-mt',
108113
'libc++-mt-noexcept',
114+
'libc++-debug-mt',
115+
'libc++-debug-mt-noexcept',
109116
'libdlmalloc-mt',
110117
'libdlmalloc-mt-debug',
111118
'libGL-emu',

system/lib/libcxx/include/__verbose_abort

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4343
// make sure that the program terminates but without taking any complex dependencies in this header.
4444
#if !defined(_LIBCPP_VERBOSE_ABORT)
4545

46-
// XXX EMSCRIPTEN __libcpp_verbose_abort creases code size too much
47-
# if !_LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT || defined (__EMSCRIPTEN__)
46+
// XXX EMSCRIPTEN avoid __libcpp_verbose_abort in release builds due to code
47+
// size
48+
# if !_LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT || (defined(__EMSCRIPTEN__) && defined(NDEBUG))
4849
// The decltype is there to suppress -Wunused warnings in this configuration.
4950
void __use(const char*, ...);
5051
# define _LIBCPP_VERBOSE_ABORT(...) (decltype(::std::__use(__VA_ARGS__))(), __builtin_abort())

system/lib/libcxx/src/verbose_abort.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <cstdarg>
1212
#include <cstdio>
1313
#include <cstdlib>
14+
#include <cstring>
1415

1516
#ifdef __BIONIC__
1617
# include <syslog.h>
@@ -30,6 +31,12 @@ _LIBCPP_WEAK void __libcpp_verbose_abort(char const* format, ...) _LIBCPP_VERBOS
3031
va_list list;
3132
va_start(list, format);
3233
std::vfprintf(stderr, format, list);
34+
// TODO(sbc): Add newline here unconditionally. libc++ seems inconsistent about strings
35+
// passed to __libcpp_verbose_abort. The _LIBCPP_VERBOSE_ABORT macro seems to never use
36+
// newlines, but _LIBCPP_ASSERTION_HANDLER does include a newline.
37+
if (format[strlen(format) - 1] != '\n') {
38+
std::fprintf(stderr, "\n");
39+
}
3340
va_end(list);
3441
}
3542

test/test_other.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16219,3 +16219,20 @@ def test_unsupported_min_version_when_unsupported_env(self, env):
1621916219
})
1622016220
def test_automatic_env_worker(self, env, emcc_args):
1622116221
self.emcc(test_file('hello_world.c'), [f'-sENVIRONMENT={env}'] + emcc_args)
16222+
16223+
def test_libcxx_errors(self):
16224+
create_file('main.cpp', '''
16225+
#include <thread>
16226+
void func() {
16227+
}
16228+
16229+
int main() {
16230+
std::thread t(func);
16231+
t.join();
16232+
}
16233+
''')
16234+
16235+
# Since we are building without -pthread the thread constructor will fail,
16236+
# and in debug mode at least we expect to see the error message from libc++
16237+
expected = 'system_error was thrown in -fno-exceptions mode with error 6 and message "thread constructor failed"'
16238+
self.do_runf('main.cpp', expected, assert_returncode=NON_ZERO)

test/test_sanity.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,15 @@ def test_emcc_caching(self):
397397

398398
# Building a file that *does* need something *should* trigger cache
399399
# generation, but only the first time
400-
libname = cache.get_lib_name('libc++.a')
401400
for i in range(3):
402401
print(i)
403402
self.clear()
404403
output = self.do([EMCC, '-O' + str(i), test_file('hello_libcxx.cpp'), '-sDISABLE_EXCEPTION_CATCHING=0'])
405-
print('\n\n\n', output)
406-
self.assertContainedIf(BUILDING_MESSAGE % libname, output, i == 0)
404+
if i == 0:
405+
libname = cache.get_lib_name('libc++-debug.a')
406+
else:
407+
libname = cache.get_lib_name('libc++.a')
408+
self.assertContainedIf(BUILDING_MESSAGE % libname, output, i == 0 or i == 1)
407409
self.assertContained('hello, world!', self.run_js('a.out.js'))
408410
self.assertExists(cache.cachedir)
409411
self.assertExists(os.path.join(cache.cachedir, libname))

tools/system_libs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ def get_files(self):
16651665
filenames=filenames)
16661666

16671667

1668-
class libcxx(ExceptionLibrary, MTLibrary):
1668+
class libcxx(ExceptionLibrary, MTLibrary, DebugLibrary):
16691669
name = 'libc++'
16701670

16711671
cflags = [

0 commit comments

Comments
 (0)