public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/111347] New: Memory leak loading a shared library built with --static-libsdtc++ when version script is used
@ 2023-09-08 21:58 gyunaev at ulduzsoft dot com
  2023-09-08 22:01 ` [Bug libstdc++/111347] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: gyunaev at ulduzsoft dot com @ 2023-09-08 21:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111347
           Summary: Memory leak loading a shared library built with
                    --static-libsdtc++ when version script is used
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gyunaev at ulduzsoft dot com
  Target Milestone: ---

Created attachment 55860
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55860&action=edit
The source code of the library, tester and Makefile

Gcc 13.2 built from the source. Linux x86_64, OpenSuSe Leap 15.5.

Our team has found that when building a C++ DSO using --static-libgcc and
--static-libstdc++ and using a version script to hide the visibility of
symbols, loading and unloading the resulting shared library leaks memory each
time such dlopen/dlclose happens. 

If a version script is not used, there is no leak.

Smallest shared library source which reproduces the issue:

------ libtest.cpp ------
#include <string>

int test()
{
    std::string a;
    return a.length();
}
---

The version script:
------ libtest.ver ------
{
    global:
        test;

    local:
        *;
};
---

Built with:

g++ -fPIC -shared -static-libgcc -static-libstdc++
-Wl,--version-script=libtest.ver libtest.cpp -o libtest.so

load-unload of this library leaks memory each time it unloads.
Loading-unloading is all that is needed - you don't need to call test or even
dlsym it. Easiest to see it when running dlclose( dlopen( "./libtest.so",
RTLD_NOW)) in a loop.

If you remove --version-script and rebuild the library, load-unload will not
leak.

Experimentally we found out that adding the symbol "_ZNSt8messagesIwE2idE;"
into global: section of version script would stop the leak, but this isn't
obvious to me why. This symbol demangles into std::messages<wchar_t>::id;

Attaching the tester, makefile and the loader.

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

* [Bug libstdc++/111347] Memory leak loading a shared library built with --static-libsdtc++ when version script is used
  2023-09-08 21:58 [Bug libstdc++/111347] New: Memory leak loading a shared library built with --static-libsdtc++ when version script is used gyunaev at ulduzsoft dot com
@ 2023-09-08 22:01 ` pinskia at gcc dot gnu.org
  2023-09-09  1:28 ` gyunaev at ulduzsoft dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-08 22:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am pretty sure _ZNSt8messagesIwE2idE is marked as GNU unique ....

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

* [Bug libstdc++/111347] Memory leak loading a shared library built with --static-libsdtc++ when version script is used
  2023-09-08 21:58 [Bug libstdc++/111347] New: Memory leak loading a shared library built with --static-libsdtc++ when version script is used gyunaev at ulduzsoft dot com
  2023-09-08 22:01 ` [Bug libstdc++/111347] " pinskia at gcc dot gnu.org
@ 2023-09-09  1:28 ` gyunaev at ulduzsoft dot com
  2023-09-09  4:49 ` gyunaev at ulduzsoft dot com
  2023-09-11 11:18 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: gyunaev at ulduzsoft dot com @ 2023-09-09  1:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from George Yunaev <gyunaev at ulduzsoft dot com> ---
Adding -fno-gnu-unique to the makefile for libleak.so doesn't remove the leak.

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

* [Bug libstdc++/111347] Memory leak loading a shared library built with --static-libsdtc++ when version script is used
  2023-09-08 21:58 [Bug libstdc++/111347] New: Memory leak loading a shared library built with --static-libsdtc++ when version script is used gyunaev at ulduzsoft dot com
  2023-09-08 22:01 ` [Bug libstdc++/111347] " pinskia at gcc dot gnu.org
  2023-09-09  1:28 ` gyunaev at ulduzsoft dot com
@ 2023-09-09  4:49 ` gyunaev at ulduzsoft dot com
  2023-09-11 11:18 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: gyunaev at ulduzsoft dot com @ 2023-09-09  4:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from George Yunaev <gyunaev at ulduzsoft dot com> ---
Indeed making a unique symbol local results in a leak.

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

* [Bug libstdc++/111347] Memory leak loading a shared library built with --static-libsdtc++ when version script is used
  2023-09-08 21:58 [Bug libstdc++/111347] New: Memory leak loading a shared library built with --static-libsdtc++ when version script is used gyunaev at ulduzsoft dot com
                   ` (2 preceding siblings ...)
  2023-09-09  4:49 ` gyunaev at ulduzsoft dot com
@ 2023-09-11 11:18 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2023-09-11 11:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
There's a reason it's marked as unique: it needs to be globally visible and
globally unique.

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

end of thread, other threads:[~2023-09-11 11:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-08 21:58 [Bug libstdc++/111347] New: Memory leak loading a shared library built with --static-libsdtc++ when version script is used gyunaev at ulduzsoft dot com
2023-09-08 22:01 ` [Bug libstdc++/111347] " pinskia at gcc dot gnu.org
2023-09-09  1:28 ` gyunaev at ulduzsoft dot com
2023-09-09  4:49 ` gyunaev at ulduzsoft dot com
2023-09-11 11:18 ` 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).