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

Link error in SPI when building for riscv (IDFGH-8720) #10161

Closed
3 tasks done
josesimoes opened this issue Nov 11, 2022 · 12 comments
Closed
3 tasks done

Link error in SPI when building for riscv (IDFGH-8720) #10161

josesimoes opened this issue Nov 11, 2022 · 12 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@josesimoes
Copy link
Contributor

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

I'm working on adding a build of .NET nanoFramework for ESP32_C3.

All good so far except that I'm running into an issue with SPI.

[build]     rtc_iram_seg:          40 B         8 KB      0.49e:/nftools/.espressif/tools/riscv32-esp-elf/esp-2021r2-patch5-8.4.0/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: esp-idf/driver/libdriver.a(spi_common.c.obj): in function `spicommon_periph_claim':
[build] E:/GitHub/esp-idf/components/driver/spi_common.c:108: undefined reference to `__atomic_compare_exchange_1'
[build] e:/nftools/.espressif/tools/riscv32-esp-elf/esp-2021r2-patch5-8.4.0/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: esp-idf/driver/libdriver.a(spi_common.c.obj): in function `spicommon_periph_free':
[build] E:/GitHub/esp-idf/components/driver/spi_common.c:127: undefined reference to `__atomic_compare_exchange_1'
[build] collect2.exe: error: ld returned 1 exit status
[build] %
[build] ninja: build stopped: subcommand failed.

I'm suspecting this is because we are calling SPI API from C++ code.
It's worth mentioning that the exact same code builds fine when builing for ESP32 and ESP32_S2.

I've searched around and found other reports of similiar issues with riscv.
Adding them here, for reference in case that's usefull:
telegramdesktop/tdesktop#17449
advancedtelematic/aktualizr#1427

Thanks!

@espressif-bot espressif-bot added the Status: Opened Issue is new label Nov 11, 2022
@github-actions github-actions bot changed the title Link error in SPI when building for riscv Link error in SPI when building for riscv (IDFGH-8720) Nov 11, 2022
@igrr
Copy link
Member

igrr commented Nov 11, 2022

Could you please try adding newlib to the PRIV_REQUIRES list here and see if that helps?

@josesimoes
Copy link
Contributor Author

Hey @igrr! I've tried that (on a clean build folder to be sure) and the error is the same...

@igrr
Copy link
Member

igrr commented Nov 11, 2022

Interesting, could you please check that the missing symbol is present in the object file?

riscv32-esp-elf-nm build/esp-idf/newlib/CMakeFiles/__idf_newlib.dir/stdatomic.c.obj | grep __atomic_compare_exchange_1

(not sure what's the equivalent of pipe & grep on Windows, sorry — the point is to see if the symbol name is present in riscv32-esp-elf-nm output)

@josesimoes
Copy link
Contributor Author

I believe the equivalent would be:
riscv32-esp-elf-nm build/esp-idf/newlib/CMakeFiles/__idf_newlib.dir/stdatomic.c.obj | findstr __atomic_compare_exchange_1

WIth and without newlib in the PRIV_REQUIRES the symbol is NOT present. (I can paste here the riscv32-esp-elf-nm output if that's of interest).

@igrr
Copy link
Member

igrr commented Nov 11, 2022

I see, then we are on to something. If the symbol is missing from the object file, then it explains why it is not found. Could you please attach or upload somewhere:

  • your project's sdkconfig file
  • output of riscv32-esp-elf-nm
  • build/compile_commands.json file

@igrr
Copy link
Member

igrr commented Nov 11, 2022

If the build is done by https://github.com/nanoframework/nf-interpreter/tree/main/CMake, then I think I might know where the issue is: your toolchain file https://github.com/nanoframework/nf-interpreter/blob/main/CMake/toolchain.riscv32-esp-elf.cmake doesn't specify correct compiler flags for ESP32-C3. There should be no -mlongcalls, but instead you should have -march=rv32imc (like here).

The files above can be used to confirm whether that's indeed the cause.

@josesimoes
Copy link
Contributor Author

Thanks for looking into that!
That was just a placeholder that was added when reworking the integration with IDF build system.
Here's the working branch: https://github.com/josesimoes/nf-interpreter/tree/develop-esp32-c3

@josesimoes
Copy link
Contributor Author

And yes, -mlongcalls have been removed 😉

@igrr
Copy link
Member

igrr commented Nov 11, 2022

Please check if adding -march=rv32imc to CMAKE_C_FLAGS and CMAKE_CXX_FLAGS of your toolchain file helps.

@josesimoes
Copy link
Contributor Author

@josesimoes
Copy link
Contributor Author

-march=rv32imc

@igrr brilliant!! That was it. It's building fine now!🥳
Thaaaaank you very much. 😃

@igrr
Copy link
Member

igrr commented Nov 11, 2022

Nice! Looking forward to the NanoFramework release for C3!

@espressif-bot espressif-bot added Resolution: Done Issue is done internally Status: Done Issue is done internally and removed Status: Opened Issue is new labels Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

3 participants