Bug 112551 - Incompatibility of libstdc++ linked statically and -Bsymbolic-functions
Summary: Incompatibility of libstdc++ linked statically and -Bsymbolic-functions
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-15 16:54 UTC by sergesanspaille
Modified: 2024-01-30 06:41 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
reproducer (510 bytes, application/gzip)
2023-11-15 16:54 UTC, sergesanspaille
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sergesanspaille 2023-11-15 16:54:22 UTC
Created attachment 56595 [details]
reproducer

Hey folks,

While debugging a firefox issue, we found an interesting bug where a program linked statically against libstdc++ and dynamically against a library that's itself statically linked against libstdc++, both with -Bsymbolic-functions, is segfaulting at startup (during Elf con structor init)

The attached tarball provides a minimal reproducer.

Our understanding of the problem is that an initializer from the libstdc++ is run by the host binary, updating locale::_S_once from the host. Then the shared libray initializes itself, calls the same initializer through its non-interposed version, checks the interposed symbol locale::_S_once (remember we only have -Bsymbolic-functions and not -Bsymbolic), decides everything is initialized, and proceeds to call a local function that references local storage that's not initialized, kaboom.

Given the setup, I'm not quite sure libstdc++ should actually support the scenario, but maybe there's a way?
Comment 1 Richard Biener 2023-11-16 07:30:51 UTC
Don't use -Bsymbolic-functions then?  You are actively breaking the C++ standard guarantees here.  Not to say, don't use static linking, but hey ... or at least fully statically link the application.