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

Allow static and shared libs to be mixed. #3467

Merged
merged 11 commits into from
Sep 9, 2022
Merged

Conversation

graebm
Copy link
Contributor

@graebm graebm commented Aug 24, 2022

Resolved issues:

This is part of a fix for an issue from another repo: aws4embeddedlinux/meta-aws#191

Description of changes:

Currently, users cannot build a shared lib that uses a static libs2n.a, and they cannot build a static lib that uses a shared libs2n.so.

With this change, a library can use either static libs2n.a or shared libs2n.so. If both are static and shared libs2n are installed, BUILD_SHARED_LIBS serves as a tie-breaker.

Testing:

Local testing:

  • installed static libs2n.a and then built a shared library that used it.
  • installed shared libs2n.so and then built a static library that used it.
  • installed BOTH static libs2n.a and shared libs2n.so
    • Built my own shared library and confirmed that it used picked libs2n.so
    • Built my own static library and confirmed that it picked libs2n.a

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Currently, users cannot build a shared lib that uses a static libs2n.a, and they cannot build a static lib that uses a shared libs2n.so.

With this change, a library can use either static libs2n.a or shared libs2n.so. If both are static and shared libs2n are installed, BUILD_SHARED_LIBS serves as a tie-breaker.
@graebm graebm requested a review from a team as a code owner August 24, 2022 23:42
@camshaft
Copy link
Contributor

Can you add a script to test that this all works as intended? I just want to make sure this behavior is preserved and doesn't break in the future. You can see an example script for the libcrypto interning support.

@graebm
Copy link
Contributor Author

graebm commented Sep 1, 2022

Yeah, I'll put something together. Good suggestion

@graebm
Copy link
Contributor Author

graebm commented Sep 2, 2022

Added a test similar to the interning one
Kinda fun, I haven't done much bash scripting 😅

some tests are failing ... but they don't seem related to my changes. What now?

@graebm
Copy link
Contributor Author

graebm commented Sep 6, 2022

nevermind my last comment.

the tests that did run all seem to have passed

Copy link
Contributor

@dougch dougch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few call-outs around libcrypto use.

# create installation dir with libs2n.so
if [ ! -d $WORK_DIR/s2n-install-shared ]; then
(set -x; cmake -B$WORK_DIR/s2n-build-shared -DCMAKE_INSTALL_PREFIX=$WORK_DIR/s2n-install-shared -DBUILD_SHARED_LIBS=ON ${COMMON_S2N_BUILD_ARGS[@]})
(set -x; cmake --build $WORK_DIR/s2n-build-shared --target install)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --target install seems to cause cmake to link against the system libcrypto (openssl 1.1 on ubuntu18). Setting S2N_LIBCRYPTO to anything else causes this test to fail (built vs linked). Might be good to check the S2N_LIBCRYPTO/LIBCRYPTO_ROOT and bail out with something like only supported on openssl-1.1.1 in CI

Copy link
Contributor Author

@graebm graebm Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clue that --target install was doing something fishy.

Turns out the install step strips off the RPATH/RUNPATH.

I pushed a fix that sets LD_LIBRARY_PATH to point at libcrypto.so's location. That way an installed s2n can still use the same version of libcrypto.so it was built against, even if libcrypto.so isn't in an offical system lib directory

codebuild/spec/buildspec_omnibus.yml Show resolved Hide resolved
Copy link
Contributor

@dougch dougch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests passed with aws-lc locally, lgtm.

@dougch dougch merged commit 60005ef into aws:main Sep 9, 2022
@graebm graebm deleted the static-shared-mix branch September 9, 2022 23:28
dougch added a commit that referenced this pull request Sep 9, 2022
dougch added a commit that referenced this pull request Sep 9, 2022
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.

None yet

3 participants