LedgerHQ / app-boilerplate-rust

Rust boilerplate application for Ledger Nano S+/X, Stax and Flex
Apache License 2.0
39 stars 28 forks source link

error: cx_aes_enc_block changed binding to STB_GLOBAL #14

Closed Thegaram closed 2 years ago

Thegaram commented 2 years ago

Hi, thank you for providing this project.

I tried building on Mac but I'm getting the following error. I was wondering if you could give some pointers as to how to resolve this.

error: failed to run custom build command for `nanos_sdk v0.1.0 (https://github.com/LedgerHQ/ledger-nanos-sdk.git#427e686d)`

Caused by:
  process didn't exit successfully: `/Users/user/rust-app/target/debug/build/nanos_sdk-c407dcfe889b4bf1/build-script-build` (exit status: 1)
  --- stdout
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-apple-darwin")
  CFLAGS_thumbv6m-none-eabi = None
  CFLAGS_thumbv6m_none_eabi = None
  TARGET_CFLAGS = None
  CFLAGS = None
  Info: default compiler flags are disabled
  running: "clang" "-I" "/Applications/ARM/bin/../arm-none-eabi/include" "-I" "./nanos-secure-sdk/include" "-I" "./nanos-secure-sdk/lib_stusb" "-I" "./nanos-secure-sdk/lib_stusb_impl" "-I" "./nanos-secure-sdk/lib_cxng/include" "-I" "./nanos-secure-sdk/lib_stusb/STM32_USB_Device_Library/Core/Inc" "-I" "./nanos-secure-sdk/lib_stusb/STM32_USB_Device_Library/Class/HID/Inc" "-Wall" "-Wextra" "-fropi" "--target=thumbv6m-none-eabi" "-fomit-frame-pointer" "-mcpu=cortex-m0" "-fno-common" "-fdata-sections" "-ffunction-sections" "-mtune=cortex-m0" "-mthumb" "-fno-jump-tables" "-fno-builtin" "-fshort-enums" "-mno-unaligned-access" "-Wno-unused-command-line-argument" "-Wno-missing-declarations" "-Wno-unused-parameter" "-Wno-implicit-fallthrough" "-Wno-sign-compare" "-Wno-unknown-pragmas" "-Wno-unknown-attributes" "-Wno-pointer-sign" "-Wno-implicit-function-declaration" "-Wno-tautological-pointer-compare" "-Wno-incompatible-pointer-types-discards-qualifiers" "-Wno-duplicate-decl-specifier" "-Wno-#warnings" "-Wno-int-conversion" "-DST31" "-DHAVE_LOCAL_APDU_BUFFER" "-DIO_HID_EP_LENGTH=64" "-DUSB_SEGMENT_SIZE=64" "-DOS_IO_SEPROXYHAL" "-DHAVE_IO_USB" "-DHAVE_L4_USBLIB" "-DHAVE_USB_APDU" "-DIO_USB_MAX_ENDPOINTS=6" "-DIO_SEPROXYHAL_BUFFER_SIZE_B=128" "-DHAVE_NES_CRYPT" "-DHAVE_ST_EDES_PLUS" "-DHAVE_ST_AES" "-DHAVE_CRC" "-DHAVE_HASH" "-DHAVE_RIPEMD160" "-DHAVE_SHA224" "-DHAVE_SHA256" "-DHAVE_SHA3" "-DHAVE_SHA384" "-DHAVE_SHA512" "-DHAVE_SHA512_WITH_BLOCK_ALT_METHOD" "-DHAVE_SHA512_WITH_BLOCK_ALT_METHOD_M0" "-DHAVE_BLAKE2" "-DHAVE_GROESTL" "-DHAVE_HMAC" "-DHAVE_PBKDF2" "-DHAVE_DES" "-DHAVE_AES" "-DHAVE_MATH" "-DHAVE_RNG" "-DHAVE_RNG_RFC6979" "-DHAVE_RNG_SP800_90A" "-DHAVE_ECC" "-DHAVE_ECC_WEIERSTRASS" "-DHAVE_ECC_TWISTED_EDWARDS" "-DHAVE_ECC_MONTGOMERY" "-DHAVE_SECP256K1_CURVE" "-DHAVE_SECP256R1_CURVE" "-DHAVE_SECP384R1_CURVE" "-DHAVE_SECP521R1_CURVE" "-DHAVE_FR256V1_CURVE" "-DHAVE_STARK256_CURVE" "-DHAVE_BLS12_381_G1_CURVE" "-DHAVE_BRAINPOOL_P256R1_CURVE" "-DHAVE_BRAINPOOL_P256T1_CURVE" "-DHAVE_BRAINPOOL_P320R1_CURVE" "-DHAVE_BRAINPOOL_P320T1_CURVE" "-DHAVE_BRAINPOOL_P384R1_CURVE" "-DHAVE_BRAINPOOL_P384T1_CURVE" "-DHAVE_BRAINPOOL_P512R1_CURVE" "-DHAVE_BRAINPOOL_P512T1_CURVE" "-DHAVE_CV25519_CURVE" "-DHAVE_CV448_CURVE" "-DHAVE_ED25519_CURVE" "-DHAVE_ED448_CURVE" "-DHAVE_ECDH" "-DHAVE_ECDSA" "-DHAVE_EDDSA" "-DHAVE_ECSCHNORR" "-o" "/Users/user/rust-app/target/thumbv6m-none-eabi/debug/build/nanos_sdk-94d749e18da4553f/out/./src/c/src.o" "-c" "./src/c/src.c"
  exit status: 0
  ...
  Info: default compiler flags are disabled
  running: "clang" "-I" "/Applications/ARM/bin/../arm-none-eabi/include" "-I" "./nanos-secure-sdk/include" "-I" "./nanos-secure-sdk/lib_stusb" "-I" "./nanos-secure-sdk/lib_stusb_impl" "-I" "./nanos-secure-sdk/lib_cxng/include" "-I" "./nanos-secure-sdk/lib_stusb/STM32_USB_Device_Library/Core/Inc" "-I" "./nanos-secure-sdk/lib_stusb/STM32_USB_Device_Library/Class/HID/Inc" "-Wall" "-Wextra" "-fropi" "--target=thumbv6m-none-eabi" "-fomit-frame-pointer" "-mcpu=cortex-m0" "-fno-common" "-fdata-sections" "-ffunction-sections" "-mtune=cortex-m0" "-mthumb" "-fno-jump-tables" "-fno-builtin" "-fshort-enums" "-mno-unaligned-access" "-Wno-unused-command-line-argument" "-Wno-missing-declarations" "-Wno-unused-parameter" "-Wno-implicit-fallthrough" "-Wno-sign-compare" "-Wno-unknown-pragmas" "-Wno-unknown-attributes" "-Wno-pointer-sign" "-Wno-implicit-function-declaration" "-Wno-tautological-pointer-compare" "-Wno-incompatible-pointer-types-discards-qualifiers" "-Wno-duplicate-decl-specifier" "-Wno-#warnings" "-Wno-int-conversion" "-DST31" "-DHAVE_LOCAL_APDU_BUFFER" "-DIO_HID_EP_LENGTH=64" "-DUSB_SEGMENT_SIZE=64" "-DOS_IO_SEPROXYHAL" "-DHAVE_IO_USB" "-DHAVE_L4_USBLIB" "-DHAVE_USB_APDU" "-DIO_USB_MAX_ENDPOINTS=6" "-DIO_SEPROXYHAL_BUFFER_SIZE_B=128" "-DHAVE_NES_CRYPT" "-DHAVE_ST_EDES_PLUS" "-DHAVE_ST_AES" "-DHAVE_CRC" "-DHAVE_HASH" "-DHAVE_RIPEMD160" "-DHAVE_SHA224" "-DHAVE_SHA256" "-DHAVE_SHA3" "-DHAVE_SHA384" "-DHAVE_SHA512" "-DHAVE_SHA512_WITH_BLOCK_ALT_METHOD" "-DHAVE_SHA512_WITH_BLOCK_ALT_METHOD_M0" "-DHAVE_BLAKE2" "-DHAVE_GROESTL" "-DHAVE_HMAC" "-DHAVE_PBKDF2" "-DHAVE_DES" "-DHAVE_AES" "-DHAVE_MATH" "-DHAVE_RNG" "-DHAVE_RNG_RFC6979" "-DHAVE_RNG_SP800_90A" "-DHAVE_ECC" "-DHAVE_ECC_WEIERSTRASS" "-DHAVE_ECC_TWISTED_EDWARDS" "-DHAVE_ECC_MONTGOMERY" "-DHAVE_SECP256K1_CURVE" "-DHAVE_SECP256R1_CURVE" "-DHAVE_SECP384R1_CURVE" "-DHAVE_SECP521R1_CURVE" "-DHAVE_FR256V1_CURVE" "-DHAVE_STARK256_CURVE" "-DHAVE_BLS12_381_G1_CURVE" "-DHAVE_BRAINPOOL_P256R1_CURVE" "-DHAVE_BRAINPOOL_P256T1_CURVE" "-DHAVE_BRAINPOOL_P320R1_CURVE" "-DHAVE_BRAINPOOL_P320T1_CURVE" "-DHAVE_BRAINPOOL_P384R1_CURVE" "-DHAVE_BRAINPOOL_P384T1_CURVE" "-DHAVE_BRAINPOOL_P512R1_CURVE" "-DHAVE_BRAINPOOL_P512T1_CURVE" "-DHAVE_CV25519_CURVE" "-DHAVE_CV448_CURVE" "-DHAVE_ED25519_CURVE" "-DHAVE_ED448_CURVE" "-DHAVE_ECDH" "-DHAVE_ECDSA" "-DHAVE_EDDSA" "-DHAVE_ECSCHNORR" "-o" "/Users/user/rust-app/target/thumbv6m-none-eabi/debug/build/nanos_sdk-94d749e18da4553f/out/./nanos-secure-sdk/src/cx_stubs.o" "-c" "./nanos-secure-sdk/src/cx_stubs.S"
  cargo:warning=<instantiation>:4:5: error: cx_aes_dec_block changed binding to STB_GLOBAL
  cargo:warning=    .global cx_aes_dec_block
  cargo:warning=    ^
  cargo:warning=<instantiation>:4:5: error: cx_aes_enc_block changed binding to STB_GLOBAL
  cargo:warning=    .global cx_aes_enc_block
  cargo:warning=    ^
  cargo:warning=<instantiation>:4:5: error: cx_aes_init_key_no_throw changed binding to STB_GLOBAL
  cargo:warning=    .global cx_aes_init_key_no_throw
  cargo:warning=    ^
  cargo:warning=<instantiation>:4:5: error: cx_aes_iv_no_throw changed binding to STB_GLOBAL
  cargo:warning=    .global cx_aes_iv_no_throw
  cargo:warning=    ^
  cargo:warning=<instantiation>:4:5: error: cx_aes_no_throw changed binding to STB_GLOBAL
  cargo:warning=    .global cx_aes_no_throw
  cargo:warning=    ^
  ...
  cargo:warning=<instantiation>:4:5: error: cx_swap_uint64 changed binding to STB_GLOBAL
  cargo:warning=    .global cx_swap_uint64
  cargo:warning=    ^
  exit status: 1

  --- stderr

  error occurred: Command "clang" "-I" "/Applications/ARM/bin/../arm-none-eabi/include" "-I" "./nanos-secure-sdk/include" "-I" "./nanos-secure-sdk/lib_stusb" "-I" "./nanos-secure-sdk/lib_stusb_impl" "-I" "./nanos-secure-sdk/lib_cxng/include" "-I" "./nanos-secure-sdk/lib_stusb/STM32_USB_Device_Library/Core/Inc" "-I" "./nanos-secure-sdk/lib_stusb/STM32_USB_Device_Library/Class/HID/Inc" "-Wall" "-Wextra" "-fropi" "--target=thumbv6m-none-eabi" "-fomit-frame-pointer" "-mcpu=cortex-m0" "-fno-common" "-fdata-sections" "-ffunction-sections" "-mtune=cortex-m0" "-mthumb" "-fno-jump-tables" "-fno-builtin" "-fshort-enums" "-mno-unaligned-access" "-Wno-unused-command-line-argument" "-Wno-missing-declarations" "-Wno-unused-parameter" "-Wno-implicit-fallthrough" "-Wno-sign-compare" "-Wno-unknown-pragmas" "-Wno-unknown-attributes" "-Wno-pointer-sign" "-Wno-implicit-function-declaration" "-Wno-tautological-pointer-compare" "-Wno-incompatible-pointer-types-discards-qualifiers" "-Wno-duplicate-decl-specifier" "-Wno-#warnings" "-Wno-int-conversion" "-DST31" "-DHAVE_LOCAL_APDU_BUFFER" "-DIO_HID_EP_LENGTH=64" "-DUSB_SEGMENT_SIZE=64" "-DOS_IO_SEPROXYHAL" "-DHAVE_IO_USB" "-DHAVE_L4_USBLIB" "-DHAVE_USB_APDU" "-DIO_USB_MAX_ENDPOINTS=6" "-DIO_SEPROXYHAL_BUFFER_SIZE_B=128" "-DHAVE_NES_CRYPT" "-DHAVE_ST_EDES_PLUS" "-DHAVE_ST_AES" "-DHAVE_CRC" "-DHAVE_HASH" "-DHAVE_RIPEMD160" "-DHAVE_SHA224" "-DHAVE_SHA256" "-DHAVE_SHA3" "-DHAVE_SHA384" "-DHAVE_SHA512" "-DHAVE_SHA512_WITH_BLOCK_ALT_METHOD" "-DHAVE_SHA512_WITH_BLOCK_ALT_METHOD_M0" "-DHAVE_BLAKE2" "-DHAVE_GROESTL" "-DHAVE_HMAC" "-DHAVE_PBKDF2" "-DHAVE_DES" "-DHAVE_AES" "-DHAVE_MATH" "-DHAVE_RNG" "-DHAVE_RNG_RFC6979" "-DHAVE_RNG_SP800_90A" "-DHAVE_ECC" "-DHAVE_ECC_WEIERSTRASS" "-DHAVE_ECC_TWISTED_EDWARDS" "-DHAVE_ECC_MONTGOMERY" "-DHAVE_SECP256K1_CURVE" "-DHAVE_SECP256R1_CURVE" "-DHAVE_SECP384R1_CURVE" "-DHAVE_SECP521R1_CURVE" "-DHAVE_FR256V1_CURVE" "-DHAVE_STARK256_CURVE" "-DHAVE_BLS12_381_G1_CURVE" "-DHAVE_BRAINPOOL_P256R1_CURVE" "-DHAVE_BRAINPOOL_P256T1_CURVE" "-DHAVE_BRAINPOOL_P320R1_CURVE" "-DHAVE_BRAINPOOL_P320T1_CURVE" "-DHAVE_BRAINPOOL_P384R1_CURVE" "-DHAVE_BRAINPOOL_P384T1_CURVE" "-DHAVE_BRAINPOOL_P512R1_CURVE" "-DHAVE_BRAINPOOL_P512T1_CURVE" "-DHAVE_CV25519_CURVE" "-DHAVE_CV448_CURVE" "-DHAVE_ED25519_CURVE" "-DHAVE_ED448_CURVE" "-DHAVE_ECDH" "-DHAVE_ECDSA" "-DHAVE_EDDSA" "-DHAVE_ECSCHNORR" "-o" "/Users/user/rust-app/target/thumbv6m-none-eabi/debug/build/nanos_sdk-94d749e18da4553f/out/./nanos-secure-sdk/src/cx_stubs.o" "-c" "./nanos-secure-sdk/src/cx_stubs.S" with args "clang" did not execute successfully (status code exit status: 1).
