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

Unknown target cpu : xtensa-esp32s3-espidf #2088

Open
lorenzo-pirchio opened this issue Jun 6, 2024 · 14 comments
Open

Unknown target cpu : xtensa-esp32s3-espidf #2088

lorenzo-pirchio opened this issue Jun 6, 2024 · 14 comments

Comments

@lorenzo-pirchio
Copy link

lorenzo-pirchio commented Jun 6, 2024

Hi,
I'm working on a project on esp32s3, I need to use rustls but I have problems with the ring crate since xtensa is not supported .
I'm using the esp32-idf-template (https://github.com/esp-rs/esp-idf-template), and I changed the depedencies adding the ones I needed.
As suggested by @briansmith, I am using the latest commit on the main branch, checking if there is this change (ed5b2a8), but It still doesn't work.
To be sure that I was using the latest commit, I downloaded the repo and added it as a local dependency.

This is my cargo.toml:

`[package]
name = "s3_rust"
version = "0.1.0"
edition = "2021"
resolver = "2"
rust-version = "1.71"

[[bin]]
name = "s3_rust"
harness = false # do not use the built in cargo test harness -> resolve rust-analyzer errors

[profile.release]
opt-level = "s"

[profile.dev]
debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"

[features]
default = ["std", "embassy", "esp-idf-svc/native"]

pio = ["esp-idf-svc/pio"]
std = ["alloc", "esp-idf-svc/binstart", "esp-idf-svc/std"]
alloc = ["esp-idf-svc/alloc"]
nightly = ["esp-idf-svc/nightly"]
experimental = ["esp-idf-svc/experimental"]
embassy = ["esp-idf-svc/embassy-sync", "esp-idf-svc/critical-section", "esp-idf-svc/embassy-time-driver"]

[dependencies]
log = { version = "0.4", default-features = false }
esp-idf-svc = { version = "0.48", default-features = false }

[target.'cfg(target_os="espidf")'.dependencies]
ring = {path="C:/ring-main/ring-main", features =[ "less-safe-getrandom-espidf"] }
rustls = { version = "0.23.7", default-features = false, features = ["ring", "logging", "std", "tls12"] }

[build-dependencies]
embuild = "0.31.3"
`

This is my config.toml:
`[build]
target = "xtensa-esp32s3-espidf"

[target.xtensa-esp32s3-espidf]
linker = "ldproxy"
runner = "espflash flash --monitor" # Select this runner for espflash v2.x.x
rustflags = [ "--cfg", "espidf_time64"] # Extending time_t for ESP IDF 5: esp-rs/rust#110

[unstable]
build-std = ["std", "panic_abort"]

[env]
MCU="esp32s3"
ESP_IDF_VERSION = "v5.1.3"
CRATE_CC_NO_DEFAULTS = "1"
`

This is what I get when I do cargo build:

warning: [email protected]: cc1.exe: warning: C:\ring-main\ring-main\pregenerated: No such file or directory [-Wmissing-include-dirs]
warning: [email protected]: In file included from C:\ring-main\ring-main\include/ring-core/base.h:74,
warning: [email protected]: from C:\ring-main\ring-main\include/ring-core/mem.h:60,
warning: [email protected]: from C:\ring-main\ring-main\crypto/curve25519/curve25519.c:22:
warning: [email protected]: C:\ring-main\ring-main\include/ring-core/target.h:53:2: error: #error "Unknown target CPU"
warning: [email protected]: 53 | #error "Unknown target CPU"
warning: [email protected]: | ^~~~~
warning: [email protected]: C:\ring-main\ring-main\include/ring-core/base.h:76:10: fatal error: ring_core_generated/prefix_symbols.h: No such file or directory
warning: [email protected]: 76 | #include <ring_core_generated/prefix_symbols.h>
warning: [email protected]: | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: [email protected]: compilation terminated.

If any of you know what is the problem, please help me.
Thanks

@lorenzo-pirchio lorenzo-pirchio changed the title Unsupported cpu : xtensa-esp32s3-espidf Unknown target cpu : xtensa-esp32s3-espidf Jun 6, 2024
@briansmith
Copy link
Owner

This is what I get when I do cargo build:

warning: [email protected]: cc1.exe: warning: C:\ring-main\ring-main\pregenerated: No such file or directory [-Wmissing-include-dirs]

It looks like you're building ring from source, but not from within a Git checkout. Thus, build.rs doesn't see .git/ and so it is expecting some files in pregenerated/. But they are not there, because they only exist in the package that's uploaded to crates.io.

cargo build

What is the exact command line of cargo build. As you can see in BUILDING.md, you need to set TARGET_CC and TARGET_AR to the correct C compiler.

@lorenzo-pirchio
Copy link
Author

lorenzo-pirchio commented Jun 7, 2024

