DMTF / libspdm

BSD 3-Clause "New" or "Revised" License
104 stars 100 forks source link

Build Error cmake/GCC #2584

Open marinuswhite opened 7 months ago

marinuswhite commented 7 months ago

Hello,

I'd like to test SPDM on a Nvidia Jetzson Orin (ARM 64, native Ubuntu).

I followed the instruction steps

=> gcc: error: unrecognized command line option ‘-maccumulate-outgoing-args’ gcc: error: unrecognized command line option ‘-mno-red-zone’ make[2]: [out/cryptlib_mbedtls.out/CMakeFiles/cryptlib_mbedtls.dir/build.make:63: out/cryptlib_mbedtls.out/CMakeFiles/cryptlib_mbedtls.dir/cipher/aead_aes_gcm.c.o] Error 1 make[1]: [CMakeFiles/Makefile2:922: out/cryptlib_mbedtls.out/CMakeFiles/cryptlib_mbedtls.dir/all] Error 2 make: *** [Makefile:130: all] Error 2

Tried it several times with different settings, always ends there

May I have overseen something?

Thank you!

steven-bellock commented 7 months ago

@twilfredo or @alistair23 might know. I can look at it more when I get access to an Orin system.

twilfredo commented 7 months ago

I haven't come across this before, but those options ( -maccumulate-outgoing-args & mno-red-zone) don't seem to be specified for aarch64?

marinuswhite commented 7 months ago

I tried both arm and aarch64, both ended with the mentioned error

alistair23 commented 7 months ago

no-red-zone is only added for x86 and accumulate-outgoing-args is similar (x64 or ia32), so you are building for the wrong architecture.

How did you install ARM_GNU? Are you able to provide the full logs from cmake and make?

dhopf commented 7 months ago

@alistair23 (I'm a colleague of @marinuswhite) I think we didn't specifically install something in addition on the NVIDIA Orin. Since the Orin is an arm64 (or - as far as I understood - alternatively named aarch64) architecture, we assumed the standard toolchain should be the arm one compiling for that target architecture. I'm not at the device currently, but I can look into providing you with the output later this week.

steven-bellock commented 7 months ago

If this is Linux on native aarch64 then you'd use

cmake -DARCH=aarch64 -DTOOLCHAIN=GCC -DTARGET=Release -DCRYPTO=mbedtls ..

dhopf commented 7 months ago

Thanks @steven-bellock, that helped greatly.

This combination unfortunately is not described in build.md. "Build Tools for Linux" in fact states subitem e) with AARCH64 GCC for AARCH64 only

sudo apt-get install gcc-aarch64-linux-gnu but in the subsequent "Linux Builds for ARM/AARCH64" section, there is no mention of For ARM GCC build (aarch64) on Linux I may create a pull request for that after we verified the correct workflow.

Regarding the actual build

It seems it almost worked. At the end however, I get the following linker error - full logfile (I used openssl als crypto lib, but I hope this shouldn't matter):

Scanning dependencies of target test_size_of_spdm_requester
[ 99%] Building C object unit_test/test_size/test_size_of_spdm_r
[build-output-libspdm.log](https://github.com/DMTF/libspdm/files/14430330/build-output-libspdm.log)
equester/CMakeFiles/test_size_of_spdm_requester.dir/spdm_requester_authentication.c.o
[ 99%] Building C object unit_test/test_size/test_size_of_spdm_requester/CMakeFiles/test_size_of_spdm_requester.dir/spdm_requester_init.c.o
[ 99%] Building C object unit_test/test_size/test_size_of_spdm_requester/CMakeFiles/test_size_of_spdm_requester.dir/spdm_requester_main.c.o
[ 99%] Building C object unit_test/test_size/test_size_of_spdm_requester/CMakeFiles/test_size_of_spdm_requester.dir/spdm_requester_session.c.o
[ 99%] Building C object unit_test/test_size/test_size_of_spdm_requester/CMakeFiles/test_size_of_spdm_requester.dir/support.c.o
[ 99%] Linking C executable ../../../bin/test_size_of_spdm_requester
/usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/9/../../../aarch64-linux-gnu/crt1.o: in function `__wrap_main':
(.text+0x38): undefined reference to `main'
collect2: error: ld returned 1 exit status
make[2]: *** [unit_test/test_size/test_size_of_spdm_requester/CMakeFiles/test_size_of_spdm_requester.dir/build.make:156: bin/test_size_of_spdm_requester] Error 1
make[1]: *** [CMakeFiles/Makefile2:5342: unit_test/test_size/test_size_of_spdm_requester/CMakeFiles/test_size_of_spdm_requester.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
-(user@user-orin1:0)-(9 files:120K@build)-(0 jobs)-(08:18)-
-(~/libspdm/build:$)-> 

I didn't check yet if the other executables work fine - those apparently compiled & linked without errors.

steven-bellock commented 7 months ago

See #612 for discussion on build parameters and native / cross compilation. Also, https://github.blog/changelog/2023-10-30-accelerate-your-ci-cd-with-arm-based-hosted-runners-in-github-actions/ may come to free GitHub users so we can add that to CI/CD.

I'll file an issue for the test_size_of_ build error. The other tests will run fine.

dhopf commented 7 months ago

I can confirm that I successfully built it on my NVIDIA Jetson AGX Orin Developer Kit. Inside the created build directory, I issued:

cmake -DARCH=aarch64 -DTOOLCHAIN=GCC -DTARGET=Release -DCRYPTO=openssl ..
make copy_sample_key
make -j12

Thanks @steven-bellock for the swift fixing!

jyao1 commented 7 months ago

Is there anything for this issue? Can we close this one?

steven-bellock commented 7 months ago

The build documentation needs to be clarified, as it is focused on cross-compilation. I can update that.