gcc/libstdc++-v3/include/ext
Jonathan Wakely da29d2a36e PR libstdc++/67843 set shared_ptr lock policy at build-time
This resolves a longstanding issue where the lock policy for shared_ptr
reference counting depends on compilation options when the header is
included, so that different -march options can cause ABI changes. For
example, objects compiled with -march=armv7 will use atomics to
synchronize reference counts, and objects compiled with -march=armv5t
will use a mutex. That means the shared_ptr control block will have a
different layout in different objects, causing ODR violations and
undefined behaviour. This was the root cause of PR libstdc++/42734 as
well as PR libstdc++/67843.

The solution is to decide on the lock policy at build time, when
libstdc++ is configured. The configure script checks for the
availability of the necessary atomic built-ins for the target and fixes
that choice permanently. Different -march flags used to compile user
code will not cause changes to the lock policy. This results in an ABI
change for certain compilations, but only where there was already an ABI
incompatibility between the libstdc++.so library and objects built with
an incompatible -march option. In general, this means a more stable ABI
that isn't silently altered when -march flags make addition atomic ops
available.

To force a target to use "atomic" or "mutex" the new configure option
--with-libstdcxx-lock-policy can be used.

In order to turn ODR violations into linker errors, the uses of
shared_ptr in filesystem directory iterators have been replaced
with __shared_ptr, and explicit instantiations are declared. This
ensures that object files using those types cannot link to libstdc++
libs unless they use the same lock policy.

	PR libstdc++/67843
	* acinclude.m4 (GLIBCXX_ENABLE_LOCK_POLICY): Add new macro
	that defines _GLIBCXX_HAVE_ATOMIC_LOCK_POLICY.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Use GLIBCXX_ENABLE_LOCK_POLICY.
	* doc/xml/manual/configure.xml: Document new configure option.
	* include/bits/fs_dir.h (directory_iterator): Use __shared_ptr
	instead of shared_ptr.
	(recursive_directory_iterator): Likewise.
	(__shared_ptr<_Dir>): Add explicit instantiation declaration.
	(__shared_ptr<recursive_directory_iterator::_Dir_stack>): Likewise.
	* include/bits/shared_ptr_base.h (__allocate_shared, __make_shared):
	Add default template argument for _Lock_policy template parameter.
	* include/ext/concurrence.h (__default_lock_policy): Check macro
	_GLIBCXX_HAVE_ATOMIC_LOCK_POLICY instead of checking if the current
	target supports the builtins for compare-and-swap.
	* src/filesystem/std-dir.cc (__shared_ptr<_Dir>): Add explicit
	instantiation definition.
	(__shared_ptr<recursive_directory_iterator::_Dir_stack>): Likewise.
	(directory_iterator, recursive_directory_iterator): Use __make_shared
	instead of make_shared.

From-SVN: r266533
2018-11-27 23:25:56 +00:00
..
pb_ds Update copyright years. 2018-01-03 11:03:58 +01:00
algorithm Update copyright years. 2018-01-03 11:03:58 +01:00
aligned_buffer.h aligned_buffer.h [...] (template<> __aligned_buffer): Define as __aligned_membuf alias. 2018-02-20 20:51:44 +00:00
alloc_traits.h Relocation (= move+destroy) 2018-10-25 13:03:13 +00:00
array_allocator.h Update copyright years. 2018-01-03 11:03:58 +01:00
atomicity.h Update copyright years. 2018-01-03 11:03:58 +01:00
bitmap_allocator.h Update copyright years. 2018-01-03 11:03:58 +01:00
cast.h Update copyright years. 2018-01-03 11:03:58 +01:00
cmath Update copyright years. 2018-01-03 11:03:58 +01:00
codecvt_specializations.h Update copyright years. 2018-01-03 11:03:58 +01:00
concurrence.h PR libstdc++/67843 set shared_ptr lock policy at build-time 2018-11-27 23:25:56 +00:00
debug_allocator.h Make ext allocators support heterogeneous equality comparison 2018-10-11 12:32:29 +01:00
enc_filebuf.h Update copyright years. 2018-01-03 11:03:58 +01:00
extptr_allocator.h Update copyright years. 2018-01-03 11:03:58 +01:00
functional Update copyright years. 2018-01-03 11:03:58 +01:00
iterator Update copyright years. 2018-01-03 11:03:58 +01:00
malloc_allocator.h Relocation (= move+destroy) 2018-10-25 13:03:13 +00:00
memory 2018-06-05 François Dumont <fdumont@gcc.gnu.org> 2018-06-05 05:47:44 +00:00
mt_allocator.h Update copyright years. 2018-01-03 11:03:58 +01:00
new_allocator.h Relocation (= move+destroy) 2018-10-25 13:03:13 +00:00
numeric Update copyright years. 2018-01-03 11:03:58 +01:00
numeric_traits.h Update copyright years. 2018-01-03 11:03:58 +01:00
pod_char_traits.h Update copyright years. 2018-01-03 11:03:58 +01:00
pointer.h Fix __gnu_cxx::_Pointer_adapter for long long arithmetic 2018-08-30 13:24:06 +01:00
pool_allocator.h Update copyright years. 2018-01-03 11:03:58 +01:00
random P0935R0 Eradicating unnecessarily explicit default constructors 2018-06-14 14:32:53 +01:00
random.tcc PR libstdc++/85749 constrain seed sequences for random number engines 2018-05-15 16:36:46 +01:00
rb_tree Update copyright years. 2018-01-03 11:03:58 +01:00
rc_string_base.h Update copyright years. 2018-01-03 11:03:58 +01:00
rope Rope iterators: don't retain pointers when copied 2018-08-14 12:23:50 +01:00
ropeimpl.h Update copyright years. 2018-01-03 11:03:58 +01:00
slist Update copyright years. 2018-01-03 11:03:58 +01:00
sso_string_base.h Update copyright years. 2018-01-03 11:03:58 +01:00
stdio_filebuf.h Update copyright years. 2018-01-03 11:03:58 +01:00
stdio_sync_filebuf.h Update copyright years. 2018-01-03 11:03:58 +01:00
string_conversions.h Update copyright years. 2018-01-03 11:03:58 +01:00
throw_allocator.h 2018-11-19 François Dumont <fdumont@gcc.gnu.org> 2018-11-19 21:02:17 +00:00
type_traits.h Update copyright years. 2018-01-03 11:03:58 +01:00
typelist.h Update copyright years. 2018-01-03 11:03:58 +01:00
vstring.h Remove char16_t and char32_t dependency on <stdint.h> 2018-07-26 15:02:01 +01:00
vstring.tcc Update copyright years. 2018-01-03 11:03:58 +01:00
vstring_fwd.h Remove char16_t and char32_t dependency on <stdint.h> 2018-07-26 15:02:01 +01:00
vstring_util.h Update copyright years. 2018-01-03 11:03:58 +01:00