riscv64 libm link question
Please forgive the noob question. I am porting a Scheme interpreter to riscv64 NuttX as apps/interpreters/umb-scheme/ but the binary fails to link in libm functions. I could use some help in this. Specifically, building on Raspberry Pi 4 Raspian 64 bit: Raspian:RasPi4:~/RISCV/NuttX/apps/bin >>> riscv64-linux-gnu-gcc-nm -u scheme U acos U asin U atan U atan2 U ceil U cos U exp U floor U log U pow U sin U sqrt U tan I am following the Pine64 Start64 recipe, which does yield a bootable NuttX on VisionFive 2 SoC: https://nuttx.apache.org/docs/latest/platforms/risc-v/jh7110/boards/star64/index.html My nuttx/.config file contains: CONFIG_LIBM=y CONFIG_ARCH_FLOAT_H=y The interpreter local make/config files are attached. They should be unsurprising. Perhaps some kind person can help me out with the proper build flags. Thanks much! -KenD [Ken (dot) Dickey (at) Whidbey (dot) COM] config INTERPRETERS_UMB_SCHEME tristate "UMB-Scheme R4RS Scheme interpreter" default y ---help--- Enable the UMB-Scheme `scheme` interpreter - Be sure to set CONFIG_LIBM=y in your .config file - Be sure to set CONFIG_ARCH_SETJMP_H=y in your .config file #if INTERPRETERS_UMB_SCHEME # #config INTERPRETERS_UMB_SCHEME_PRIORITY #int "UMB-Scheme task priority" #default 100 # #config INTERPRETERS_UMB_SCHEME_STACKSIZE #int "UMB-Scheme stack size" # default 4096 # #endif# Makefile for the UMB Scheme interpreter. include $(APPDIR)/Make.defs # UMB-Scheme built-in application info PROGNAME = scheme PRIORITY = 100 #$(INTERPRETERS_UMB_SCHEME_PRIORITY) STACKSIZE = 4096 #$(INTERPRETERS_UMB_SCHEME_STACKSIZE) MODULE= $(INTERPRETERS_UMB_SCHEME) # UMB-Scheme components CSRCS = object.c primitive.c debug.c CSRCS += io.c compiler.c eval.c architecture.c number.c CSRCS += fixnum.c bignum.c rational.c real.c complex.c MAINSRC = steering.c ###??### LDLIBS += ${NUTTX_PATH}/libs include $(APPDIR)/Application.mk ### E O F ### # ?? How to turn off -Wstrict-prototypes ?? ifneq ($(CONFIG_INTERPRETERS_UMB_SCHEME),) CONFIGURED_APPS += $(APPDIR)/interpreters/umb-scheme CFLAGS += -lm endif
Re: riscv64 libm link question
On 2023-09-17 12:47, Petro Karashchenko wrote: Hi, What kind of RISC-V toolchain are you using? Raspian:RasPi4:~/RISCV/NuttX/apps >>> apt search riscv64-unknown Sorting... Done Full Text Search... Done binutils-riscv64-unknown-elf/oldstable,now 2.32.2020.04+dfsg-2 arm64 [installed] GNU assembler, linker and binary utilities for RISC-V processors gcc-riscv64-unknown-elf/oldstable,now 8.3.0.2019.08+dfsg-1 arm64 [installed] GCC compiler for embedded RISC-V chips picolibc-riscv64-unknown-elf/oldstable,oldstable,now 1.5.1-2 all [installed] Smaller embedded C library for RISC-V development So just `sudo apt-get install ...` of the above. Please try to remove "CFLAGS += -lm " and feedback if that helps. No change. The problem is not that I am trying to use some released libm library but that the NuttX nuttx/libs/libm/libm.a is not being linked into the scheme binary file. I have not used other than trivial makefiles in a couple of decades, never used `make menuconfig`, which allows one to specify many non-bootable systems, and so have little clue how to specify linking the NuttX libm into the scheme executable or alternately getting nuttx to dynamically load the libm library. Note that there is no file 'kconfig-language.txt' in the NuttX tools repository. I am kinda stuck. Thanks for any help! -KenD
Re: riscv64 libm link question
As I am building on aarch64/arm64 Linux, someone might have a better time with x86. I made a git repo: https://github.com/KenDickey/nuttx-umb-scheme This goes into apps/interpreters. The code has been reliably ported a lot and should run on most targets with command line console. Sample code: (+ 1/2 1/3 1/6) ;; --> 1 (sqrt -4) ;; --> 0+2i ((lambda (n) (* n n)) (sqrt -4)) ;; --> -4 Note that there is nothing time critical about this -- fine to wait until after the upcoming NuttX Workshop! Thanks again for all. -KenD
Re: riscv64 libm link question
Ah. I tried using `make menuconfig` to build the Basic interpreter. Raspian:RasPi4:~/RISCV/NuttX/apps >>> riscv64-linux-gnu-gcc-nm -u bin/bas U atan U ceil U cos U exp U floor U fmod U log U log10 U log2 U pow U sin U sqrt U tan Same result with the released `Bas` interpreter, so perhaps a general build problem related to aarch64/arm64 linux build environment? I have an old Intel/x86 box in the closet. I will try to resurect it and see if I can build on x86 with the same result. FYI, -KenD
Re: riscv64 libm link question
On 2023-09-18 12:05, Alan C. Assis wrote: Hi Ken, Are you enabling the same symbols as in the sim bas or bastest ? I just used menuconfig interpreters bas selection Raspian:RasPi4:~/RISCV/NuttX/nuttx >>> grep CONFIG_INTERPRETER_BAS .config CONFIG_INTERPRETER_BAS_VERSION="2.4" CONFIG_INTERPRETER_BAS_PRIORITY=100 CONFIG_INTERPRETER_BAS_STACKSIZE=4096 CONFIG_INTERPRETER_BAS_VT100=y # CONFIG_INTERPRETER_BAS_USE_LR0 is not set # CONFIG_INTERPRETER_BAS_USE_SELECT is not set # CONFIG_INTERPRETER_BAS_HAVE_FTRUNCATE is not set Otherwise, basically same as ./tools/configure.sh star64:nsh as I am building for VisionFive 3 riscv64 SoC. -KenD
Re: riscv64 libm link question
On 2023-09-18 13:08, Alan C. Assis wrote: The thumb rule when starting with NuttX is using an existent configuration as base. OK. Unfortunately the menuconfig is not prepared (better say it cannot) to fix all dependencies for an driver or application (because of the flexibility to use things in different ways on NuttX). Yes. I found Kconfig quite fragile. My hope was that selecting the basic interpreter in menuconfig would result in a working basic interpreter as this option exists in the base NuttX release. NuttX boots fine and `nsh` runs. A CLI console based interpreter should be no problem as no extra drivers are required. I tried building on x86 Linux, but with the same result -- working nsh but failing bas & scheme. `nm -u` shows both interpreters need to be linked with libm. I just have no idea how the NuttX build system specifies link libraries, i.e. how to link an application with libm. I will keep at it. Thanks for the help. -KenD
Re: riscv64 libm link question
On 2023-09-18 15:10, Alan C. Assis wrote: .. Did you enable CONFIG_LIBM in the menuconfig? Normally it is enough if your arch correctly configured. Yep. Enabled. I added LDLIBS += $(APPDIR)/../nuttx/libs/libm/libm.a to the Makefile and the Scheme interpreter works -- some console wackyness, gc bug, but simple tests run. Now I can progress! Thanks again.. -KenD
Re: [Article] NuttX on Ox64 BL808 RISC-V SBC: Sv39 Memory Management Unit
Lup, Another great article! One suggestion. In section 10 "Swap the SATP Register" You mention: "Huh? Our Applications can meddle with the I/O Memory? Nope they can’t, because the “U” User Permission is denied. Therefore we’re all safe and well protected! " I may have missed the reference, but this might be a place to introduce the idea that Kernel trampoline, eCalls, and so forth make use of kernel memory being mapped and available in all User address spaces so the Kernel's handling code does not have to immediately swap SATP to access its data structures. I know this is a large topic on its own, but am important trick to learn. Again, great article! Thanks!! -KenD