Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix source2 plugin issues related to stdc++ linking #167

Merged
merged 2 commits into from
Mar 7, 2024

Conversation

GAMMACASE
Copy link
Member

The general issue comes from using std stuff that depends on linking order of initialization, due to libengine2.so and other libraries in the cs2 package (generally the s2) to have the libstdc++ statically included in them and being higher in the symbol lookup hierarchy (due to how the game loads them and their order). This causes issues when you try to lookup symbols in a global scope as it falls down to finding symbols in a game libraries instead, which isn't a problem generally for a lot of std stuff, but there are certain functionalities that depends on a specific initialization process to be done which gets overwritten/reinitialized and causes issues on a completely working code.

As an example, currently running this code on a s2_sample plugin would not build the string correctly (the output would be test without the 1 at the end):

std::ostringstream test;
test << "test" << 1;
Msg("Message: %s", test.str().c_str());

To combat this issue, statically linking stdc++ to all the plugins and loading them up with RTLD_DEEPBIND flag seems to be the solution. And testing the sample plugin with these fixes, resolves the above issue.

The according pr was also opened at alliedmodders/hl2sdk-manifests#6 to include static libstdc++ linking for s2 titles (cs2 & dota2) and I'll mark this pr as a draft until the manifests are merged to also update the submodule in here with this pr.

Main credit for finding this issue, debugging it and finding a fix for it goes to poggu_, so thanks for that to him!

@GAMMACASE GAMMACASE marked this pull request as ready for review March 7, 2024 03:10
@psychonic psychonic merged commit 9fbe7f3 into alliedmodders:master Mar 7, 2024
4 checks passed
zer0k-z pushed a commit to zer0k-z/metamod-source that referenced this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants