【问题标题】:Crypto++ and neon_vector_type attribute is not supported for this target using Android NDK?使用 Android NDK 的此目标不支持 Crypto++ 和 neon_vector_type 属性?
【发布时间】:2019-07-11 12:16:17
【问题描述】:

我想为 android armeabi 构建 cryptopp。指南在这里:https://github.com/noloader/cryptopp-android

git clone http://github.com/weidai11/cryptopp.git
cd cryptopp
git submodule add http://github.com/noloader/cryptopp-android.git android
git submodule update --remote

cp "$PWD/android/Android.mk" "$PWD"
cp "$PWD/android/Application.mk" "$PWD"

打开Application.mk文件,修改一些变量

APP_ABI := all → APP_ABI := armeabi

APP_STL := c++_shared → APP_STL := gnustl_shared

然后,设置环境变量:

export ANDROID_SDK_ROOT=/Users/user/Library/Android/sdk/
export ANDROID_NDK_ROOT=/Users/user/Downloads/android-ndk-r16b/

构建命令:android-ndk-r16b/ndk-build V=1 NDK_PROJECT_PATH="$PWD" NDK_APPLICATION_MK="$PWD/Application.mk" NDK_HOST_32BIT=1

错误如下:

>     android-ndk-r16b/toolchains/llvm/prebuilt/darwin-x86_64/lib64/clang/5.0.300080/include/arm_neon.h:28:2:
 error: "NEON support not enabled"
     #error "NEON support not enabled"  ^ android-ndk-r16b/toolchains/llvm/prebuilt/darwin-x86_64/lib64/clang/5.0.300080/include/arm_neon.h:48:24:
 error: 'neon_vector_type' attribute is not
           supported for this target typedef __attribute__((neon_vector_type(8))) int8_t int8x8_t;

编辑

我推荐了 config_asm.h 文件中的所有 CRYPTOPP 标志。错误信息在这里

$android-ndk-r16b/ndk-build NDK_PROJECT_PATH="$PWD" NDK_APPLICATION_MK="$PWD/Application.mk"

/home/android-ndk-r16b/build/core/setup-app.mk:81: Android NDK: Application targets deprecated ABI(s): armeabi    
/home/android-ndk-r16b/build/core/setup-app.mk:82: Android NDK: Support for these ABIs will be removed in a future NDK release.    
[armeabi] Compile++ thumb: cryptopp_shared <= cryptlib.cpp
[armeabi] Compile++ thumb: cryptopp_shared <= cpu.cpp
[armeabi] Compile++ thumb: cryptopp_shared <= integer.cpp
[armeabi] Compile++ thumb: cryptopp_shared <= 3way.cpp
[armeabi] Compile++ thumb: cryptopp_shared <= adler32.cpp
[armeabi] Compile++ thumb: cryptopp_shared <= algebra.cpp
[armeabi] Compile++ thumb: cryptopp_shared <= algparam.cpp
[armeabi] Compile++ thumb: cryptopp_shared <= arc4.cpp
[armeabi] Compile++ thumb: cryptopp_shared <= aria.cpp
[armeabi] Compile++ thumb: cryptopp_shared <= aria_simd.cpp
In file included from /home/crypto++/cryptopp/aria_simd.cpp:19:0:
/home/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/include/arm_neon.h:31:2: error: #error You must enable NEON instructions (e.g. -mfloat-abi=softfp -mfpu=neon) to use arm_neon.h
 #error You must enable NEON instructions (e.g. -mfloat-abi=softfp -mfpu=neon) to use arm_neon.h
  ^
/home/crypto++/cryptopp/aria_simd.cpp:65:34: error: 'uint32x4_t' does not name a type
 inline void ARIA_GSRK_NEON(const uint32x4_t X, const uint32x4_t Y, byte RK[16])
                                  ^
/home/crypto++/cryptopp/aria_simd.cpp:65:54: error: 'uint32x4_t' does not name a type
 inline void ARIA_GSRK_NEON(const uint32x4_t X, const uint32x4_t Y, byte RK[16])
                                                      ^
/home/crypto++/cryptopp/aria_simd.cpp: In function 'void CryptoPP::ARIA_UncheckedSetKey_Schedule_NEON(CryptoPP::byte*, CryptoPP::word32*, unsigned int)':
/home/crypto++/cryptopp/aria_simd.cpp:80:8: error: 'uint32x4_t' does not name a type
  const uint32x4_t w0 = vld1q_u32(ws+ 0);
        ^
