Skip to content

Add "Libs.private: -m" to wolfssl.pc.in for a static linking#7224

Merged
douzzer merged 2 commits intowolfSSL:masterfrom
mpsuzuki:pkg-config-static-link
Mar 2, 2024
Merged

Add "Libs.private: -m" to wolfssl.pc.in for a static linking#7224
douzzer merged 2 commits intowolfSSL:masterfrom
mpsuzuki:pkg-config-static-link

Conversation

@mpsuzuki
Copy link
Copy Markdown
Contributor

@mpsuzuki mpsuzuki commented Feb 8, 2024

Description

Currently wolfssl.pc returns -lwolfssl only, regardless whether the linking is dynamic or static. libwolfssl uses a few math functions, like log() and pow(), so static linking of libwolfssl needs "-lm" explicitly. Please consider "Libs.private: -lm" to wolfssl.pc.in.

Testing

Before this patch, both of "pkg-config --libs wolfssl" and "pkg-config --libs --static wolfssl" return "-L... -lwolfssl".
After this patch, "pkg-confg --libs wolfssl" returns "-L... -lwolfssl", but "pkg-config --libs --static wolfssl" returns "-L... -lwolfssl -lm".

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@wolfSSL-Bot
Copy link
Copy Markdown

Can one of the admins verify this patch?

@dgarske
Copy link
Copy Markdown
Member

dgarske commented Feb 8, 2024

Hi @mpsuzuki ,

The -lm math for pow/log is only required for DH is not using the standard DH P/G params. If you add WOLFSSL_DH_CONST to your build options -lm is not required. Will that solution work for you?

Thanks,
David Garske, wolfSSL

@dgarske dgarske self-assigned this Feb 8, 2024
@mpsuzuki
Copy link
Copy Markdown
Contributor Author

mpsuzuki commented Feb 9, 2024

Hi @dgarske,

Thank you for comment. Umm, maybe I failed to describe my intention. I have no problem about the dependency itself, but I want "pkg-config --libs --static" to return appropriate options to link libwolfssl statically.

In my understanding, your comment might be negative to introduce "Libs.private: -lm" to wolfssl.pc. Looking at configure.ac and CMakeLists.txt carefully, I understand the background of your position as follows:

  1. It is misunderstanding that wolfSSL is ALWAYS dependent with libm, so hardwiring the dependency into wolfssl.pc is not good.
  2. For example, "--enable-dh=const" can build a libwolfssl without a dependency with libm.
  3. Also, we should not assume as a math library is ALWAYS named as "libm".

I think my last patch is unacceptable for the viewpoint of the portability, I apologize. Checking configure.ac more carefully, I found that LT_LIB_M (a macro to set LIBM variable pointing a math library, defined by GNU libtool) is invoked if needed, like

# Link with the math library iff needed.
if test "$ENABLED_DH" != "no" && test "$ENABLED_DH" != "const"; then
   LT_LIB_M
fi

Thus, I revised my patch (e4b1e54) as following:

  1. Add a variable LIBM to wolfssl.pc.in, and expect a meta-build tool (configure or cmake) set it appropriately before generating wolfssl.pc.
  2. Add "AC_SUBST([LIBM])" to configure.ac. LIBM would be blank if LT_LIB_M is not invoked (e.g. ENABLED_DH == "no" or "const"). If invoked, LIBM would have appropriate value to link a math library.
  3. Let cmake search "m" in the target link libraries for libwolfssl, and if it is found, let cmake set LIBM.

I cannot find other meta-build tool files caring about wolfssl.pc in IDE directory. Is this more considerable?

@dgarske
Copy link
Copy Markdown
Member

dgarske commented Feb 9, 2024

Hi @mpsuzuki ,

The changes look good. Can you tell us more about your project? Are you planning on making additional PR's? For code contributions we required a signed contributor agreement.

Thanks,
David Garske, wolfSSL

@mpsuzuki
Copy link
Copy Markdown
Contributor Author

Dear @dgarske ,
Thank you for taking care on this. Please let me know more about required signed agreement. Does it require the signatue of my employer?

Although I made a forked repository to develop my patch, my patches in future (if there is) would be only for the meta-build tools or the compatibility macros for OpenSSL, because I have little expertise in the cryptography, secure network programming.
As the educational materials, I wrote a few toy servers for popular TLS implementations (OpenSSL, GnuTLS, BearSSL and wolfSSL) to show the similarities & differences of the APIs. I believe that my patches would be too small to insist some intellectual properties.

@dgarske
Copy link
Copy Markdown
Member

dgarske commented Feb 12, 2024

Hi @mpsuzuki ,

I recommend you email support at wolfssl dot com and provide some additional details and request a contributor agreement. Typically you would sign the contributor agreement yourself. It would be great to hear more about your education materials and we will happily support you in efforts involving wolfSSL in those.

Thanks,
David Garske, wolfSSL

@embhorn
Copy link
Copy Markdown
Member

embhorn commented Feb 28, 2024

@mpsuzuki is approved as a contributor.

@dgarske dgarske assigned wolfSSL-Bot and unassigned dgarske Feb 28, 2024
@dgarske dgarske requested a review from douzzer February 28, 2024 18:51
@douzzer douzzer merged commit 88f0777 into wolfSSL:master Mar 2, 2024
@mpsuzuki
Copy link
Copy Markdown
Contributor Author

mpsuzuki commented Mar 2, 2024

Thank you, @dgarske, @embhorn and @douzzer !

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.

5 participants