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

Cross compile aws-iot-device-sdk-embedded-C for AARCH64 Raspberry pi3 B #1382

Closed
zlhk100 opened this issue Nov 7, 2020 · 5 comments
Closed
Assignees

Comments

@zlhk100
Copy link

zlhk100 commented Nov 7, 2020

Hi Experts,

We are trying to build a POC based on AWS IOT HUB using Raspberry PI3 B board.

I'm trying to add https://github.com/aws/aws-iot-device-sdk-embedded-C into my PI3 embedded Linux BUILDROOT as a CMake package and expect it to generating necessary shared libraries/headers so my linux application could use APIs exposed from those libraries. For now, I'm mostly interested in basic coreMQTT and coreHTTP client libraries.

Already tried building from my ubuntu18.4 and ran two of the demos without any problem. http/mqtt_mutual_auth_demos.

When I tried to do build, the process failed at cross-compiling aws-iod-device-embedded-c package. Please see attached building errors.

Any hints would be much appreciated!
Lei

-- The C compiler identification is GNU 9.2.1
-- Check for working C compiler: /home/leizhou/workspace/rpi3-optee/out-br/host/bin/aarch64-linux-gnu-gcc
-- Check for working C compiler: /home/leizhou/workspace/rpi3-optee/out-br/host/bin/aarch64-linux-gnu-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found OpenSSL: /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/libcrypto.a (found version "1.1.1g")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
Downloading the Amazon Root CA certificate...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1188 100 1188 0 0 3151 0 --:--:-- --:--:-- --:--:-- 3151
Downloading the Baltimore Cybertrust Root CA certificate...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1262 100 1262 0 0 1828 0 --:--:-- --:--:-- --:--:-- 1826
-- Looking for AWS_IOT_ENDPOINT
-- Looking for AWS_IOT_ENDPOINT - found
-- Looking for CLIENT_CERT_PATH
-- Looking for CLIENT_CERT_PATH - found
-- Looking for CLIENT_PRIVATE_KEY_PATH
-- Looking for CLIENT_PRIVATE_KEY_PATH - found
-- Looking for AWS_IOT_ENDPOINT
-- Looking for AWS_IOT_ENDPOINT - found
-- Looking for CLIENT_CERT_PATH
-- Looking for CLIENT_CERT_PATH - found
-- Looking for CLIENT_PRIVATE_KEY_PATH
-- Looking for CLIENT_PRIVATE_KEY_PATH - found
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:

BUILD_DOC
BUILD_DOCS
BUILD_EXAMPLE
BUILD_EXAMPLES
BUILD_TEST
BUILD_TESTING

-- Build files have been written to: /home/leizhou/workspace/rpi3-optee/out-br/build/aws_iotsdk_ext-1.0/buildroot-build