/home/crypto++/cryptopp/aria_simd.cpp:81:8: error: 'uint32x4_t' does not name a type
  const uint32x4_t w1 = vld1q_u32(ws+ 8);
        ^
/home/crypto++/cryptopp/aria_simd.cpp:82:8: error: 'uint32x4_t' does not name a type
  const uint32x4_t w2 = vld1q_u32(ws+12);
        ^
/home/crypto++/cryptopp/aria_simd.cpp:83:8: error: 'uint32x4_t' does not name a type
  const uint32x4_t w3 = vld1q_u32(ws+16);
        ^
/home/crypto++/cryptopp/aria_simd.cpp:85:21: error: 'w0' was not declared in this scope
  ARIA_GSRK_NEON<19>(w0, w1, rk +   0);
                     ^
/home/crypto++/cryptopp/aria_simd.cpp:85:25: error: 'w1' was not declared in this scope
  ARIA_GSRK_NEON<19>(w0, w1, rk +   0);
                         ^
/home/crypto++/cryptopp/aria_simd.cpp:86:25: error: 'w2' was not declared in this scope
  ARIA_GSRK_NEON<19>(w1, w2, rk +  16);
                         ^
/home/crypto++/cryptopp/aria_simd.cpp:87:25: error: 'w3' was not declared in this scope
  ARIA_GSRK_NEON<19>(w2, w3, rk +  32);
                         ^
/home/crypto++/cryptopp/aria_simd.cpp: In function 'void CryptoPP::ARIA_ProcessAndXorBlock_NEON(const byte*, CryptoPP::byte*, const byte*, CryptoPP::word32*)':
/home/crypto++/cryptopp/aria_simd.cpp:136:22: error: 'vld1q_u8' was not declared in this scope
     vld1q_u8(xorBlock),
                      ^
/home/crypto++/cryptopp/aria_simd.cpp:139:31: error: 'vrev32q_u8' was not declared in this scope
      vrev32q_u8(vld1q_u8((rk))))));
                               ^
/home/crypto++/cryptopp/aria_simd.cpp:139:32: error: 'veorq_u8' was not declared in this scope
      vrev32q_u8(vld1q_u8((rk))))));
                                ^
/home/crypto++/cryptopp/aria_simd.cpp:139:33: error: 'veorq_u8' was not declared in this scope
      vrev32q_u8(vld1q_u8((rk))))));
                                 ^
/home/crypto++/cryptopp/aria_simd.cpp:139:33: error: redeclaration of '<typeprefixerror>veorq_u8'
/home/crypto++/cryptopp/aria_simd.cpp:139:32: note: previous declaration '<typeprefixerror>veorq_u8'
      vrev32q_u8(vld1q_u8((rk))))));
                                ^
/home/crypto++/cryptopp/aria_simd.cpp:139:34: error: 'vst1q_u8' was not declared in this scope
      vrev32q_u8(vld1q_u8((rk))))));
                                  ^
/home/crypto++/cryptopp/aria_simd.cpp:145:22: error: 'vld1q_u8' was not declared in this scope
     vld1q_u8(outBlock),
                      ^
/home/crypto++/cryptopp/aria_simd.cpp:146:28: error: 'vrev32q_u8' was not declared in this scope
     vrev32q_u8(vld1q_u8(rk))));
                            ^
/home/crypto++/cryptopp/aria_simd.cpp:146:29: error: 'veorq_u8' was not declared in this scope
     vrev32q_u8(vld1q_u8(rk))));
                             ^
/home/crypto++/cryptopp/aria_simd.cpp:146:30: error: 'vst1q_u8' was not declared in this scope
     vrev32q_u8(vld1q_u8(rk))));
                              ^
make: *** [/home/crypto++/cryptopp/obj/local/armeabi/objs/cryptopp_shared/aria_simd.o] Error 1

【问题讨论】:

  • 仅供参考:除非您的 Android 设备已经使用了 10 年以上,否则它几乎肯定会基于 ARMv7 或 ARMv8 架构。较新版本的 NDK 甚至不支持过时的 ARMv5 (armeabi) 架构。
  • 认为我知道问题出在哪里。作为创可贴,打开config_asm.h(或config.h)并在顶部附近取消注释CRYPTOPP_DISABLE_ASM。另请参阅 Crypto++ wiki 上的 Android.mk (Command Line)
  • @jww 我做了,现在我得到一个不同的错误。 #error 您必须启用 NEON 指令(例如 -mfloat-abi=softfp -mfpu=neon)才能使用 arm_neon.h
  • 我将 LOCAL_CFLAGS := -DHAVE_NEON=1 添加到 Android.mk 文件中。但这并不能解决这个问题。
  • 不,这行不通。我认为我们需要为您进行一些源代码更改。 ARM 真的很痛苦,因为所有的编译器都在做自己的事情。不遵循 ARM ACLE 约定。 Android 有点糟糕,因为它自己做事,而且它使用经过修改的工具链,这让我们更加困难。我们正在Issue 863 跟踪此事。

