Bug 93208 - duplicated memory_resource, monotomic_buffer_resource vtable, type_info d/t all-inline virtual functions
Summary: duplicated memory_resource, monotomic_buffer_resource vtable, type_info d/t a...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 9.1.0
: P3 normal
Target Milestone: 9.3
Assignee: Jonathan Wakely
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-09 08:45 UTC by Marc Mutz
Modified: 2020-01-09 14:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-01-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Mutz 2020-01-09 08:45:23 UTC
Both `memory_resource` and `monotonic_buffer_resource` have all virtual methods inline, so their vtables (and rtti) are not pinned to libstdc++.so, but are duplicated in each executable (.so or application), causing minor executable code bloat and false negative dynamic_casts.

Expected: At least their dtor should be out-of-line, so the vtable and the type_info object are emitted in libstdc++.so, and only there.
Comment 1 Marc Mutz 2020-01-09 08:49:32 UTC
Also in 9.1, according to gotbolt.org. Making the dtors out-of-line should be a binary-compatible.
Comment 2 Jonathan Wakely 2020-01-09 09:57:15 UTC
(In reply to Marc Mutz from comment #0)
> false negative dynamic_casts.

That shouldn't happen on sane platforms.

(In reply to Marc Mutz from comment #1)
> Also in 9.1, according to gotbolt.org. Making the dtors out-of-line should
> be a binary-compatible.

We've already bumped the library version to libstdc++.so.6.0.26 for the GCC 9.3 release, so we could add another symbol to it now. That could cause problems for distros already shipping 9.2.1 snapshots though.

It would be safer to only change it on trunk.
Comment 3 Jonathan Wakely 2020-01-09 09:57:57 UTC
(In reply to Jonathan Wakely from comment #2)
> We've already bumped the library version to libstdc++.so.6.0.26 

Typo! That should be libstdc++.so.6.0.27
Comment 4 Jonathan Wakely 2020-01-09 13:18:51 UTC
Author: redi
Date: Thu Jan  9 13:18:20 2020
New Revision: 280044

URL: https://gcc.gnu.org/viewcvs?rev=280044&root=gcc&view=rev
Log:
libstdc++: Define memory resource key functions non-inline (PR93208)

This prevents the vtables and RTTI from being emitted in every object
file that uses memory_resource and monotonic_buffer_resource.

Objects compiled by GCC 9.1 or 9.2 will contain inline definitions of
the destructors, vtable and RTTI, but this is harmless. The inline
definitions have identical effects to the ones that are now defined in
libstdc++.so so it doesn't matter if the inline ones are used instead of
calling the symbols exported from the runtime library.

	PR libstdc++/93208
	* config/abi/pre/gnu.ver: Add new exports.
	* include/std/memory_resource (memory_resource::~memory_resource()):
	Do not define inline.
	(monotonic_buffer_resource::~monotonic_buffer_resource()): Likewise.
	* src/c++17/memory_resource.cc (memory_resource::~memory_resource()):
	Define.
	(monotonic_buffer_resource::~monotonic_buffer_resource()): Define.
	* testsuite/20_util/monotonic_buffer_resource/93208.cc: New test.

Added:
    trunk/libstdc++-v3/testsuite/20_util/monotonic_buffer_resource/93208.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/config/abi/pre/gnu.ver
    trunk/libstdc++-v3/include/std/memory_resource
    trunk/libstdc++-v3/src/c++17/memory_resource.cc
Comment 5 Jonathan Wakely 2020-01-09 13:19:08 UTC
Author: redi
Date: Thu Jan  9 13:18:37 2020
New Revision: 280045

URL: https://gcc.gnu.org/viewcvs?rev=280045&root=gcc&view=rev
Log:
libstdc++: Define memory resource key functions non-inline (PR93208)

This prevents the vtables and RTTI from being emitted in every object
file that uses memory_resource and monotonic_buffer_resource.

Objects compiled by GCC 9.1 or 9.2 will contain inline definitions of
the destructors, vtable and RTTI, but this is harmless. The inline
definitions have identical effects to the ones that are now defined in
libstdc++.so so it doesn't matter if the inline ones are used instead of
calling the symbols exported from the runtime library.

	PR libstdc++/93208
	* config/abi/pre/gnu.ver: Add new exports.
	* include/std/memory_resource (memory_resource::~memory_resource()):
	Do not define inline.
	(monotonic_buffer_resource::~monotonic_buffer_resource()): Likewise.
	* src/c++17/memory_resource.cc (memory_resource::~memory_resource()):
	Define.
	(monotonic_buffer_resource::~monotonic_buffer_resource()): Define.
	* testsuite/20_util/monotonic_buffer_resource/93208.cc: New test.

Added:
    branches/gcc-9-branch/libstdc++-v3/testsuite/20_util/monotonic_buffer_resource/93208.cc
Modified:
    branches/gcc-9-branch/libstdc++-v3/ChangeLog
    branches/gcc-9-branch/libstdc++-v3/config/abi/pre/gnu.ver
    branches/gcc-9-branch/libstdc++-v3/include/std/memory_resource
    branches/gcc-9-branch/libstdc++-v3/src/c++17/memory_resource.cc
Comment 6 Jonathan Wakely 2020-01-09 13:48:46 UTC
Fixed for 9.3
Comment 7 Marc Mutz 2020-01-09 14:21:52 UTC
Thanks!