ockam
ockam copied to clipboard
Compatibility with IAR Embedded Workbench
Hi @mrinalwadhwa, can you please provide some details here? I may be able to help. I already have the toolchain and license. I just don't know what you want done exactly.
CLA Assistant Lite All Contributors have signed the CLA.
I have read the CLA Document and I hereby sign the CLA.
Hi @fkouteib 👋
Thank you for exploring the issues, signing the CLA and offering to help ❤️.
Here's the first thing to try:
If someone clones the repo and opens IAR Embedded Workbench in the C implementation directory ockam/implementations/c
. Does it pickup the CMake setup and build/test?
On the command line I would build as follows:
git clone [email protected]:ockam-network/ockam.git
cd ockam/implementations/c
cmake -G "Unix Makefiles" -S . -B build
cd build
make
ctest
Maybe we'll need to write a CMake toolchain file. If it doesn't build with the toolchain, then we'll want to identify what are the things we're doing that are incompatible with the IAR toolchain.
After we know that the above works, we can explore how to make libs from our rust code available to a C dev using IAR workbench.
Does it pickup the CMake setup and build/test?
No, not without adding a toolchain file.
Maybe we'll need to write a CMake toolchain file.
Yes. Done. PR will be up shortly after I post this comment.
If it doesn't build with the toolchain, then we'll want to identify what are the things we're doing that are incompatible with the IAR toolchain.
Compile errors. High level summary next, then verbose details.
High level summary: Certain C header files from C library were not found. So any invokations of functions depending on them failed at compile stage. I don't know why the files are missing, or where the disconnect is coming from. Also not the CMAKE warning about lack of support for dynamic linking. So it's forced/implied conversion to static linking for that library.
Environment: This was done on Windows 10, with IAR Embedded Workbench 8.32.1 for ARM, I used "MinGW" for makefile generation and execution. CMake 3.18.1. Full output below.
cmake output:
c:\Workspace\ockam\implementations\c>cmake -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain-iar-arm.cmake -S . -B build -- The C compiler identification is IAR ARM 8.32.1 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.2/arm/bin/iccarm.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- Looking for assert.h -- Looking for assert.h - found -- Looking for inttypes.h -- Looking for inttypes.h - found -- Looking for io.h -- Looking for io.h - not found -- Looking for malloc.h -- Looking for malloc.h - not found -- Looking for memory.h -- Looking for memory.h - not found -- Looking for setjmp.h -- Looking for setjmp.h - found -- Looking for signal.h -- Looking for signal.h - found -- Looking for stdarg.h -- Looking for stdarg.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for stdio.h -- Looking for stdio.h - found -- Looking for stdlib.h -- Looking for stdlib.h - found -- Looking for string.h -- Looking for string.h - found -- Looking for strings.h -- Looking for strings.h - not found -- Looking for sys/stat.h -- Looking for sys/stat.h - not found -- Looking for sys/types.h -- Looking for sys/types.h - not found -- Looking for time.h -- Looking for time.h - found -- Looking for unistd.h -- Looking for unistd.h - not found -- Performing Test HAVE_STRUCT_TIMESPEC -- Performing Test HAVE_STRUCT_TIMESPEC - Success -- Looking for calloc -- Looking for calloc - found -- Looking for exit -- Looking for exit - found -- Looking for fprintf -- Looking for fprintf - not found -- Looking for free -- Looking for free - found -- Looking for longjmp -- Looking for longjmp - found -- Looking for siglongjmp -- Looking for siglongjmp - not found -- Looking for malloc -- Looking for malloc - found -- Looking for memcpy -- Looking for memcpy - found -- Looking for memset -- Looking for memset - found -- Looking for printf -- Looking for printf - not found -- Looking for setjmp -- Looking for setjmp - found -- Looking for signal -- Looking for signal - found -- Looking for strsignal -- Looking for strsignal - not found -- Looking for strcmp -- Looking for strcmp - found -- Looking for clock_gettime -- Looking for clock_gettime - not found -- Looking for sprintf -- Looking for sprintf - found -- Looking for vsnprintf -- Looking for vsnprintf - found -- Performing Test HAVE_GCC_THREAD_LOCAL_STORAGE -- Performing Test HAVE_GCC_THREAD_LOCAL_STORAGE - Failed -- Check if the system is big endian -- Searching 16 bit integer -- Check size of unsigned short -- Check size of unsigned short - done -- Searching 16 bit integer - Using unsigned short -- Check if the system is big endian - little endian CMake Warning (dev) at build/_deps/cmocka-src/src/CMakeLists.txt:34 (add_library): ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking. Building a STATIC library instead. This may lead to problems. This warning is for project developers. Use -Wno-dev to suppress it. -- Found Doxygen: C:/Program Files/doxygen/bin/doxygen.exe (found version "1.8.20 (f246dd2f1c58eea39ea3f50c108019e4d4137bd5)") found components: doxygen missing components: dot CMake Warning (dev) at build/_deps/cryptoauthlib-src/CMakeLists.txt:2 (project): Policy CMP0048 is not set: project() command manages VERSION variables. Run "cmake --help-policy CMP0048" for policy details. Use the cmake_policy command to set the policy and suppress this warning. The following variable(s) would be set to empty: PROJECT_VERSION PROJECT_VERSION_MAJOR PROJECT_VERSION_MINOR PROJECT_VERSION_PATCH This warning is for project developers. Use -Wno-dev to suppress it. -- The CXX compiler identification is IAR ARM 8.32.1 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.2/arm/bin/iccarm.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Building Configuration: -- C:/Workspace/ockam/implementations/c/build/ockam/log/include -- Log is enabled -- Custom logging is disabled -- Configuring done -- Generating done -- Build files have been written to: C:/Workspace/ockam/implementations/c/build
Compile output:
C:\Workspace\ockam\implementations\c\build>mingw32-make Scanning dependencies of target bearssl [ 0%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/aead/gcm.c.obj [ 1%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/codec/ccopy.c.obj [ 1%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/codec/dec32be.c.obj [ 2%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/codec/enc32be.c.obj [ 2%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/ec/ec_c25519_i31.c.obj [ 3%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/ec/ec_curve25519.c.obj [ 4%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/ec/ec_keygen.c.obj [ 4%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/ec/ec_p256_m31.c.obj [ 5%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/ec/ec_pubkey.c.obj [ 5%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/hash/sha2small.c.obj [ 6%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/hash/ghash_ctmul32.c.obj [ 6%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/int/i31_add.c.obj [ 7%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/int/i31_decmod.c.obj [ 8%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/int/i31_encode.c.obj [ 8%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/int/i31_montmul.c.obj [ 9%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/int/i31_sub.c.obj [ 9%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/kdf/hkdf.c.obj [ 10%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/mac/hmac.c.obj [ 10%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/rand/hmac_drbg.c.obj [ 11%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/symcipher/aes_ct.c.obj [ 12%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/symcipher/aes_ct_ctr.c.obj [ 12%] Building C object external/bearssl/CMakeFiles/bearssl.dir///_deps/bearssl-src/src/symcipher/aes_ct_enc.c.obj [ 13%] Linking C static library libbearssl.a [ 13%] Built target bearssl Scanning dependencies of target ockam_log [ 13%] Building C object ockam/log/CMakeFiles/ockam_log.dir/log.c.obj fprintf(stdout, "%s %-11s %s:%d: ", time_str, level_strings[level], file, line); ^ "C:\Workspace\ockam\implementations\c\ockam\log\log.c",30 Warning[Pe223]: function "fprintf" declared implicitly fprintf(stdout, "%s %-11s %s:%d: ", time_str, level_strings[level], file, line); ^ "C:\Workspace\ockam\implementations\c\ockam\log\log.c",30 Error[Pe020]: identifier "stdout" is undefined vfprintf(stdout, fmt, args); ^ "C:\Workspace\ockam\implementations\c\ockam\log\log.c",31 Warning[Pe223]: function "vfprintf" declared implicitly fflush(stdout); ^ "C:\Workspace\ockam\implementations\c\ockam\log\log.c",34 Warning[Pe223]: function "fflush" declared implicitly ockam\log\CMakeFiles\ockam_log.dir\build.make:80: recipe for target 'ockam/log/CMakeFiles/ockam_log.dir/log.c.obj' failed mingw32-make[2]: *** [ockam/log/CMakeFiles/ockam_log.dir/log.c.obj] Error 2 CMakeFiles\Makefile2:1813: recipe for target 'ockam/log/CMakeFiles/ockam_log.dir/all' failed mingw32-make[1]: *** [ockam/log/CMakeFiles/ockam_log.dir/all] Error 2 Makefile:168: recipe for target 'all' failed mingw32-make: *** [all] Error 2
HI @mrinalwadhwa I can't push my local branch to your repo. I am trying to put up PR for the toolchain files change made to get the above results. Thanks.
Great. The above log is very helpful 🙏
Thank you for working on the PR for a toolchain file.
Please add it to implementations/c/cmake/toolchain/
To create a PR, you can use the "Fork and Pull Request" workflow. Here are a few guides on that from github
- https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/about-collaborative-development-models
- https://guides.github.com/activities/forking/
- https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork
I onion peeled this further by commenting out compile errors as I go to see the next set of failures. Below is my attempt at bucketizing compile errors as you evaluate how you want to holistically address compatibility and conformance to different compilers in the c code base going forward.
OCKAM_*_ERROR_DOMAIN "C:\Workspace\ockam\implementations\c<blah>.c",7 Error[Pe028]: expression must have a constant value
Several instances of this in code base all following the same convention. const char* const assigned into an enum.
File I/O function related errors
These are related to missing headers identified by cmake. Also these cause 1/3 external libraries (cmocka) not to build. The other two build just fine.
POSIX threads and POSIX sockets
I don't belive IAR supports POSIX without RTOS. From quick search, I did, this https://www.iar.com/support/tech-notes/compiler/managing-a-multithreaded-environment/ is what turned up. This also covers the mutex and queue implementations.
includes [<unistd.h>; <sys/types.h>; <fcntl.h>; <arpa/inet.h>; <netdb.h>; <netinet/in.h>; <netinet/tcp.h>; <sys/socket.h>;
Can't find matching headers in IAR provided C headers.
exit labels that are have no goto that branches to them.
This seems like functions that were made consistently with expectation you may later add goto logic, or followed blueprint and didnt need them.
Beyond these issues which IAR compiler treated like errors, there are warnings for variables declared and never used. Local variables that get initialized after some goto statement and may go uninitialized in some cases.
In terms of linking, this is really odd but IAR basically built each module it compiled into a static library but did not generate any executables. I suspect this may have to do with cmake warnings about converting dynamically linked libraries to static and its inadvertant effects.
Lastly, in 'implementations/c/ockam/key_agreement/xx/xx_initiator.c', xx_initiator_m3_make(), local var 'u_int16_t offset = 0;' that 's a typo/compile bug uint16_t has an extra underscore.