mandrean commented 2 years ago

Hey @Thegaram. I've run into the same issue. What I figured out after a couple of days of trial&error is the following:

You need specifically Apple Clang 12 to build this project. Not Apple Clang 13, vanilla Clang 12, Homebrew Clang 12 or anything else. Only Apple Clang 12!

You can download the older Command Line Tools for Xcode 12.5.1 from Apple's developer portal.

If it says the package is too old to install on your system, you'll have to extract the tools manually. This is how I did it:

# after mounting 'Command_Line_Tools_for_Xcode_12.5.1.dmg'
❯ pkgutil --expand-full /Volumes/Command\ Line\ Developer\ Tools/Command\ Line\ Tools.pkg /tmp/CLTools

# rename CLTools v13
❯ sudo mv /Library/Developer/CommandLineTools /Library/Developer/CommandLineTools@13

# move CLTools v12 into place
❯ sudo mv /tmp/CLTools/CLTools_Executables.pkg/Payload/Library/Developer/CommandLineTools /Library/Developer/CommandLineTools

# symlink shared SDKs
❯ sudo ln -s /Library/Developer/CommandLineTools@13/SDKs /Library/Developer/CommandLineTools/SDKs

# clean up
❯ rm -rf /tmp/CLTools

I can now compile the Rust project in question:

