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

Undefined symbols for architecture x86_64 iPhone Simulator #779

Closed
jnavarrom opened this issue Jan 11, 2019 · 3 comments
Closed

Undefined symbols for architecture x86_64 iPhone Simulator #779

jnavarrom opened this issue Jan 11, 2019 · 3 comments

Comments

@jnavarrom
Copy link
Contributor

We have a linker problem in the iPhone simulator with master. It works for devices but not for simulator. The problem is that for the simulator the flag -DCRYPTOPP_DISABLE_ASM is added to the compilation and then the flag CRYPTOPP_BOOL_ALIGN16 is set to 0 in the config.h, so CryptoPP::AlignedAllocate and CryptoPP::AlignedDeallocate aren't compiled:

Undefined symbols for architecture x86_64:
  "CryptoPP::AlignedAllocate(unsigned long)", referenced from:
      CryptoPP::AllocatorWithCleanup<unsigned int, true>::allocate(unsigned long, void const*) in libMEGASDK.a(megaapi_impl.o)
      ...
  "CryptoPP::AlignedDeallocate(void*)", referenced from:
      CryptoPP::AllocatorWithCleanup<unsigned int, true>::deallocate(void*, unsigned long) in libMEGASDK.a(megaapi_impl.o)
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

In our headers search path, the cryptopp config.h has the line https://github.com/weidai11/cryptopp/blob/master/config.h#L64 commented and I think for that the linker fails. This line should be commented for devices (armv7, armv7s and arm64) but not for simulator (x84_64).

The problem is that we have a fat library (for iPhone and iPhone simulator), the arch x86_64 built with -DCRYPTOPP_DISABLE_ASM and the others one without -DCRYPTOPP_DISABLE_ASM and then we have the same config.h (one library with all archs and one common include folder). We compile the cryptopp using the setenv-ios.sh scrript and the make -f GNUmakefile-cross lean -j 8.

We can fix the issue, compiling all the archs with -DCRYPTOPP_DISABLE_ASM and uncommented the line in the config.h, but we wouldn't take the adventage of use ASM where available.

Any advice to fix this issues?

@noloader
Copy link
Collaborator

the flag CRYPTOPP_BOOL_ALIGN16 is set to 0 in the config.h, so CryptoPP::AlignedAllocate and CryptoPP::AlignedDeallocate aren't compiled
...

Yeah, I seem to recall hitting that in the past. I thought we cleared it about 2 or 3 years ago by making both aligned and non-aligned available all the time. I can't find the issue/discussion at the moment. I found CryptoPP 5.6.2 - Undefined symbols for architecture x86_64 on the mailing list but I think there's a better discussion somewhere.

I see another report was opened about a year ago and it was closed due to lack of feedback.

I [still?] think the best way forward is to make both routines available all of the time to sidestep the problem. Let me see if I can get the change added without breaking things.

noloader added a commit to noloader/cryptopp that referenced this issue Jan 11, 2019
@noloader
Copy link
Collaborator

noloader commented Jan 11, 2019

I think the changes on my testing fork are OK. I'm going to merge them.

$ source ./setenv-ios.sh iPhoneSimulator
Configuring for iPhoneSimulator (i386)
XCODE_SDK: iPhoneSimulator8.2.sdk
XCODE_DEVELOPER: /Applications/Xcode.app/Contents/Developer
XCODE_TOOLCHAIN: /Applications/Xcode.app/Contents/Developer/usr/bin
XCODE_DEVELOPER_TOP: /Applications/Xcode.app/Contents/Developer/Platforms/iPhone Simulator.platform/Developer
IOS_ARCH: i386
IOS_TOOLCHAIN: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefaul t.xctoolchain/usr/bin/
IOS_FLAGS:  -DCRYPTOPP_DISABLE_ASM -miphoneos-version-min=5 -DCRYPTOPP_DISABLE_ASM
IOS_SYSROOT: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.2.sdk
...

$ make -f GNUmakefile-cross -j 4
Here's what we found... IS_X86: 1, IS_X64: 0, IS_ARM32: 0, IS_ARMV8: 0
clang++ -DNDEBUG -g2 -O3 -fPIC -pipe -Wall -DCRYPTOPP_DISABLE_ASM -miphoneos-ver sion-min=5 -DCRYPTOPP_DISABLE_ASM -arch i386 -isysroot "/Applications/Xcode.app/ Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimul ator8.2.sdk" -stdlib=libc++ -c misc.cpp
...

And then:

$ nm libcryptopp.a 2>/dev/null | c++filt | grep -i allocate  | grep ' T '
00000940 T CryptoPP::AlignedAllocate(unsigned long)
000009d0 T CryptoPP::AlignedDeallocate(void*)
000009e0 T CryptoPP::UnalignedAllocate(unsigned long)
00000a70 T CryptoPP::UnalignedDeallocate(void*)

noloader added a commit that referenced this issue Jan 11, 2019
…780)

* Make AlignedAllocate available in simulator debug builds (GH #779)

* Use CRYPTOPP_CONSTANT for rotate params
@noloader
Copy link
Collaborator

noloader commented Jan 11, 2019

I'm fairly certain we cleared the issue at PR #780. Ping back if you still have trouble. I can re-open the issue.

freebsd-git pushed a commit to freebsd/freebsd-ports that referenced this issue Sep 16, 2022
Drop most of the SIMD logic. The cryptopp Makefile autodetects CPU
features regardless if CPUTYPE is set and it is not possible to disable
specific instruction sets. It is only possible to completely disable
assembly optimizations, which is recommended for package building unless
all consumer machines support the build machine's CPU instruction sets.

Since version 8.1, it is no longer necessary to export
-DCRYPTOPP_DISABLE_ASM to the pkgconfig file. Consumers will now
build without it defined if the SIMD option is disabled. Remove old
workarounds pertaining to this issue.
weidai11/cryptopp#779

Bump PORTREVISION on consumers due to ABI incompatibility.

https://www.cryptopp.com/release870.html
mekanix pushed a commit to mekanix/freebsd-ports that referenced this issue Sep 21, 2022
Drop most of the SIMD logic. The cryptopp Makefile autodetects CPU
features regardless if CPUTYPE is set and it is not possible to disable
specific instruction sets. It is only possible to completely disable
assembly optimizations, which is recommended for package building unless
all consumer machines support the build machine's CPU instruction sets.

Since version 8.1, it is no longer necessary to export
-DCRYPTOPP_DISABLE_ASM to the pkgconfig file. Consumers will now
build without it defined if the SIMD option is disabled. Remove old
workarounds pertaining to this issue.
weidai11/cryptopp#779

Bump PORTREVISION on consumers due to ABI incompatibility.

https://www.cryptopp.com/release870.html
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

No branches or pull requests

2 participants