-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++abi] Disable undesired attempts at opening file descriptors #418
base: main
Are you sure you want to change the base?
Conversation
When building for a web target, there is no stderr. However, the abort implementation in the current CXXABI runtime is implemented with writes to stderr. Since the constructors for default objects call abort, these are rightfully not optimised out from the compiler. However, it is hardly sensible in my opinion to have to include a whole WASI runtime implementation in the browser just to handle more informative aborts by default. To prevent this, compile the cxxabi runtime with NDEBUG and CXXABI_BAREMETAL flags. This is not enough though, as the compiler will still try to instantiate __libcpp_verbose_abort from the stdcxx library. To prevent the compiler from instantiating __libcpp_verbose_abort, clean fix for this is to consistently set _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT=0 in the __availability header. This requires forking or patching LLVM.
@@ -185,6 +185,7 @@ build/compiler-rt.BUILT: build/llvm.BUILT | |||
# $(3): the name of the target being built for | |||
# $(4): extra compiler flags to pass | |||
LIBCXX_CMAKE_FLAGS = \ | |||
-DNDEBUG=1 \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is -DCMAKE_BUILD_TYPE=RelWithDebInfo
below not enough to get this defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, from further inspection it looks like it. This flag isn't piped through to make
. See the thread for why I included it in the first place.
Can you perhaps mention in the title and/or description that this change relates specifically the libc++abi? (Perhaps prefix the title with |
And just to clarify: this PR does not fully solve #401 because of |
This is the patch that needs to be applied to llvm to be able to run stdlib code bare metal in the browser. This alone is sufficient to fix #401 - at least for C++.
For me it looks like setting I noticed from Regarding A full solution would need to both compile |
@@ -205,7 +206,8 @@ LIBCXX_CMAKE_FLAGS = \ | |||
-DLIBCXX_ENABLE_SHARED:BOOL=$(2) \ | |||
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL=OFF \ | |||
-DLIBCXX_ENABLE_EXCEPTIONS:BOOL=OFF \ | |||
-DLIBCXX_ENABLE_FILESYSTEM:BOOL=ON \ | |||
-DLIBCXX_ENABLE_FILESYSTEM:BOOL=OFF \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
does this disable the following message?
while i agree a library should not use stderr in general, |
answering myself, it's easy for apps to override "abort_message". extern "C" void abort_message(const char *fmt, ...)
{
} isn't it enough for your purpose? |
When building for a web target, there is no stderr. However, the abort implementation in the current CXXABI runtime is implemented with writes to stderr.
Since the constructors for default objects call abort, these are rightfully not optimised out from the compiler. However, it is hardly sensible in my opinion to have to include a whole WASI runtime implementation in the browser just to handle more informative aborts by default.
To prevent this, compile the cxxabi runtime with
NDEBUG
andCXXABI_BAREMETAL
flags.This is not enough though, as the compiler will still try to instantiate
__libcpp_verbose_abort
from the stdcxx library. To prevent the compiler from instantiating__libcpp_verbose_abort
, clean fix for this is to consistently set_LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT=0
in the__availability
header. This requires forking or patching LLVM.