❯ clang --version
Apple clang version 12.0.5 (clang-1205.0.22.11)

❯ cargo build --release
...
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s

If you wanna restore Apple Clang 13 you ofc just do:

❯ sudo mv /Library/Developer/CommandLineTools /Library/Developer/CommandLineTools@12
❯ sudo mv /Library/Developer/CommandLineTools@13 /Library/Developer/CommandLineTools
mandrean commented 2 years ago

And by the way, this actually worked on my Apple M1 Silicon machine with arm64.

For anyone interested in that, I had to install the xPack GNU Arm Embedded GCC toolchain which recently added Apple Silicon support:

❯ npm install --global xpm@latest
❯ xpm install --global @xpack-dev-tools/arm-none-eabi-gcc@latest
❯ echo 'export PATH="$HOME/Library/xPacks/@xpack-dev-tools/arm-none-eabi-gcc/10.3.1-2.3.1/.content/bin:$PATH"' >> ~/.bashrc
❯ source ~/.bashrc

❯ arm-none-eabi-gcc --version
arm-none-eabi-gcc (xPack GNU Arm Embedded GCC arm64) 10.3.1 20210824 (release)

❯ file `which arm-none-eabi-gcc`
~/Library/xPacks/@xpack-dev-tools/arm-none-eabi-gcc/10.3.1-2.3.1/.content/bin/arm-none-eabi-gcc:
Mach-O 64-bit executable arm64
Thegaram commented 2 years ago

Awesome, thanks @mandrean, I'll try again following your instructions.

SionoiS commented 2 years ago

I'm having the same problem but on linux. No sure what version of clang to use. 12 & 14 do not work.

yhql commented 2 years ago

Hello, indeed it seems from LLVM 12+ this problem appears. The fix is here if you want to try?

SionoiS commented 2 years ago

Wow that was fast! I will try your fix. @yhql

yhql commented 2 years ago

Not that fast actually, I've stumbled on this before and forgot to publish the fix 😞

SionoiS commented 2 years ago

It works!

edit: ledger-nanos-ui also depend on ledger-nanos-sdk so more fiddling is need to make it work dependency wise.