Everytime I set from cmd:

  • CARGO_TARGET_DIR
  • CC to MinGW\bin\gcc.exe
  • TARGET_CC to xtensa-esp32s3-elf-gcc.exe
  • TARGET_AR to xtensa-esp32s3-elf-ar.exe

And finally I do cargo build.
I changed the dependencies in cargo.toml adding ring={git="https://github.com/briansmith/ring.git", features =[ "less-safe-getrandom-espidf"]} but I have all these warnings.

warning: [email protected]: In file included from C:\Users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\include/ring-core/base.h:74,
warning: [email protected]: from C:\Users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\include/ring-core/mem.h:60,
warning: [email protected]: from C:\Users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto/curve25519/curve25519.c:22:
warning: [email protected]: C:\Users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\include/ring-core/target.h:53:2: error: #error "Unknown target CPU"
warning: [email protected]: #error "Unknown target CPU"
warning: [email protected]: ^~~~~
warning: [email protected]: In file included from C:\Users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto/curve25519/internal.h:20,
warning: [email protected]: from C:\Users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto/curve25519/curve25519.c:24:
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:219:2: error: #error "Must define either OPENSSL_32_BIT or OPENSSL_64_BIT"
warning: [email protected]: #error "Must define either OPENSSL_32_BIT or OPENSSL_64_BIT"
warning: [email protected]: ^~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:232:15: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t value_barrier_w(crypto_word_t a) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:232:45: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t value_barrier_w(crypto_word_t a) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:244:15: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t constant_time_msb_w(crypto_word_t a) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:244:49: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t constant_time_msb_w(crypto_word_t a) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:249:15: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t constant_time_is_zero_w(crypto_word_t a) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:249:53: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t constant_time_is_zero_w(crypto_word_t a) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:264:15: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t constant_time_is_nonzero_w(crypto_word_t a) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:264:56: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t constant_time_is_nonzero_w(crypto_word_t a) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:269:15: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t constant_time_eq_w(crypto_word_t a,
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:269:48: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t constant_time_eq_w(crypto_word_t a,
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:270:48: error: unknown type name 'crypto_word_t'
warning: [email protected]: crypto_word_t b) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:277:15: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t constant_time_select_w(crypto_word_t mask,
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:277:52: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t constant_time_select_w(crypto_word_t mask,
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:278:52: error: unknown type name 'crypto_word_t'
warning: [email protected]: crypto_word_t a,
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:279:52: error: unknown type name 'crypto_word_t'
warning: [email protected]: crypto_word_t b) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:291:46: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline uint8_t constant_time_select_8(crypto_word_t mask, uint8_t a,
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:308:59: error: unknown type name 'crypto_word_t'
warning: [email protected]: const crypto_word_t mask) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h: In function 'constant_time_conditional_memcpy':
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:313:14: error: implicit declaration of function 'constant_time_select_8'; did you mean 'bssl_constant_time_test_main'? [-Werror=implicit-function-declaration]
warning: [email protected]: out[i] = constant_time_select_8(mask, in[i], out[i]);
warning: [email protected]: ^~~~~~~~~~~~~~~~~~~~~~
warning: [email protected]: bssl_constant_time_test_main
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:313:14: error: nested extern declaration of 'constant_time_select_8' [-Werror=nested-externs]
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h: At top level:
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:322:59: error: unknown type name 'crypto_word_t'
warning: [email protected]: const crypto_word_t mask) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h: In function 'constant_time_conditional_memxor':
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:327:15: error: implicit declaration of function 'value_barrier_w' [-Werror=implicit-function-declaration]
warning: [email protected]: out[i] ^= value_barrier_w(mask) & in[i];
warning: [email protected]: ^~~~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:327:15: error: nested extern declaration of 'value_barrier_w' [-Werror=nested-externs]
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h: At top level:
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:359:15: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t constant_time_declassify_w(crypto_word_t v) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: c:\users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto\internal.h:359:56: error: unknown type name 'crypto_word_t'
warning: [email protected]: static inline crypto_word_t constant_time_declassify_w(crypto_word_t v) {
warning: [email protected]: ^~~~~~~~~~~~~
warning: [email protected]: C:\Users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto/curve25519/curve25519.c: In function 'x25519_ge_scalarmult_small_precomp':
warning: [email protected]: C:\Users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto/curve25519/curve25519.c:721:35: error: implicit declaration of function 'constant_time_eq_w'; did you mean 'bssl_constant_time_test_main'? [-Werror=implicit-function-declaration]
warning: [email protected]: cmov(&e, &multiples[j-1], 1&constant_time_eq_w(index, j));
warning: [email protected]: ^~~~~~~~~~~~~~~~~~
warning: [email protected]: bssl_constant_time_test_main
warning: [email protected]: C:\Users\lpirc.cargo\git\checkouts\ring-51509f604a4fd25b\70b59d6\crypto/curve25519/curve25519.c:721:35: error: nested extern declaration of 'constant_time_eq_w' [-Werror=nested-externs]
warning: [email protected]: cc1.exe: all warnings being treated as errors

error: failed to run custom build command for ring v0.17.8 (https://github.com/briansmith/ring.git#70b59d6e)

It's the same error as #2008 (comment)

@briansmith
Copy link
Owner

What does xtensa-esp32s3-elf-gcc.exe --version output?

@lorenzo-pirchio
Copy link
Author

This is xtensa-esp32s3-elf-gcc.exe --version output:

xtensa-esp32s3-elf-gcc.exe (crosstool-NG esp-2021r2-patch5) 8.4.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I added this to target.h:
#elif defined(XTENSA)
#define OPENSSL_32_BIT

Now, when I compile it, I don't get any errors or warnings, but I don't know actually if it will work fine.

@briansmith
Copy link
Owner

In target.h, you can see:

// Versions of GCC before 10.0 didn't define `__ILP32__` for all 32-bit targets.
#elif defined(__MIPSEL__) || defined(__MIPSEB__) || defined(__PPC__) || defined(__powerpc__) || defined(__csky__)
#define OPENSSL_32_BIT

Ideally, you would upgrade to a newer version of GCC. Then it should "just work." Otherwise, you can find out what symbol to add to the above #elif and add it for xtensa. Note XTENSA isn't the right thing; the symbol we're looking for will start with '__' like the others in the list.

@lorenzo-pirchio
Copy link
Author

Yes, I wrote Xtensa with '__' as the beginning and end as you said, but in markdown double underscores are used to format text as bold, as you can see in the previous message.

@briansmith
Copy link
Owner

OK, it looks like somebody just needs to submit the PR.

@lorenzo-pirchio
Copy link
Author

Do you want me to submit a PR with the lines I added for xtensa?

@briansmith
Copy link
Owner

#elif defined(__MIPSEL__) || defined(__MIPSEB__) || defined(__PPC__) || defined(__powerpc__) || defined(__csky__)

^ Please extend that line.

Incidentally, is there no newer version of the xtensa SDK that lets you use GCC 10 or higher?

@lorenzo-pirchio
Copy link
Author

I changed to GCC 12 because now I'm using esp-idf 5.1, which requires GCC 12.
But unfortunately I have problems with the linker and I have errors about ring.
Here they are:
Errors.txt
I have been trying to find possible solutions but I'm stuck doint this for a week.
If you have any suggestion, I'd be thankful to you.

@briansmith
Copy link
Owner

I changed to GCC 12 because now I'm using esp-idf 5.1, which requires GCC 12.
But unfortunately I have problems with the linker and I have errors about ring.
Here they are:
Errors.txt
I have been trying to find possible solutions but I'm stuck doint this for a week.
If you have any suggestion, I'd be thankful to you.

https://www.esp32.com/viewtopic.php?t=1612 and other things seem to say that you may need CFLAGS=-mlongcalls when invoking cargo?

@juliankrieger
Copy link
Contributor

@briansmith since I can't find a PR from @lorenzo-pirchio , I will create one myself.

Furthermore, I'm on GCC V 13 (via crosstools) and still encounter the same error.

@juliankrieger
Copy link
Contributor

@briansmith I can confirm building works with

  • espup install (installs toolchains for esp32)
  • the recent patch
  • The following .cargo/config.toml section:
TARGET_CC="xtensa-esp32s3-elf-cc"
TARGET_AR="xtensa-esp32s3-elf-ar"
TARGET_CFLAGS="-mlongcalls"

@ealinye
Copy link

ealinye commented Nov 2, 2024

im also trying to build rustls with ring on esp32, here is a fragment of my Cargo.toml file

[dependencies]
log = { version = "0.4", default-features = false }
esp-idf-svc = { version = "0.49", default-features = false }
h3-shim = { git = "https://github.com/ealinye/gm-quic.git" }
bytes = "1"
futures = "0.3"
tokio = { version = "1", features = ["rt"] }
ring = { version = "0.17.8", features = ["less-safe-getrandom-espidf"] }

[dependencies.rustls]
version = "0.23"
default-features = false
features = ["std", "ring"]

# [dependencies.reqwest]
# git = "https://github.com/ealinye/reqwest.git"
# default-features = false
# features = ["http3"]
# branch = "ealinye"

[patch.crates-io]
ring = { git = "https://github.com/briansmith/ring.git" }
rustls = { git = "https://github.com/rustls/rustls.git" }

[build-dependencies]
embuild = "0.32.0"

But the error i met is different with you, it seems a internal error of conpiler?

error: Undefined temporary symbol .LBB113_16

error: could not compile `rustls` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...

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

4 participants