[llvm-bugs] [Bug 48360] New: Lack of visibility specification on forward declaration of class template may hide derived symbols
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Dec 2 05:27:41 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=48360
Bug ID: 48360
Summary: Lack of visibility specification on forward
declaration of class template may hide derived symbols
Product: clang
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: predelnik at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Take a look at the following program
#include <any>
template <typename T>
class PublicTemplateClass;
class [[gnu::visibility("default")]] D {};
class E
{
PublicTemplateClass<D> f ();
};
template <typename T>
class [[gnu::visibility("default")]] PublicTemplateClass
{
};
PublicTemplateClass<D> E::f ()
{
PublicTemplateClass<D> v;
std::any a (v);
return v;
}
Running the following command:
clang++ -fvisibility=hidden -std=c++17 -shared -fPIC a.cpp && readelf -s a.out
| grep Manager
I see the following output:
15: 0000000000001c70 39 FUNC LOCAL HIDDEN 12
_ZNSt3any17_Manager_inter
16: 0000000000001b90 178 FUNC LOCAL HIDDEN 12
_ZNSt3any17_Manager_inter
Manager...thingie is basically a function pointer which is compared in any_cast
in libstdc++. So the problem is that when it's hidden any_cast to correct type
will fail because user of the library will have different pointer to this
function.
If however I add [[gnu::visibility("default")]] to forward declaration of
PublicTemplateClass like this:
template <typename T>
class [[gnu::visibility("default")]] PublicTemplateClass;
I receive the following:
10: 0000000000001ef0 178 FUNC WEAK DEFAULT 12
_ZNSt3any17_Manager_inter
13: 0000000000001fd0 39 FUNC WEAK DEFAULT 12
_ZNSt3any17_Manager_inter
28: 0000000000001fd0 39 FUNC WEAK DEFAULT 12
_ZNSt3any17_Manager_inter
29: 0000000000001ef0 178 FUNC WEAK DEFAULT 12
_ZNSt3any17_Manager_inter
I'm not 100% sure that this is not intended behavior but this seems to be very
unfortunate because:
1. Error is very subtle, hard to find, runtime only &c.
2. gcc does not behave like this
3. Normal classes do not seem to trigger such behavior with requiring
visibility specification for forward declarations.
If you need me to built full fledged example where executable + so lib fail to
perform any cast in such case I would be happy to provide that but I hope the
problem is already clear from this short sample.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201202/48271f99/attachment.html>
More information about the llvm-bugs
mailing list