From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9484838425B0; Wed, 18 May 2022 14:02:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9484838425B0 From: "kndevl at outlook dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105645] New: Template specializations are not hidden with fvisibility=hidden Date: Wed, 18 May 2022 14:02:57 +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: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kndevl at outlook 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 May 2022 14:02:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105645 Bug ID: 105645 Summary: Template specializations are not hidden with fvisibility=3Dhidden Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kndevl at outlook dot com Target Milestone: --- Consider this snippet `encoding.cpp` ``` namespace Test { enum class Encoding { A, B }; template int encode(int); template <> int encode(int x) { return x + 1; } int f() { return 42; } } ``` I am compiling it through CMake with `/usr/bin/g++ -Dencoding_EXPORTS -g -= fPIC -fvisibility=3Dhidden -fvisibility-inlines-hidden -std=3Dgnu++17 -MD -MT CMakeFiles/encoding.dir/encoding.cpp.o -MF CMakeFiles/encoding.dir/encoding.cpp.o.d -o CMakeFiles/encoding.dir/encoding.cpp.o -c /home/nishanth/source/main/encoding.cpp` and linking it with `/usr/bin/g++ -fPIC -g -shared -Wl,-soname,libencodin= g.so -o libencoding.so CMakeFiles/encoding.dir/encoding.cpp.o CMakeFiles/encoding.dir/encoding-user.cpp.o` I expect `f()` and `Test::encode` to have the same symbol bind= ing in `libencoding.so`. This is the output of `nm -C libencoding.so` ``` 0000000000001118 t Test::f() 0000000000001109 T int Test::encode<(Test::Encoding)0>(int) ``` `objdump -t encoding.cpp.o` does not have a `.hidden` tag on the `encode` specialization ``` 0000000000000000 g F .text 000000000000000f _ZN4Test6encodeILNS_8EncodingE0EEEii 000000000000000f g F .text 000000000000000b .hidden _ZN4Test1fEv ``` I can make `Test::encode` specialization local only by using `__attribute__((visibility("hidden")))` explicitly on the definition, in addition to calling the compiler with `-fvisibility=3Dhidden`.=20 On the other hand, clang 13.0.1 marks both `f()` and the `encode` specialization with `.hidden` in `objdump -t` output. Is there a way I can force g++ to hide template specializations?=