-
Notifications
You must be signed in to change notification settings - Fork 409
Use a linker script for libstdc++. #1134
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
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
So this is a much better solution than what I was doing before: to fix #902, we removed the shared libstdc++.so, however, this has issues since the static version reference symbols resolved in The solution is actually quite simple: use a linker script (which I should have though of, a long time ago): /* cross-rs linker script
* this allows us to statically link libstdc++ to avoid segfaults
* https://github.com/cross-rs/cross/issues/902
*/
GROUP ( libstdc++.a AS_NEEDED( -lgcc -lc -lm ) ) This way, we always link to our static C++ library, and then resolve the missing symbols if required. This works when built against a crate using re2 as a CMake dependency as seen in #1112. |
This comment was marked as outdated.
This comment was marked as outdated.
99d89f8
to
64ef5a6
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
64ef5a6
to
c7c819d
Compare
bors try --target musl |
tryBuild succeeded: |
Use a linker script for `libstdc++.so` since we remove the dylib, to ensure a static build is always used to avoid segfaults at runtime. However, the archive can reference missing symbols present in `libc` or `libgcc`, and itself depends on symbols in `libm`. To ensure these libraries are properly linked when forcing a build against the static `libstdc++`, create a linker script for `libstdc++.so` that links to the static archive, and as needed, all dependencies.
c7c819d
to
cd05ef7
Compare
Just a ping for a review on this: does this look ready? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops my bad!
yes this looks great
bors r+
Build succeeded: |
Use a linker script for
libstdc++.so
since we remove the dylib, to ensure a static build is always used to avoid segfaults at runtime. However, the archive can reference missing symbols present inlibc
orlibgcc
, and itself depends on symbols inlibm
. To ensure these libraries are properly linked when forcing a build against the staticlibstdc++
, create a linker script forlibstdc++.so
that links to the static archive, and as needed, all dependencies.Related to #1124.