public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107535] New: Shouldn't -fvisibility=hidden hide C++17 inline static variables?
@ 2022-11-05 12:38 junchao.zhang at gmail dot com
2022-11-07 7:00 ` [Bug c++/107535] -fvisibility=hidden should not hide C++17 inline static variables rguenth at gcc dot gnu.org
2023-06-15 11:07 ` redi at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: junchao.zhang at gmail dot com @ 2022-11-05 12:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107535
Bug ID: 107535
Summary: Shouldn't -fvisibility=hidden hide C++17 inline static
variables?
Product: gcc
Version: 11.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: junchao.zhang at gmail dot com
Target Milestone: ---
I think inline static variables are global. However, they could be hidden by
-fvisibility=hidden.
This is dangerous, since with C++17 inline static variables, they will appear
in headers and be included in *.cpp files. If the *.cpp files are compiled with
-fvisibility=hidden, each will get their own storage.
$ cat foo.hpp
struct Foo {static inline int s = 100; };
extern __attribute__ ((visibility ("default"))) void DumpLibFoo();
$ cat foo.cpp
#include <stdio.h>
#include <foo.hpp>
void DumpLibFoo() { printf("In libfoo, Foo::s (%p) = %d\n", &Foo::s, Foo::s); }
$ cat test.cpp
#include <stdio.h>
#include <foo.hpp>
int main() {
Foo::s = 200;
printf("In main, Foo::s (%p) = %d\n", &Foo::s, Foo::s);
DumpLibFoo();
return 0;
}
-----
gcc -std=c++17 -c -fPIC -I./ test.cpp -fvisibility=hidden
gcc -std=c++17 -c -fPIC -I./ foo.cpp
gcc -o libfoo.so -shared foo.o
gcc -std=c++17 -o test test.o -Wl,-rpath ./ -L ./ -lfoo
./test
In main, Foo::s (0x5604c2741010) = 200
In libfoo, Foo::s (0x7f4e5173d028) = 100
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/107535] -fvisibility=hidden should not hide C++17 inline static variables
2022-11-05 12:38 [Bug c++/107535] New: Shouldn't -fvisibility=hidden hide C++17 inline static variables? junchao.zhang at gmail dot com
@ 2022-11-07 7:00 ` rguenth at gcc dot gnu.org
2023-06-15 11:07 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-11-07 7:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107535
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |ABI
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
kind-of a pilot error, maybe we should diagnose those cases instead?
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/107535] -fvisibility=hidden should not hide C++17 inline static variables
2022-11-05 12:38 [Bug c++/107535] New: Shouldn't -fvisibility=hidden hide C++17 inline static variables? junchao.zhang at gmail dot com
2022-11-07 7:00 ` [Bug c++/107535] -fvisibility=hidden should not hide C++17 inline static variables rguenth at gcc dot gnu.org
@ 2023-06-15 11:07 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2023-06-15 11:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107535
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> kind-of a pilot error,
Yes, this seems to be exactly what the code asks for. If you compile the class
with hidden visibility, its static member isn't shared between libfoo.so and
the rest of the program.
I think this fixes it:
struct __attribute__ ((visibility ("default"))) Foo {static inline int s = 100;
};
> maybe we should diagnose those cases instead?
So warn that DumpLibFoo has global visibility but refers to a global variable
that's potentially reachable from outside the current library, but that the
global variable's visibility doesn't match? Or something else?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-15 11:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-05 12:38 [Bug c++/107535] New: Shouldn't -fvisibility=hidden hide C++17 inline static variables? junchao.zhang at gmail dot com
2022-11-07 7:00 ` [Bug c++/107535] -fvisibility=hidden should not hide C++17 inline static variables rguenth at gcc dot gnu.org
2023-06-15 11:07 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).