Bug 231998

Summary: security/cryptopp: undefined reference to `CryptoPP::AlignedDeallocate(void*)'
Product: Ports & Packages Reporter: Andreas Sommer <andreas.sommer87>
Component: Individual Port(s)Assignee: Jason E. Hale <jhale>
Status: Closed Works As Intended    
Severity: Affects Some People Flags: jhale: maintainer-feedback+
Priority: ---    
Version: Latest   
Hardware: Any   
OS: Any   
Bug Depends on:    
Bug Blocks: 241335    
Description Flags
cryptopp 7.0.0 build log on 2018Q4 / FreeBSD 11.2 amd64 none

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:

        #define CRYPTOPP_BOOL_ALIGN16 1
        #define CRYPTOPP_BOOL_ALIGN16 0

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)
  # Apply to all targets (may not be what you want, was fine in my case)
  # Fall back to our previous solution (not included with CMake!)
  find_package(CryptoPP REQUIRED)
# ...link to ${CRYPTOPP_LIBRARIES} in targets...