Skip to content

Commit

Permalink
tflite:riscv:Fix riscv32_mcu build failed with undefined references
Browse files Browse the repository at this point in the history
Fix the ld error:
undefined references to __wrap_puts for build commands like `make -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=riscv32_mcu hello_world_bin`
The related issue is #32041

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 specified __wrap__funs are not included correctly.
  • Loading branch information
zhoupeng committed Nov 4, 2019
1 parent 4ef8409 commit 2a18731
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
HELLO_WORLD_TEST_SRCS := \
HELLO_WORLD_TEST_SRCS += \
tensorflow/lite/experimental/micro/examples/hello_world/hello_world_test.cc \
tensorflow/lite/experimental/micro/examples/hello_world/sine_model_data.cc

Expand All @@ -13,7 +13,7 @@ OUTPUT_HANDLER_TEST_HDRS := \
tensorflow/lite/experimental/micro/examples/hello_world/output_handler.h \
tensorflow/lite/experimental/micro/examples/hello_world/constants.h

HELLO_WORLD_SRCS := \
HELLO_WORLD_SRCS += \
tensorflow/lite/experimental/micro/examples/hello_world/main.cc \
tensorflow/lite/experimental/micro/examples/hello_world/main_functions.cc \
tensorflow/lite/experimental/micro/examples/hello_world/sine_model_data.cc \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ GESTURE_PREDICTOR_TEST_HDRS := \
tensorflow/lite/experimental/micro/examples/magic_wand/constants.h \
tensorflow/lite/experimental/micro/examples/magic_wand/gesture_predictor.h \

magic_wand_TEST_SRCS := \
magic_wand_TEST_SRCS += \
tensorflow/lite/experimental/micro/examples/magic_wand/magic_wand_test.cc \
tensorflow/lite/experimental/micro/examples/magic_wand/magic_wand_model_data.cc \
tensorflow/lite/experimental/micro/examples/magic_wand/angle_micro_features_data.cc \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ third_party/kissfft/kiss_fft.h \
third_party/kissfft/_kiss_fft_guts.h \
third_party/kissfft/tools/kiss_fftr.h

MICRO_SPEECH_TEST_SRCS := \
MICRO_SPEECH_TEST_SRCS += \
tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc \
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/tiny_conv_micro_features_model_data.cc \
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.cc \
Expand All @@ -35,7 +35,7 @@ tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micr
MICRO_SPEECH_TEST_HDRS := \
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/tiny_conv_micro_features_model_data.h \
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.h \
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.h \
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.h

SIMPLE_FEATURES_GENERATOR_TEST_SRCS := \
tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_features_generator.cc \
Expand Down Expand Up @@ -183,7 +183,7 @@ tensorflow/lite/experimental/micro/examples/micro_speech/command_responder.cc
COMMAND_RESPONDER_TEST_HDRS := \
tensorflow/lite/experimental/micro/examples/micro_speech/command_responder.h

MICRO_SPEECH_SRCS := \
MICRO_SPEECH_SRCS += \
tensorflow/lite/experimental/micro/examples/micro_speech/main.cc \
tensorflow/lite/experimental/micro/examples/micro_speech/main_functions.cc \
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.cc \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ person_detection_MODEL_HDRS := \
tensorflow/lite/experimental/micro/examples/person_detection/model_settings.h \
tensorflow/lite/experimental/micro/examples/person_detection/person_detect_model_data.h

person_detection_TEST_SRCS := \
person_detection_TEST_SRCS += \
tensorflow/lite/experimental/micro/examples/person_detection/person_detection_test.cc \
$(MAKEFILE_DIR)/downloads/person_model_grayscale/no_person_image_data.cc \
$(MAKEFILE_DIR)/downloads/person_model_grayscale/person_image_data.cc \
Expand All @@ -35,7 +35,7 @@ tensorflow/lite/experimental/micro/examples/person_detection/detection_responder
DETECTION_RESPONDER_TEST_HDRS := \
tensorflow/lite/experimental/micro/examples/person_detection/detection_responder.h

person_detection_SRCS := \
person_detection_SRCS += \
tensorflow/lite/experimental/micro/examples/person_detection/detection_responder.cc \
tensorflow/lite/experimental/micro/examples/person_detection/image_provider.cc \
tensorflow/lite/experimental/micro/examples/person_detection/main.cc \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ $(1)_LOCAL_SRCS := $$(call specialize,$$($(1)_LOCAL_SRCS))
ALL_SRCS += $$($(1)_LOCAL_SRCS)
$(1)_LOCAL_HDRS := $(3)
$(1)_LOCAL_OBJS := $$(addprefix $$(OBJDIR), \
$$(patsubst %.cc,%.o,$$(patsubst %.c,%.o,$$($(1)_LOCAL_SRCS))))
$$(patsubst %.S,%.o,$$(patsubst %.cc,%.o,$$(patsubst %.c,%.o,$$($(1)_LOCAL_SRCS)))))
$(1)_BINARY := $$(BINDIR)$(1)
$$($(1)_BINARY): $$($(1)_LOCAL_OBJS) $$(MICROLITE_LIB_PATH)
@mkdir -p $$(dir $$@)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,30 @@ ifeq ($(TARGET), riscv32_mcu)

MICROLITE_CC_SRCS += \
$(wildcard tensorflow/lite/experimental/micro/riscv32_mcu/*.cc)
MICRO_SPEECH_TEST_SRCS += \

# Wrap functions
MICRO_FE310_LIBWRAP_SRCS += \
$(wildcard $(MAKEFILE_DIR)/downloads/sifive_fe310_lib/bsp/libwrap/sys/*.c) \
$(wildcard $(MAKEFILE_DIR)/downloads/sifive_fe310_lib/bsp/libwrap/sys/*.cc) \
$(MAKEFILE_DIR)/downloads/sifive_fe310_lib/bsp/libwrap/misc/write_hex.c \
$(MAKEFILE_DIR)/downloads/sifive_fe310_lib/bsp/libwrap/stdlib/malloc.c \
$(MAKEFILE_DIR)/downloads/sifive_fe310_lib/bsp/libwrap/stdlib/malloc.c

MICRO_FE310_BSP_ENV_SRCS += \
$(MAKEFILE_DIR)/downloads/sifive_fe310_lib/bsp/env/start.S \
$(MAKEFILE_DIR)/downloads/sifive_fe310_lib/bsp/env/entry.S \
$(MAKEFILE_DIR)/downloads/sifive_fe310_lib/bsp/env/freedom-e300-hifive1/init.c

MICRO_SPEECH_TEST_SRCS += $(MICRO_FE310_LIBWRAP_SRCS) $(MICRO_FE310_BSP_ENV_SRCS)
MICRO_SPEECH_SRCS += $(MICRO_FE310_LIBWRAP_SRCS) $(MICRO_FE310_BSP_ENV_SRCS)

HELLO_WORLD_TEST_SRCS += $(MICRO_FE310_LIBWRAP_SRCS) $(MICRO_FE310_BSP_ENV_SRCS)
HELLO_WORLD_SRCS += $(MICRO_FE310_LIBWRAP_SRCS) $(MICRO_FE310_BSP_ENV_SRCS)

magic_wand_TEST_SRCS += $(MICRO_FE310_LIBWRAP_SRCS) $(MICRO_FE310_BSP_ENV_SRCS)
magic_wand_SRCS += $(MICRO_FE310_LIBWRAP_SRCS) $(MICRO_FE310_BSP_ENV_SRCS)

person_detection_TEST_HDRS += $(MICRO_FE310_LIBWRAP_SRCS) $(MICRO_FE310_BSP_ENV_SRCS)
person_detection_SRCS += $(MICRO_FE310_LIBWRAP_SRCS) $(MICRO_FE310_BSP_ENV_SRCS)

LIBWRAP_SYMS := malloc free \
open lseek read write fstat stat close link unlink \
execve fork getpid kill wait \
Expand All @@ -76,4 +92,4 @@ ifeq ($(TARGET), riscv32_mcu)
$(BINDIR)/%.bin: $(BINDIR)/%
@mkdir -p $(dir $@)
$(OBJCOPY) $< $@ -O binary
endif
endif

0 comments on commit 2a18731

Please sign in to comment.