Skip to content

Commit 6441347

Browse files
authored
[libc++] Simplify the implementation of locale::id (llvm#65781)
Since we use C++20 to build the dylib, we can use a lambda to do the first-time initialization instead of emulating std::bind. This should not change the behavior of the code at all, it merely simplifies it. This removes a symbol from the dylib, however that symbol was only ever used inside the dylib so it shouldn't break the ABI for anyone. I confirmed that by searching for that symbol on the ABI boundary of a large number of programs and couldn't find any references to that function.
1 parent 131ba0a commit 6441347

10 files changed

+14
-39
lines changed

libcxx/include/__locale

-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ public:
163163
void operator=(const id&) = delete;
164164
id(const id&) = delete;
165165

166-
private:
167-
void __init();
168166
public: // only needed for tests
169167
long __get();
170168

libcxx/lib/abi/CHANGELOG.TXT

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ New entries should be added directly below the "Version" header.
1616
Version 18.0
1717
------------
1818

19+
* [libc++] Simplify the implementation of locale::id
20+
21+
This patch removes a symbol defined in the library for std::locale::id::__init().
22+
The symbol '__init' was defined as a private static function as part of the locale::id
23+
class and was never visible from outside the dylib. The addition of this symbol to the
24+
ABI was most likely accidental. The deletion of the symbol should not be a breaking change.
25+
26+
All platforms
27+
-------------
28+
Symbol removed: _ZNSt3__16locale2id6__initEv
29+
1930
* [libc++] Remove symbol for std::system_error from the dylib
2031

2132
This patch removes a symbol defined in the library for std::system_error.
@@ -27,7 +38,7 @@ Version 18.0
2738
this was never used outside of the dylib.
2839
The deletion of the symbol should not be a breaking change.
2940

30-
All platforms
41+
All platforms
3142
-------------
3243
Symbol removed: _ZNSt3__112system_error6__initERKNS_10error_codeENS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE
3344

libcxx/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist

-1
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,6 @@
16771677
{'is_defined': True, 'name': '__ZNSt3__16gslice6__initEm', 'type': 'FUNC'}
16781678
{'is_defined': True, 'name': '__ZNSt3__16locale14__install_ctorERKS0_PNS0_5facetEl', 'type': 'FUNC'}
16791679
{'is_defined': True, 'name': '__ZNSt3__16locale2id5__getEv', 'type': 'FUNC'}
1680-
{'is_defined': True, 'name': '__ZNSt3__16locale2id6__initEv', 'type': 'FUNC'}
16811680
{'is_defined': True, 'name': '__ZNSt3__16locale2id9__next_idE', 'size': 0, 'type': 'OBJECT'}
16821681
{'is_defined': True, 'name': '__ZNSt3__16locale3allE', 'size': 0, 'type': 'OBJECT'}
16831682
{'is_defined': True, 'name': '__ZNSt3__16locale4noneE', 'size': 0, 'type': 'OBJECT'}

libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist

-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,6 @@
693693
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16gslice6__initEm', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
694694
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16locale14__install_ctorERKS0_PNS0_5facetEl', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
695695
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16locale2id5__getEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
696-
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16locale2id6__initEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
697696
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16locale2id9__next_idE', 'storage_mapping_class': 'RW', 'type': 'OBJECT'}
698697
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16locale3allE', 'storage_mapping_class': 'RO', 'type': 'OBJECT'}
699698
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16locale4noneE', 'storage_mapping_class': 'RO', 'type': 'OBJECT'}

libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist

-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,6 @@
693693
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16gslice6__initEm', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
694694
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16locale14__install_ctorERKS0_PNS0_5facetEl', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
695695
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16locale2id5__getEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
696-
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16locale2id6__initEv', 'storage_mapping_class': 'DS', 'type': 'FUNC'}
697696
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16locale2id9__next_idE', 'storage_mapping_class': 'RW', 'type': 'OBJECT'}
698697
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16locale3allE', 'storage_mapping_class': 'RO', 'type': 'OBJECT'}
699698
{'import_export': 'EXP', 'is_defined': True, 'name': '_ZNSt3__16locale4noneE', 'storage_mapping_class': 'RO', 'type': 'OBJECT'}

libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist

-1
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,6 @@
16771677
{'is_defined': True, 'name': '__ZNSt3__16gslice6__initEm', 'type': 'FUNC'}
16781678
{'is_defined': True, 'name': '__ZNSt3__16locale14__install_ctorERKS0_PNS0_5facetEl', 'type': 'FUNC'}
16791679
{'is_defined': True, 'name': '__ZNSt3__16locale2id5__getEv', 'type': 'FUNC'}
1680-
{'is_defined': True, 'name': '__ZNSt3__16locale2id6__initEv', 'type': 'FUNC'}
16811680
{'is_defined': True, 'name': '__ZNSt3__16locale2id9__next_idE', 'size': 0, 'type': 'OBJECT'}
16821681
{'is_defined': True, 'name': '__ZNSt3__16locale3allE', 'size': 0, 'type': 'OBJECT'}
16831682
{'is_defined': True, 'name': '__ZNSt3__16locale4noneE', 'size': 0, 'type': 'OBJECT'}

libcxx/lib/abi/x86_64-unknown-freebsd.libcxxabi.v1.stable.exceptions.nonew.abilist

-1
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,6 @@
13721372
{'is_defined': True, 'name': '_ZNSt3__16gslice6__initEm', 'type': 'FUNC'}
13731373
{'is_defined': True, 'name': '_ZNSt3__16locale14__install_ctorERKS0_PNS0_5facetEl', 'type': 'FUNC'}
13741374
{'is_defined': True, 'name': '_ZNSt3__16locale2id5__getEv', 'type': 'FUNC'}
1375-
{'is_defined': True, 'name': '_ZNSt3__16locale2id6__initEv', 'type': 'FUNC'}
13761375
{'is_defined': True, 'name': '_ZNSt3__16locale2id9__next_idE', 'size': 4, 'type': 'OBJECT'}
13771376
{'is_defined': True, 'name': '_ZNSt3__16locale3allE', 'size': 4, 'type': 'OBJECT'}
13781377
{'is_defined': True, 'name': '_ZNSt3__16locale4noneE', 'size': 4, 'type': 'OBJECT'}

libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist

-1
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,6 @@
13731373
{'is_defined': True, 'name': '_ZNSt3__16gslice6__initEm', 'type': 'FUNC'}
13741374
{'is_defined': True, 'name': '_ZNSt3__16locale14__install_ctorERKS0_PNS0_5facetEl', 'type': 'FUNC'}
13751375
{'is_defined': True, 'name': '_ZNSt3__16locale2id5__getEv', 'type': 'FUNC'}
1376-
{'is_defined': True, 'name': '_ZNSt3__16locale2id6__initEv', 'type': 'FUNC'}
13771376
{'is_defined': True, 'name': '_ZNSt3__16locale2id9__next_idE', 'size': 4, 'type': 'OBJECT'}
13781377
{'is_defined': True, 'name': '_ZNSt3__16locale3allE', 'size': 4, 'type': 'OBJECT'}
13791378
{'is_defined': True, 'name': '_ZNSt3__16locale4noneE', 'size': 4, 'type': 'OBJECT'}

libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.noexceptions.nonew.abilist

-1
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,6 @@
13451345
{'is_defined': True, 'name': '_ZNSt3__16gslice6__initEm', 'type': 'FUNC'}
13461346
{'is_defined': True, 'name': '_ZNSt3__16locale14__install_ctorERKS0_PNS0_5facetEl', 'type': 'FUNC'}
13471347
{'is_defined': True, 'name': '_ZNSt3__16locale2id5__getEv', 'type': 'FUNC'}
1348-
{'is_defined': True, 'name': '_ZNSt3__16locale2id6__initEv', 'type': 'FUNC'}
13491348
{'is_defined': True, 'name': '_ZNSt3__16locale2id9__next_idE', 'size': 4, 'type': 'OBJECT'}
13501349
{'is_defined': True, 'name': '_ZNSt3__16locale3allE', 'size': 4, 'type': 'OBJECT'}
13511350
{'is_defined': True, 'name': '_ZNSt3__16locale4noneE', 'size': 4, 'type': 'OBJECT'}

libcxx/src/locale.cpp

+2-29
Original file line numberDiff line numberDiff line change
@@ -690,38 +690,11 @@ locale::facet::__on_zero_shared() noexcept
690690

691691
constinit int32_t locale::id::__next_id = 0;
692692

693-
namespace
694-
{
695-
696-
class __fake_bind
697-
{
698-
locale::id* id_;
699-
void (locale::id::* pmf_)();
700-
public:
701-
__fake_bind(void (locale::id::* pmf)(), locale::id* id)
702-
: id_(id), pmf_(pmf) {}
703-
704-
void operator()() const
705-
{
706-
(id_->*pmf_)();
707-
}
708-
};
709-
710-
}
711-
712-
long
713-
locale::id::__get()
714-
{
715-
call_once(__flag_, __fake_bind(&locale::id::__init, this));
693+
long locale::id::__get() {
694+
call_once(__flag_, [&] { __id_ = __libcpp_atomic_add(&__next_id, 1); });
716695
return __id_ - 1;
717696
}
718697

719-
void
720-
locale::id::__init()
721-
{
722-
__id_ = __libcpp_atomic_add(&__next_id, 1);
723-
}
724-
725698
// template <> class collate_byname<char>
726699

727700
collate_byname<char>::collate_byname(const char* n, size_t refs)

0 commit comments

Comments
 (0)