Skip to content

Commit 7282a74

Browse files
committed
Enable libc++ error message in debug builds
Fixes: #24541
1 parent 2fe9aeb commit 7282a74

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

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 aare building without -pthread the thread constructor will fail,
16236+
# and in debug mode at leasts 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)

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)