From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A3FDF38576A0; Sat, 5 Nov 2022 12:38:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3FDF38576A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667651914; bh=6pS3t/wTqV2184Od007mhdkPCNx0FKBS53jAVRynEsc=; h=From:To:Subject:Date:From; b=VkLQbzDhl8L7qV3dT63MCOzYhuYDAEW+PhmqcXe/seX8n0i3GoMpVITM+/kZmIHbc nZDQtD8PKKgjnCdtKEepPi83LqAUIga5gH10QtZQXpDHxmYzuoX82hHKaqxRkdwEpK G8wRQJwyWz2UjjVR7cueeaZASFiFJLOBKtgBRSxM= From: "junchao.zhang at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107535] New: Shouldn't -fvisibility=hidden hide C++17 inline static variables? Date: Sat, 05 Nov 2022 12:38:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.3.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: junchao.zhang at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107535 Bug ID: 107535 Summary: Shouldn't -fvisibility=3Dhidden 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=3Dhidden. This is dangerous, since with C++17 inline static variables, they will app= ear in headers and be included in *.cpp files. If the *.cpp files are compiled = with -fvisibility=3Dhidden, each will get their own storage. $ cat foo.hpp=20 struct Foo {static inline int s =3D 100; }; extern __attribute__ ((visibility ("default"))) void DumpLibFoo(); $ cat foo.cpp #include #include void DumpLibFoo() { printf("In libfoo, Foo::s (%p) =3D %d\n", &Foo::s, Foo:= :s); } $ cat test.cpp #include #include int main() { Foo::s =3D 200; printf("In main, Foo::s (%p) =3D %d\n", &Foo::s, Foo::s); DumpLibFoo(); return 0; } ----- gcc -std=3Dc++17 -c -fPIC -I./ test.cpp -fvisibility=3Dhidden gcc -std=3Dc++17 -c -fPIC -I./ foo.cpp gcc -o libfoo.so -shared foo.o gcc -std=3Dc++17 -o test test.o -Wl,-rpath ./ -L ./ -lfoo ./test In main, Foo::s (0x5604c2741010) =3D 200 In libfoo, Foo::s (0x7f4e5173d028) =3D 100=