Bug 231998 - security/cryptopp: undefined reference to `CryptoPP::AlignedDeallocate(void*)'
Summary: security/cryptopp: undefined reference to `CryptoPP::AlignedDeallocate(void*)'
Status: Closed Works As Intended
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Jason E. Hale
URL:
Keywords:
Depends on:
Blocks: 241335
  Show dependency treegraph
 
Reported: 2018-10-06 13:29 UTC by Andreas Sommer
Modified: 2019-11-17 18:29 UTC (History)
0 users

See Also:
jhale: maintainer-feedback+


Attachments
cryptopp 7.0.0 build log on 2018Q4 / FreeBSD 11.2 amd64 (57.78 KB, text/plain)
2018-10-06 13:29 UTC, Andreas Sommer
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Sommer 2018-10-06 13:29:38 UTC
Created attachment 197832 [details]
cryptopp 7.0.0 build log on 2018Q4 / FreeBSD 11.2 amd64

By default, the SIMD option is off, resulting in disabling certain features:

c++ -O2 -pipe -fstack-protector -fno-strict-aliasing -std=c++11 -stdlib=libc++ -Wno-deprecated-declarations -fPIC -DNDEBUG -DCRYPTOPP_DISABLE_ASM -DCRYPTOPP_DISABLE_SSE2 -DCRYPTOPP_DISABLE_SSSE3 -DCRYPTOPP_DISABLE_SSE4 -pthread -pipe -c misc.cpp

Thus, the `AlignedDeallocate` function does not get compiled.

Trying to use the shared object with `-lcryptopp` results in the above linker error because `config.h` determines enabled features by the `CRYPTOPP_DISABLE_*` macros.

In this case:

#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64) && !defined(CRYPTOPP_DISABLE_ASM)
        #define CRYPTOPP_BOOL_ALIGN16 1
#else
        #define CRYPTOPP_BOOL_ALIGN16 0
#endif

So a program linking against libcryptopp will think that CRYPTOPP_BOOL_ALIGN16=1 while it was actually compiled (using default option) with CRYPTOPP_BOOL_ALIGN16=0, leading to the missing function.

Not sure how to approach this. Maybe write the chosen `CRYPTOPP_DISABLE_*` into the installed `config.h`?!
Comment 1 Jason E. Hale freebsd_committer 2018-10-06 13:52:50 UTC
If you are linking something against libcryptopp, I recommend you use pkgconf to set the correct definitions. If cryptopp was built with ASM disabled, the -DCRYPTOPP_DISABLE_ASM definition will be added to the cflags in the pkg-config file. So, whatever you are building needs to have this definintion set correctly.

All of the ports that currently depend on cryptopp have been fixed (AFAIK) to use pkgconf to set the correct definitions, so if this a private project, use the output of:

pkgconf --cflags-only-other libcryptopp

and add that to your CFLAGS/CXXFLAGS. If cryptopp was built without ASM, the output should be -DCRYPTOPP_DISABLE_ASM. If it was built with ASM, the output should be empty.
Comment 2 Andreas Sommer 2018-10-06 17:20:54 UTC
That makes sense, thank you!

Here's what I did for a CMake project, in case it's helpful for someone else:

# Try pkg-config in case cryptopp>=7.0.0 port is available
pkg_check_modules(CRYPTOPP libcryptopp)
if (CRYPTOPP_FOUND)
  # Apply to all targets (may not be what you want, was fine in my case)
  add_definitions(${CRYPTOPP_CFLAGS})
else()
  # Fall back to our previous solution (not included with CMake!)
  find_package(CryptoPP REQUIRED)
  set(CRYPTOPP_LIBRARIES ${CRYPTOPP_LIBRARY_RELEASE})
endif()
# ...link to ${CRYPTOPP_LIBRARIES} in targets...