Author: smeenai Date: Tue Mar 28 14:33:31 2017 New Revision: 298937 URL: http://llvm.org/viewvc/llvm-project?rev=298937&view=rev Log: [libc++] Add a key function for bad_function_call
Summary: bad_function_call is currently an empty class, so any object files using that class will end up with their own copy of its typeinfo, typeinfo name and vtable, leading to unnecessary duplication that has to be resolved by the dynamic linker. Instead, give bad_function_call a key function and put a definition for that key function in libc++ itself, to centralize the typeinfo and vtable. This is consistent with the behavior for other exception classes. The key functions are defined in libc++ rather than libc++abi since the class is defined in the libc++ versioning namespace, so ABI compatibility with libstdc++ is not a concern. Guard this change behind an ABI macro, since it isn't backwards compatible (i.e., clients built against the new libc++ headers wouldn't be able to run against an older libc++ library). Reviewers: mclow.lists, EricWF Subscribers: mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D27387 Added: libcxx/trunk/src/functional.cpp Modified: libcxx/trunk/include/__config libcxx/trunk/include/functional libcxx/trunk/lib/CMakeLists.txt Modified: libcxx/trunk/include/__config URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=298937&r1=298936&r2=298937&view=diff ============================================================================== --- libcxx/trunk/include/__config (original) +++ libcxx/trunk/include/__config Tue Mar 28 14:33:31 2017 @@ -58,6 +58,10 @@ // `pointer_safety` and `get_pointer_safety()` will no longer be available // in C++03. #define _LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE +// Define a key function for `bad_function_call` in the library, to centralize +// its vtable and typeinfo to libc++ rather than having all other libraries +// using that class define their own copies. +#define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION #elif _LIBCPP_ABI_VERSION == 1 #if !defined(_WIN32) // Enable compiling copies of now inline methods into the dylib to support Modified: libcxx/trunk/include/functional URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/functional?rev=298937&r1=298936&r2=298937&view=diff ============================================================================== --- libcxx/trunk/include/functional (original) +++ libcxx/trunk/include/functional Tue Mar 28 14:33:31 2017 @@ -1389,6 +1389,12 @@ mem_fn(_Rp _Tp::* __pm) _NOEXCEPT class _LIBCPP_EXCEPTION_ABI bad_function_call : public exception { +#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION +public: + virtual ~bad_function_call() _NOEXCEPT; + + virtual const char* what() const _NOEXCEPT; +#endif }; _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE Modified: libcxx/trunk/lib/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/CMakeLists.txt?rev=298937&r1=298936&r2=298937&view=diff ============================================================================== --- libcxx/trunk/lib/CMakeLists.txt (original) +++ libcxx/trunk/lib/CMakeLists.txt Tue Mar 28 14:33:31 2017 @@ -177,7 +177,7 @@ endif() split_list(LIBCXX_COMPILE_FLAGS) split_list(LIBCXX_LINK_FLAGS) -# Add a object library that contains the compiled source files. +# Add an object library that contains the compiled source files. add_library(cxx_objects OBJECT ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) if(WIN32 AND NOT MINGW) target_compile_definitions(cxx_objects Added: libcxx/trunk/src/functional.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/functional.cpp?rev=298937&view=auto ============================================================================== --- libcxx/trunk/src/functional.cpp (added) +++ libcxx/trunk/src/functional.cpp Tue Mar 28 14:33:31 2017 @@ -0,0 +1,26 @@ +//===----------------------- functional.cpp -------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "functional" + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION +bad_function_call::~bad_function_call() _NOEXCEPT +{ +} + +const char* +bad_function_call::what() const _NOEXCEPT +{ + return "std::bad_function_call"; +} +#endif + +_LIBCPP_END_NAMESPACE_STD _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits