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

micro: riscv32_mcu build failed with undefined references #32041

Closed
ehirdoy opened this issue Aug 28, 2019 · 7 comments
Closed

micro: riscv32_mcu build failed with undefined references #32041

ehirdoy opened this issue Aug 28, 2019 · 7 comments
Labels
comp:lite TF Lite related issues type:bug Bug

Comments

@ehirdoy
Copy link

ehirdoy commented Aug 28, 2019

System information

  • OS Platform and Distribution: Ubuntu 18.04
  • TensorFlow installed from: source
  • TensorFlow version: 298534b
  • Python version: 2.7.15+/3.6.8
  • Installed using virtualenv? pip? conda?: pip3

Describe the problem
TF Lite for micro, riscv32 build fails with undefined references.

make -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=riscv32_mcu TARGET_ARCH=riscv32 hello_world_bin

/home/ehirdoy/src/tensorflow/tensorflow/lite/experimental/micro/riscv32_mcu/debug_log.cc:18: undefined reference to __wrap_puts' exit.c:(.text.exit+0x2e): undefined reference to __wrap__exit'
sbrkr.c:(.text._sbrk_r+0x12): undefined reference to __wrap__sbrk' writer.c:(.text._write_r+0x16): undefined reference to __wrap__write'
closer.c:(.text._close_r+0x12): undefined reference to __wrap__close' lseekr.c:(.text._lseek_r+0x16): undefined reference to __wrap__lseek'
readr.c:(.text._read_r+0x16): undefined reference to __wrap__read' fstatr.c:(.text._fstat_r+0x14): undefined reference to __wrap__fstat'
isattyr.c:(.text._isatty_r+0x12): undefined reference to `__wrap__isatty'

Provide the exact sequence of commands / steps that you executed before running into the problem

export PATH="$PATH:./tensorflow/lite/experimental/micro/tools/make/downloads/riscv_toolchain/bin"
make -f tensorflow/lite/experimental/micro/tools/make/Makefile clean
make -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=riscv32_mcu TARGET_ARCH=riscv32 hello_world_bin

Any other info / logs
make.log

@aselle
Copy link
Contributor

aselle commented Aug 28, 2019

@dansitu, please take a look.

@gadagashwini-zz gadagashwini-zz self-assigned this Aug 29, 2019
@gadagashwini-zz gadagashwini-zz added comp:lite TF Lite related issues type:bug Bug labels Aug 29, 2019
@ymodak ymodak assigned dansitu and unassigned ymodak Aug 30, 2019
@Zielasko
Copy link

I am running into a similar error when trying to compile any of the examples for riscv using the same commands as listed above.
So far i have tested 3 different riscv-toolchains:

@zhoupeng
Copy link
Contributor

zhoupeng commented Nov 4, 2019

I write patches which fix this bug, and tested on my machine.
This pull request to fix this issue is #33972
Hi @ehirdoy @Zielasko
Could you have a try of these patches pls? If you find it helpful, pls have a support click.

Best,

@Zielasko
Copy link

Thank you for writing a fix @zhoupeng .
I tried to write a workaround in an older version of this repository that let me compile the hello world example and a few examples i have written myself, but they didn't behave correctly.
Using your version lets me compile and successfully run the hello world example on a risc-v simulator with the expected output.
(Using make -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=riscv32_mcu hello_world to build the executable)

Unfortunately I still can't build the micro_speech, magic_wand or person_detection examples for
riscv32_mcu.
For the magic_wand example it cant find __wrap_malloc and __wrap_free .

person_detection fails with the error

person_detection section `.bss' will not fit in region `ram' 
[...]
section .stack VMA [0000000080003800,0000000080003fff] overlaps section .bss VMA [00000000800002b8,0000000080012d87]
[...]
region `ram' overflowed by 0 bytes

I have yet to test my own models.

Also, trying to build a linux version of the hello world example with the __dso fix gives me this error:
multiple definition of __dso_handle'`

@zhoupeng
Copy link
Contributor

zhoupeng commented Nov 13, 2019

Hi @Zielasko , Thanks for your response. Sorry for late reply, I am not convenient to handle mail in time, because on a travel of RISC-V tech forum.
1)For the .bss' will not fit in region ram error:
Set the MEMORY.ram option with a larger value in the link script can fix.
The ram option is in the link script tensorflow.git/tensorflow/lite/experimental/micro/tools/make/downloads/sifive_fe310_lib/bsp/env/freedom-e300-hifive1/flash.lds.
In my case, I only try to set ram (wxa!ri) : ORIGIN = 0x80000000, LENGTH = 128K (Maybe 64K or 32K is enough for some examples, but I didn't try)

2)__dso_handle missing problem. Thanks for response, very helpful.
This problem may only exists on non-Linux target (riscv32_mcu,Windows ...), I will submit a new version patch adding target OS check.
Before the new patch, If you try to build a linux version, you can try to comment __dso_handle by replacing void* __dso_handle;
with // void* __dso_handle;, in tensorflow.git/tensorflow/lite/experimental/micro/arduino/abi.cc,

Hi @nkreeger @gbaned @rockyrhodes, sorry for late, thanks @nkreeger for your detail review I will submit a new version patch, catching up on this Fridays after my RISC-V tech forum journey.

@dansitu dansitu removed their assignment Jan 22, 2020
zhoupeng referenced this issue in zhoupeng/tensorflow Jan 22, 2020
Fix the ld error:
undefined references to `__wrap_puts` for build commands like `make -f tensorflow/lite/micro/tools/make/Makefile TARGET=riscv32_mcu hello_world_bin`
The related issue is tensorflow#32041

Refactoring, suggested by Nick Kreeger(nick.kreeger@gmail.com):
The targets/mcu_riscv_makefile.inc should only include the bare-bones parts for building for this platform.
So move platform specific items from targets/mcu_riscv_makefile.inc to the actual example folder.
Create a riscv32_mcu folder in each example directory. In those directories, create a new Makefile.inc that adds these rules moved out.

The bug's original reasons:
The Makefile variables XXX_TEST_SRCS/XXX_SRCS in targets/mcu_riscv_makefile.inc are overridden by the the examples's respective makefile.inc (eg. hello_world/Makefile.inc), which leads to the
architecture special __wrap__funs are not included correctly.
@ymodak
Copy link
Contributor

ymodak commented Feb 24, 2021

Closing since the associated PR has been merged. Feel free to reopen if necessary. Thanks!

@ymodak ymodak closed this as completed Feb 24, 2021
@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:lite TF Lite related issues type:bug Bug
Projects
None yet
Development

No branches or pull requests

7 participants