aws_iotsdk_ext 1.0 Building
PATH="/home/leizhou/workspace/rpi3-optee/out-br/host/bin:/home/leizhou/workspace/rpi3-optee/out-br/host/sbin:/home/leizhou/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/leizhou/bin:/usr/lib/jvm/java-8-openjdk-amd64/bin:/home/leizhou/bin:/usr/lib/jvm/java-8-openjdk-amd64/bin:/tools/Xilinx/Vivado/2020.1/bin:/tools/Xilinx/Vitis/2020.1/bin:/tools/Xilinx/Vitis/2020.1/gnu/aarch64/lin/aarch64-linux/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux/:/home/leizhou/bin/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin:/home/leizhou/bin/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin:/home/leizhou/bin/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin" /usr/bin/make -j5 -C /home/leizhou/workspace/rpi3-optee/out-br/build/aws_iotsdk_ext-1.0//buildroot-build
Scanning dependencies of target retry_utils_posix
Scanning dependencies of target clock_posix
Scanning dependencies of target sockets_posix
[ 15%] Building C object platform/posix/CMakeFiles/retry_utils_posix.dir/retry_utils_posix.c.o
[ 15%] Building C object platform/posix/CMakeFiles/clock_posix.dir/clock_posix.c.o
[ 15%] Building C object platform/posix/transport/CMakeFiles/sockets_posix.dir/src/sockets_posix.c.o
[ 20%] Linking C shared library ../../../lib/libsockets_posix.so
[ 25%] Linking C shared library ../../lib/libclock_posix.so
[ 30%] Linking C shared library ../../lib/libretry_utils_posix.so
[ 30%] Built target clock_posix
[ 30%] Built target sockets_posix
[ 30%] Built target retry_utils_posix
Scanning dependencies of target openssl_posix
Scanning dependencies of target plaintext_posix
[ 35%] Building C object platform/posix/transport/CMakeFiles/openssl_posix.dir/src/openssl_posix.c.o
[ 40%] Building C object platform/posix/transport/CMakeFiles/plaintext_posix.dir/src/plaintext_posix.c.o
[ 45%] Linking C shared library ../../../lib/libplaintext_posix.so
[ 50%] Linking C shared library ../../../lib/libopenssl_posix.so
[ 50%] Built target plaintext_posix
/home/leizhou/workspace/rpi3-optee/toolchains/aarch64/bin/../lib/gcc/aarch64-none-linux-gnu/9.2.1/../../../../aarch64-none-linux-gnu/bin/ld: /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(sha1-armv8.o): relocation R_AARCH64_PREL64 against symbol OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(sha1-armv8.o): in function sha1_block_armv8':
(.text+0x1240): dangerous relocation: unsupported relocation
/home/leizhou/workspace/rpi3-optee/toolchains/aarch64/bin/../lib/gcc/aarch64-none-linux-gnu/9.2.1/../../../../aarch64-none-linux-gnu/bin/ld: /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(chacha-armv8.o): relocation R_AARCH64_PREL64 against symbol OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(chacha-armv8.o):(.text+0x20): dangerous relocation: unsupported relocation /home/leizhou/workspace/rpi3-optee/toolchains/aarch64/bin/../lib/gcc/aarch64-none-linux-gnu/9.2.1/../../../../aarch64-none-linux-gnu/bin/ld: /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(poly1305-armv8.o): relocation R_AARCH64_ADR_PREL_LO21 against symbol poly1305_blocks' which may bind externally can not be used when making a shared object; recompile with -fPIC
/home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(poly1305-armv8.o): in function poly1305_init': (.text+0x40): dangerous relocation: unsupported relocation /home/leizhou/workspace/rpi3-optee/toolchains/aarch64/bin/../lib/gcc/aarch64-none-linux-gnu/9.2.1/../../../../aarch64-none-linux-gnu/bin/ld: /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(poly1305-armv8.o): relocation R_AARCH64_ADR_PREL_LO21 against symbol poly1305_emit' which may bind externally can not be used when making a shared object; recompile with -fPIC
(.text+0x48): dangerous relocation: unsupported relocation
/home/leizhou/workspace/rpi3-optee/toolchains/aarch64/bin/../lib/gcc/aarch64-none-linux-gnu/9.2.1/../../../../aarch64-none-linux-gnu/bin/ld: /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(poly1305-armv8.o): relocation R_AARCH64_PREL64 against symbol OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(poly1305-armv8.o): in function poly1305_emit_neon':
(.text+0x9a0): dangerous relocation: unsupported relocation
/home/leizhou/workspace/rpi3-optee/toolchains/aarch64/bin/../lib/gcc/aarch64-none-linux-gnu/9.2.1/../../../../aarch64-none-linux-gnu/bin/ld: /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(sha256-armv8.o): relocation R_AARCH64_PREL64 against symbol OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(sha256-armv8.o): in function sha256_block_data_order':
(.text+0xf88): dangerous relocation: unsupported relocation
/home/leizhou/workspace/rpi3-optee/toolchains/aarch64/bin/../lib/gcc/aarch64-none-linux-gnu/9.2.1/../../../../aarch64-none-linux-gnu/bin/ld: /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(sha512-armv8.o): relocation R_AARCH64_PREL64 against symbol OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC /home/leizhou/workspace/rpi3-optee/out-br/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libcrypto.a(sha512-armv8.o): in function sha512_block_data_order':
(.text+0x1108): dangerous relocation: unsupported relocation
collect2: error: ld returned 1 exit status
platform/posix/transport/CMakeFiles/openssl_posix.dir/build.make:97: recipe for target 'lib/libopenssl_posix.so' failed
make[5]: *** [lib/libopenssl_posix.so] Error 1
CMakeFiles/Makefile2:239: recipe for target 'platform/posix/transport/CMakeFiles/openssl_posix.dir/all' failed
make[4]: *** [platform/posix/transport/CMakeFiles/openssl_posix.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make[3]: *** [all] Error 2
package/pkg-generic.mk:247: recipe for target '/home/leizhou/workspace/rpi3-optee/out-br/build/aws_iotsdk_ext-1.0/.stamp_built' failed
make[2]: *** [/home/leizhou/workspace/rpi3-optee/out-br/build/aws_iotsdk_ext-1.0/.stamp_built] Error 2
Makefile:23: recipe for target '_all' failed
make[1]: *** [_all] Error 2
make[1]: Leaving directory '/home/leizhou/workspace/rpi3-optee/out-br'
common.mk:286: recipe for target 'buildroot' failed
make: *** [buildroot] Error 2

@yourslab
Copy link
Contributor

yourslab commented Nov 9, 2020

Hi Lei,

It looks like you are trying to link a static library to a shared library: libcrypto.a -> libopenssl_posix.so. This will only work if libcrypto.a from the OpenSSL library is compiled with -fPIC. You have the following options to fix this:

Option 1: Build CMake with the following flag: cmake .. -DBUILD_SHARED_LIBS=0. This will force all libraries to be built as static (i.e. .a extension) hence position independent code will no longer be required.
Option 2: Build libcrypto as a static library but with the -fPIC compiler flag, resulting in the file libcrypto.a.
Option 3: Build libcrypto as a shared library, resulting in the file libcrypto.so.

Option 1 is the easiest way to get around this problem while the other options may require you to build OpenSSL from source.
Feel free to reach out if you have any questions or encounter other issues.

@zlhk100
Copy link
Author

zlhk100 commented Nov 9, 2020

Thanks @yourslab for your prompt response and I will go with option 3 linking against libcrypto.so, which is already available.

Another designing question, is there any limitation we should be aware if using AWS IOT SDK as general purpose http client library?

Much appreciated!
Lei

@yourslab
Copy link
Contributor

yourslab commented Nov 9, 2020

There are certain features like streaming and pipelining that are not yet supported in the http client library. If your project does not require these features, then coreHTTP would be a suitable choice.

@yourslab
Copy link
Contributor

Seems there are no further queries so I will be closing this issue. Please feel free to reach out again.

@zlhk100
Copy link
Author

zlhk100 commented Nov 12, 2020

Thanks very much @yourslab for your support! Sorryfor late reply.

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