Page MenuHomePhabricator

[libcxx] Don't define exception types with -fno-exceptions
Needs RevisionPublic

Authored by phosek on Jul 26 2021, 10:13 PM.

Details

Reviewers
ldionne
mstorsjo
Group Reviewers
Restricted Project
Restricted Project
Summary

When exceptions are disabled, that is when _HAS_EXCEPTIONS=0, the
vcruntime_exception.h header doesn't define the ABI base class
std::exception which breaks the libc++ build.

This change ifdefs out all subclass of exception/error to avoid
this issue. This can be also beneficial on other platforms that
disable exceptions because we don't need to distribute code that's
never going to be used.

For example, on Fuchsia, we ship both variants of libc++ (with and
without exceptions) and select the correct one using the multilib
mechanism. Since the first party code doesn't use exceptions, this
can reduce binary size and this change can help further in addition
to making libc++ usable on Windows with _HAC_EXCEPTIONS=0.

Diff Detail

Unit TestsFailed

TimeTest
1,950 mslibcxx CI -fno-exceptions > libc++.libcxx/input_output/filesystems/class_directory_entry/directory_entry_mods::last_write_time.pass.cpp
Script: -- : 'COMPILED WITH'; /usr/bin/c++ /home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/libcxx/input.output/filesystems/class.directory_entry/directory_entry.mods/last_write_time.pass.cpp -v --target=x86_64-unknown-linux-gnu -include /home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/include/c++/v1 -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/support -std=c++2b -fno-exceptions -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1 -I /home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/libcxx/input.output/filesystems/class.directory_entry/directory_entry.mods/../../../../../../src/filesystem -lc++experimental -L/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/./lib -L/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/./lib -Wl,-rpath,/home/libcxx-builder/.
2,190 mslibcxx CI -fno-exceptions > libc++.libcxx/input_output/filesystems/class_path/path_member/path_native_obs::string_alloc.pass.cpp
Script: -- : 'COMPILED WITH'; /usr/bin/c++ /home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/libcxx/input.output/filesystems/class.path/path.member/path.native.obs/string_alloc.pass.cpp -v --target=x86_64-unknown-linux-gnu -include /home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/include/c++/v1 -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/support -std=c++2b -fno-exceptions -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1 -lc++experimental -L/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/./lib -L/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/./lib -nodefaultlibs -lc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc -latomic -o /home/libcxx-builder/.buildkite…
1,750 mslibcxx CI -fno-exceptions > libc++.std/concepts/concepts_object::regular.compile.pass.cpp
Script: -- : 'COMPILED WITH'; /usr/bin/c++ /home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/std/concepts/concepts.object/regular.compile.pass.cpp -v --target=x86_64-unknown-linux-gnu -include /home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/include/c++/v1 -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/support -std=c++2b -fno-exceptions -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1 -fsyntax-only
1,730 mslibcxx CI -fno-exceptions > libc++.std/concepts/concepts_object::semiregular.compile.pass.cpp
Script: -- : 'COMPILED WITH'; /usr/bin/c++ /home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/std/concepts/concepts.object/semiregular.compile.pass.cpp -v --target=x86_64-unknown-linux-gnu -include /home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/include/c++/v1 -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/support -std=c++2b -fno-exceptions -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1 -fsyntax-only
1,200 mslibcxx CI -fno-exceptions > libc++.std/diagnostics/std_exceptions/domain_error::domain_error.pass.cpp
Script: -- : 'COMPILED WITH'; /usr/bin/c++ /home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/std/diagnostics/std.exceptions/domain.error/domain_error.pass.cpp -v --target=x86_64-unknown-linux-gnu -include /home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/include/c++/v1 -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/libcxx/test/support -std=c++2b -fno-exceptions -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1 -lc++experimental -L/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/./lib -L/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm-project/libcxx-ci/build/generic-noexceptions/./lib -nodefaultlibs -lc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc -latomic -o /home/libcxx-builder/.buildkite-agent/builds/5a05a36815ae-1/llvm…
View Full Test Results (504 Failed)

Event Timeline

phosek requested review of this revision.Jul 26 2021, 10:13 PM
phosek created this revision.
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 26 2021, 10:13 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript

This is an alternative to D103947.

phosek updated this revision to Diff 361909.Jul 26 2021, 10:28 PM
ldionne requested changes to this revision.Jul 27 2021, 7:29 AM

I would like to avoid providing a different API for when exceptions are enabled vs disabled.

Do you guys know what the rationale is for the VC runtime not to provide std::exception? I think we should try to align with them. My ideal resolution would simply be that the VC runtime provides the std::exception class even when -fno-exceptions is used, since that's what all other platforms do.

This revision now requires changes to proceed.Jul 27 2021, 7:29 AM

I would like to avoid providing a different API for when exceptions are enabled vs disabled.

Do you guys know what the rationale is for the VC runtime not to provide std::exception? I think we should try to align with them. My ideal resolution would simply be that the VC runtime provides the std::exception class even when -fno-exceptions is used, since that's what all other platforms do.

Would D103947 be a more acceptable solution? I don't know why VC runtime doesn't provide std::exception but even if we can convince Microsoft to change their approach, it's going to take years for that change to roll out so that strategy is not feasible for us since we would like to start using libc++ on Windows now.

I would like to avoid providing a different API for when exceptions are enabled vs disabled.

Do you guys know what the rationale is for the VC runtime not to provide std::exception? I think we should try to align with them. My ideal resolution would simply be that the VC runtime provides the std::exception class even when -fno-exceptions is used, since that's what all other platforms do.

Would D103947 be a more acceptable solution? I don't know why VC runtime doesn't provide std::exception but even if we can convince Microsoft to change their approach, it's going to take years for that change to roll out so that strategy is not feasible for us since we would like to start using libc++ on Windows now.

Yeah, my initial reaction is that D103947 is more in line with what we do in libc++ on other platforms, so we should go with that (after addressing some issues with that patch). But let's keep discussing on D103947 -- I have little context on Windows so I might be asking for silly things without knowing.