标签: android android-ndk crypto++


【解决方案1】:
$android-ndk-r16b/ndk-build NDK_PROJECT_PATH="$PWD" NDK_APPLICATION_MK="$PWD/Application.mk"

/home/android-ndk-r16b/build/core/setup-app.mk:81: Android NDK: Application targets deprecated ABI(s): armeabi    
/home/android-ndk-r16b/build/core/setup-app.mk:82: Android NDK: Support for these ABIs will be removed in a future NDK release.    
[armeabi] Compile++ thumb: cryptopp_shared <= cryptlib.cpp
...
[armeabi] Compile++ thumb: cryptopp_shared <= aria_simd.cpp
In file included from /home/crypto++/cryptopp/aria_simd.cpp:19:0:
/home/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/include/arm_neon.h:31:2:
error: #error You must enable NEON instructions (e.g. -mfloat-abi=softfp -mfpu=neon) to use arm_neon.h

我通常不这样做,但是...基于 ndk-r16b,我认为您应该更新 NDK。我没有ndk-r16b:

cryptopp$ ls /opt/
android-ndk  android-ndk-r19c  android-sdk

我有 ndk-19c,我无法复制 Master 的问题。首先,armeabi 不见了:

cryptopp$ ndk-build APP_ABI=armeabi NDK_PROJECT_PATH="$PWD" NDK_APPLICATION_MK="$PWD/Application.mk" V=1
Android NDK: The armeabi ABI is no longer supported. Use armeabi-v7a.    
Android NDK: NDK Application 'local' targets unknown ABI(s): armeabi    
Android NDK: Please fix the APP_ABI definition in /home/jwalton/cryptopp/Application.mk    
/opt/android-ndk-r19c/build/core/setup-app.mk:79: *** Android NDK: Aborting    .  Stop.

其次,armeabi-v7a 构建成功:

cryptopp$ ndk-build APP_ABI=armeabi-v7a NDK_PROJECT_PATH="$PWD" NDK_APPLICATION_MK="$PWD/Application.mk" V=1
rm -f /home/jwalton/cryptopp/libs/armeabi-v7a/
rm -f /home/jwalton/cryptopp/libs/armeabi-v7a/gdbserver
rm -f /home/jwalton/cryptopp/libs/armeabi-v7a/gdb.setup
...

/opt/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -MMD -MP
 -MF /home/jwalton/cryptopp/obj/local/armeabi-v7a/objs/cryptopp_static/aria.o.d
-target armv7-none-linux-androideabi21 -fdata-sections -ffunction-sections -fsta
ck-protector-strong -funwind-tables -no-canonical-prefixes  --sysroot /opt/andro
id-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/sysroot -g -Wno-invalid-comman
d-line-argument -Wno-unused-command-line-argument  -fno-addrsig -fno-exceptions
-fno-rtti -fpic -mfpu=vfpv3-d16  -march=armv7-a -mthumb -Oz -DNDEBUG  -I/opt/and
roid-ndk-r19c/sources/android/cpufeatures -I/opt/android-ndk-r19c/sources/cxx-st
l/llvm-libc++/include -I/opt/android-ndk-r19c/sources/cxx-stl/llvm-libc++/../llv
m-libc++abi/include -I/home/jwalton/cryptopp -std=c++11    -DANDROID  -nostdinc+
+ -Wa,--noexecstack -Wformat -Werror=format-security -Wall -frtti -fexceptions
-c  /home/jwalton/cryptopp/aria.cpp -o /home/jwalton/cryptopp/obj/local/armeabi-
v7a/objs/cryptopp_static/aria.o
[armeabi-v7a] Compile++ thumb: cryptopp_static <= aria_simd.cpp
rm -f /home/jwalton/cryptopp/obj/local/armeabi-v7a/objs/cryptopp_static/aria_simd.o

我也无法使用 Clang 在 ARM 开发板上使用 march=armv5te 复制它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-17
    • 1970-01-01
    • 2015-08-26
    • 2013-10-19
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多