LedgerHQ / ledger-app-builder

Docker image to compile app for Ledger device (NanoS, X, S+, Stax and Flex).
42 stars 36 forks source link

Clang segmentation fault when compiling Nano S Plus apps #29

Closed NicolasFlamel1 closed 2 years ago

NicolasFlamel1 commented 2 years ago

Compiling apps for the Nano S Plus causes Clang to seg fault.

Here's steps to recreate this issue. This example uses the new Bitcoin app, but this error happens on ever app that I've tried so far.

sudo docker build -t ledger-app-builder:latest .
git clone https://github.com/LedgerHQ/app-bitcoin-new.git
cd ./app-bitcoin-new/
sudo docker run --rm -ti -v "$(realpath .):/app" ledger-app-builder:latest
make BOLOS_SDK=$NANOSP_SDK

And here's the error.

Stack dump:
0.  Program arguments: /usr/bin/ld.lld --gc-sections -Map debug/app.map obj/apdu_parser.o obj/bagl.o obj/bagl_fonts.o obj/bagl_glyphs.o obj/base58.o obj/bip32.o obj/bip32_path.o obj/btchip.o obj/btchip_apdu_get_coin_version.o obj/btchip_apdu_get_firmware_version.o obj/btchip_apdu_get_operation_mode.o obj/btchip_apdu_get_random.o obj/btchip_apdu_get_trusted_input.o obj/btchip_apdu_get_wallet_public_key.o obj/btchip_apdu_hash_input_finalize_full.o obj/btchip_apdu_hash_input_start.o obj/btchip_apdu_hash_sign.o obj/btchip_apdu_set_operation_mode.o obj/btchip_apdu_setup.o obj/btchip_apdu_sign_message.o obj/btchip_apdu_verify_pin.o obj/btchip_bcd.o obj/btchip_context.o obj/btchip_display_variables.o obj/btchip_ecc.o obj/btchip_filesystem.o obj/btchip_helpers.o obj/btchip_nvram.o obj/btchip_public_ram_variables.o obj/btchip_rom_variables.o obj/btchip_secure_value.o obj/btchip_transaction.o obj/buffer.o obj/cashaddr.o obj/check_merkle_tree_sorted.o obj/checks.o obj/compare_wallet_script_at_path.o obj/crypto.o obj/cx_stubs.o obj/cxram_stash.o obj/debug.o obj/dispatcher.o obj/display.o obj/display_utils.o obj/format.o obj/get_extended_pubkey.o obj/get_fingerprint_and_path.o obj/get_master_fingerprint.o obj/get_merkle_leaf_element.o obj/get_merkle_leaf_hash.o obj/get_merkle_leaf_index.o obj/get_merkle_preimage.o obj/get_merkleized_map.o obj/get_merkleized_map_value.o obj/get_merkleized_map_value_hash.o obj/get_preimage.o obj/get_wallet_address.o obj/glyphs.o obj/handle_check_address.o obj/handle_get_printable_amount.o obj/handle_swap_sign_transaction.o obj/io.o obj/ledger_protocol.o obj/main.o obj/main_old.o obj/menu.o obj/merkle.o obj/os.o obj/os_io_seproxyhal.o obj/os_io_task.o obj/os_io_usb.o obj/os_printf.o obj/parser.o obj/pic.o obj/policy.o obj/printf.o obj/psbt_parse_rawtx.o obj/read.o obj/register_wallet.o obj/segwit_addr.o obj/sign_message.o obj/sign_psbt.o obj/stack_protector.o obj/stack_protector_init.o obj/stream_merkle_leaf_element.o obj/stream_merkleized_map_value.o obj/stream_preimage.o obj/svc_call.o obj/svc_cx_call.o obj/swap_globals.o obj/syscalls.o obj/u2f_impl.o obj/u2f_io.o obj/update_hashes_with_map_value.o obj/usbd_ccid_cmd.o obj/usbd_ccid_core.o obj/usbd_ccid_if.o obj/usbd_conf.o obj/usbd_core.o obj/usbd_ctlreq.o obj/usbd_hid.o obj/usbd_impl.o obj/usbd_ioreq.o obj/ux_flow_engine.o obj/ux_layout_bb.o obj/ux_layout_bn.o obj/ux_layout_bnn.o obj/ux_layout_bnnn.o obj/ux_layout_nn.o obj/ux_layout_nnbnn.o obj/ux_layout_nnn.o obj/ux_layout_nnnn.o obj/ux_layout_paging.o obj/ux_layout_paging_compute.o obj/ux_layout_pb.o obj/ux_layout_pbb.o obj/ux_layout_pbn.o obj/ux_layout_pn.o obj/ux_layout_pnn.o obj/ux_layout_utils.o obj/ux_legacy.o obj/ux_menulist.o obj/ux_stack.o obj/varint.o obj/wallet.o obj/write.o -lm -lgcc -lc --defsym=stack_size=1500 -Bstatic -L/usr/lib/llvm-10/lib/clang/10.0.0/lib/baremetal -L/opt/nanosplus-secure-sdk/lib/ -L/opt/nanosplus-secure-sdk/lib/ -T /opt/nanosplus-secure-sdk/script.ld -o bin/app.elf 
/lib/x86_64-linux-gnu/libLLVM-10.so.1(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x1f)[0x7fe78dbaf4ff]
/lib/x86_64-linux-gnu/libLLVM-10.so.1(_ZN4llvm3sys17RunSignalHandlersEv+0x50)[0x7fe78dbad7b0]
/lib/x86_64-linux-gnu/libLLVM-10.so.1(+0x981ac5)[0x7fe78dbafac5]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x153c0)[0x7fe7918d73c0]
/usr/bin/ld.lld[0x5120f4]
/usr/bin/ld.lld[0x5f2361]
/usr/bin/ld.lld[0x5d5f6a]
/usr/bin/ld.lld[0x4b4ff5]
/usr/bin/ld.lld[0x4adf2d]
/usr/bin/ld.lld[0x4ac539]
/usr/bin/ld.lld[0x42734a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0x7fe78cd170b3]
/usr/bin/ld.lld[0x426b4e]
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: ld.lld command failed due to signal (use -v to see invocation)
make: *** [/opt/nanosplus-secure-sdk/Makefile.rules_generic:79: bin/app.elf] Error 254

I'm able to workaround this issue by providing a CLANGPATH to a newer version of Clang. The version of Clang that the app builder uses may need to be updated.

kobigurk commented 2 years ago

@NicolasFlamel1 what version of clang did you use? I tried clang 14 and got the same

kobigurk commented 2 years ago

ah, I haven't updated ld.lld to point to 14. After doing that, I get messages of this sort:

ld.lld: error: obj/celo.o:(.debug_info+0x30): has non-ABS relocation R_ARM_SBREL32 against symbol 'appState'
kobigurk commented 2 years ago

worked with 13 :)

NicolasFlamel1 commented 2 years ago

@kobigurk I'm using version 13.0.0.

codespool commented 2 years ago

Not sure is this related to the version upgrade, but clang -v now returns "Ubuntu clang version 12.0.0-3ubuntu1~20.04.5" so this line: https://github.com/LedgerHQ/nanosplus-secure-sdk/blob/9da334cdcde521bc54d0a50172e167a09f94eec5/Makefile.rules_generic#L38 will fail because the cut -f3 -d' ' will now get "version" instead of number.

apaillier-ledger commented 2 years ago

These issues should be fixed with the new version of the Docker container. It has been upgraded to LLVM 12 (#30). Let us know if the problem still persists.

NicolasFlamel1 commented 2 years ago

@apaillier-ledger I can confirm that this issue is fixed now. Thank you.