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

            Bug ID: 118071
           Summary: C++ class method visible in shared object even with
                    -fviisibility=hidden and -fvisibility-inlines-hidden
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kstewart at efficios dot com
  Target Milestone: ---

Created attachment 59883
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59883&action=edit
lib.so-lib.ii from compilation

Given the following files:

```
// lib.h
#ifndef LIB_H
#define LIB_H

#ifdef __cplusplus
extern "C" {
#endif
__attribute__((visibility("default"))) int foo(int len);
#ifdef __cplusplus
}
#endif

#endif /* LIB_H */
```

And the source file, lib.cpp:

```
// lib.cpp
#include "lib.h"

#include <vector>

int foo(int len) {
        auto x = std::vector<int> {};
        x.resize(len);
        return int(sizeof(x));
}
```

When compiled with the following command:

g++ -o lib.so -shared -fvisibility=hidden -fvisibility-inlines-hidden -fPIC
lib.h lib.cpp -save-temps

The produced shared object contains a symbol with default visibility for the
vector append method.

E.g.

```
$ nm -g -D -C lib.so
                 w __cxa_finalize@GLIBC_2.2.5
0000000000001179 T foo
                 w __gmon_start__
                 U __gxx_personality_v0@CXXABI_1.3
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
                 U memcpy@GLIBC_2.14
                 U _Unwind_Resume@GCC_3.0
                 U operator delete(void*, unsigned long)@CXXABI_1.3.9
0000000000001506 W std::vector<int, std::allocator<int>
>::_M_default_append(unsigned long)
                 U operator new(unsigned long)@GLIBCXX_3.4
                 U std::__throw_bad_alloc()@GLIBCXX_3.4
                 U std::__throw_length_error(char const*)@GLIBCXX_3.4
                 U std::__throw_bad_array_new_length()@GLIBCXX_3.4.29
```

It seems to me that the `std::vector<int, std::allocator<int>...` symbol
shouldn't have the default visibility. Is there something I don't understand,
or is this a bug?

It seems somewhat similar to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105645 but I'm not sure if they
share the same cause.

Currently using gcc (Debian 14.2.0-8) 14.2.0.

Reply via email to