[libc++] Resolve missing table_size symbol

The aim of this patch is to resolve the missing `table_size` symbol (see reduced test case). That const variable is declared and defined in //libcxx/include/locale//; however, the test case suggests that the symbol is missing. This is due to a C++ pitfall (highlighted [[ https://quuxplusone.github.io/blog/2020/09/19/value-or-pitfall/ | here ]]). In summary, assigning the reference of `table_size` doesn't enforce the const-ness and expects to find `table_size` in the DLL. The fix is to use `constexpr` or have an out-of-line definition in the src (for consistency).

Differential Revision: https://reviews.llvm.org/D110647
This commit is contained in:
Muiez Ahmed 2021-11-18 15:49:45 -05:00
parent 46c26991ae
commit 049f6c29a6
6 changed files with 51 additions and 0 deletions

View File

@ -16,6 +16,21 @@ New entries should be added directly below the "Version" header.
Version 14.0
------------
* [libc++] Resolve missing table_size symbol
This commit added an out-of-line definition for `table_size` in the library.
This is not an ABI break since we are just adding a symbol to the library.
In fact, any program that would have attempted to refer to that symbol would
have previously failed to link.
x86_64-apple-apple-darwin
-------------------------
Symbol added: _ZNSt3__15ctypeIcE10table_sizeE
x86_64-unknown-linux-gnu
------------------------
Symbol added: _ZNSt3__15ctypeIcE10table_sizeE
* [libc++] Always define a key function for std::bad_function_call in the dylib
This commit added a new explicit instantiation of std::bad_function_call's

View File

@ -1646,6 +1646,7 @@
{'is_defined': True, 'name': '__ZNSt3__14stolERKNS_12basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEEEPmi', 'type': 'FUNC'}
{'is_defined': True, 'name': '__ZNSt3__14wcinE', 'size': 0, 'type': 'OBJECT'}
{'is_defined': True, 'name': '__ZNSt3__15alignEmmRPvRm', 'type': 'FUNC'}
{'is_defined': True, 'name': '__ZNSt3__15ctypeIcE10table_sizeE', 'size': 0, 'type': 'OBJECT'}
{'is_defined': True, 'name': '__ZNSt3__15ctypeIcE13classic_tableEv', 'type': 'FUNC'}
{'is_defined': True, 'name': '__ZNSt3__15ctypeIcE2idE', 'size': 0, 'type': 'OBJECT'}
{'is_defined': True, 'name': '__ZNSt3__15ctypeIcEC1EPKjbm', 'type': 'FUNC'}

View File

@ -1646,6 +1646,7 @@
{'is_defined': True, 'name': '__ZNSt3__14stolERKNS_12basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEEEPmi', 'type': 'FUNC'}
{'is_defined': True, 'name': '__ZNSt3__14wcinE', 'size': 0, 'type': 'OBJECT'}
{'is_defined': True, 'name': '__ZNSt3__15alignEmmRPvRm', 'type': 'FUNC'}
{'is_defined': True, 'name': '__ZNSt3__15ctypeIcE10table_sizeE', 'size': 0, 'type': 'OBJECT'}
{'is_defined': True, 'name': '__ZNSt3__15ctypeIcE13classic_tableEv', 'type': 'FUNC'}
{'is_defined': True, 'name': '__ZNSt3__15ctypeIcE2idE', 'size': 0, 'type': 'OBJECT'}
{'is_defined': True, 'name': '__ZNSt3__15ctypeIcEC1EPKjbm', 'type': 'FUNC'}

View File

@ -1337,6 +1337,7 @@
{'is_defined': True, 'name': '_ZNSt3__14stolERKNS_12basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEEEPmi', 'type': 'FUNC'}
{'is_defined': True, 'name': '_ZNSt3__14wcinE', 'size': 168, 'type': 'OBJECT'}
{'is_defined': True, 'name': '_ZNSt3__15alignEmmRPvRm', 'type': 'FUNC'}
{'is_defined': True, 'name': '_ZNSt3__15ctypeIcE10table_sizeE', 'size': 8, 'type': 'OBJECT'}
{'is_defined': True, 'name': '_ZNSt3__15ctypeIcE13classic_tableEv', 'type': 'FUNC'}
{'is_defined': True, 'name': '_ZNSt3__15ctypeIcE21__classic_lower_tableEv', 'type': 'FUNC'}
{'is_defined': True, 'name': '_ZNSt3__15ctypeIcE21__classic_upper_tableEv', 'type': 'FUNC'}

View File

@ -988,6 +988,8 @@ ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfau
locale::id ctype<char>::id;
const size_t ctype<char>::table_size;
ctype<char>::ctype(const mask* tab, bool del, size_t refs)
: locale::facet(refs),
__tab_(tab),

View File

@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <locale>
// template <> class ctype<char>
// Make sure we can reference std::ctype<char>::table_size.
// Before https://llvm.org/D110647, the shared library did not contain
// std::ctype<char>::table_size, so this test fails with a link error.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14|15}}
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx{{11|12|13}}
#include <locale>
#include <cassert>
#include "test_macros.h"
int main(int, char**) {
typedef std::ctype<char> F;
const size_t* G = &F::table_size;
assert(*G >= 256);
return 0;
}