public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105645] New: Template specializations are not hidden with fvisibility=hidden
@ 2022-05-18 14:02 kndevl at outlook dot com
  2022-05-18 14:25 ` [Bug c++/105645] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: kndevl at outlook dot com @ 2022-05-18 14:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105645

            Bug ID: 105645
           Summary: Template specializations are not hidden with
                    fvisibility=hidden
           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 <Encoding enc>
int encode(int);

template <>
int encode<Encoding::A>(int x)
{
    return x + 1;
}

int f() { return 42; }
}
```

I am compiling it through CMake with `/usr/bin/g++ -Dencoding_EXPORTS  -g -fPIC
-fvisibility=hidden -fvisibility-inlines-hidden -std=gnu++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,libencoding.so
-o libencoding.so CMakeFiles/encoding.dir/encoding.cpp.o
CMakeFiles/encoding.dir/encoding-user.cpp.o`

I expect `f()` and `Test::encode<Encoding::A>` to have the same symbol binding
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=hidden`. 

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?

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-05-26  7:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-18 14:02 [Bug c++/105645] New: Template specializations are not hidden with fvisibility=hidden kndevl at outlook dot com
2022-05-18 14:25 ` [Bug c++/105645] " pinskia at gcc dot gnu.org
2022-05-19  6:10 ` kndevl at outlook dot com
2024-02-23 13:40 ` tanksherman27 at gmail dot com
2024-05-26  7:43 ` pinskia at gcc dot gnu.org
2024-05-26  7:48 ` tanksherman27 at gmail dot com

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).