[microTVM] Build error in standalone CRT with gcc 12.1.0

Hello, I believe I’ve run into an error compiling tvm with the latest gcc version.

I have the following options ON in config.cmake:

  • USE_MICRO
  • USE_RPC
  • USE_GRAPH_RUNTIME
  • USE_MICRO_STANDALONE_RUNTIME
  • USE_LLVM
  • USE_RANDOM
  • USE_SORT
  • USE_RELAY_DEBUG

Versions:

  • Arch Linux
  • LLVM = 14.0.6
  • gcc = 12.1.0
  • tvm commit b84ed27260d492e954963448e6cc8aee329b4cc6
  • cmake = 3.23.2

CMake stops the build because GCC throws a warning: -Werror=stringop-overread

[545/609] Generating host_standalone_crt/libmemory.a, host_standalone_crt/libgraph_execut...c_server.a, host_standalone_crt/libmicrotvm_rpc_common.a, host_standalone_crt/libcommon.a
FAILED: host_standalone_crt/libmemory.a host_standalone_crt/libgraph_executor.a host_standalone_crt/libmicrotvm_rpc_server.a host_standalone_crt/libmicrotvm_rpc_common.a host_standalone_crt/libcommon.a /home/josse/phd/tvm-fork/build/host_standalone_crt/libmemory.a /home/josse/phd/tvm-fork/build/host_standalone_crt/libgraph_executor.a /home/josse/phd/tvm-fork/build/host_standalone_crt/libmicrotvm_rpc_server.a /home/josse/phd/tvm-fork/build/host_standalone_crt/libmicrotvm_rpc_common.a /home/josse/phd/tvm-fork/build/host_standalone_crt/libcommon.a 
cd /home/josse/phd/tvm-fork/build/standalone_crt && make CRT_CONFIG=/home/josse/phd/tvm-fork/src/runtime/micro/crt_config.h BUILD_DIR=/home/josse/phd/tvm-fork/build/host_standalone_crt EXTRA_CFLAGS=-fPIC EXTRA_CXXFLAGS=-fPIC EXTRA_LDFLAGS=-fPIC clean && make CRT_CONFIG=/home/josse/phd/tvm-fork/src/runtime/micro/crt_config.h BUILD_DIR=/home/josse/phd/tvm-fork/build/host_standalone_crt EXTRA_CFLAGS=-fPIC EXTRA_CXXFLAGS=-fPIC EXTRA_LDFLAGS=-fPIC all
rm -rf "/home/josse/phd/tvm-fork/build/host_standalone_crt"
src/runtime/crt/aot_executor/aot_executor.c: In function ‘TVMAotExecutor_Run’:
src/runtime/crt/aot_executor/aot_executor.c:92:12: error: ‘strnlen’ specified bound 120 exceeds source size 14 [-Werror=stringop-overread]
   92 |     len += strnlen(tvm_main_suffix, max_strlen);
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/runtime/crt/aot_executor/aot_executor.c: In function ‘TVMAotExecutor_Init’:
src/runtime/crt/aot_executor/aot_executor.c:142:18: error: ‘strnlen’ specified bound 120 exceeds source size 8 [-Werror=stringop-overread]
  142 |     size_t len = strnlen(tvmgen_prefix, max_strlen);
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/runtime/crt/aot_executor/aot_executor.c:144:12: error: ‘strnlen’ specified bound 120 exceeds source size 16 [-Werror=stringop-overread]
  144 |     len += strnlen(get_c_metdata_suffix, max_strlen);
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:54: /home/josse/phd/tvm-fork/build/host_standalone_crt/runtime/crt/aot_executor/aot_executor.o] Error 1

We have our own downstream CI that runs an ubuntu 20.04 container where this is not an issue.

I’ve been able to build with the same options on this system with clang (14.0.6) iso gcc. However, there the build fails due to an invalid supplied linker option to lld:

ld.lld: error: unknown argument '-force_load'
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

TVM compiles fine with gcc when USE_MICRO is set to OFF.

A few questions:

  • Should I report this as an issue on github?
  • Do I actually have to build with USE_MICRO in the first place to be able to deploy on a MicroTVM? As I have to build the emitted CRT later for my embedded platform anyway? It’s not so clear to me which parts of the config.cmake are required for microTVM purposes

Thanks! Regards!

1 Like

I can already answer two questions myself here:

Seems like a yes :smiley:

Traceback (most recent call last):
  File "relay.py", line 65, in <module>
    compile_model(tvmc_model=model,
  File "/home/josse/phd/tvm-fork/python/tvm/driver/tvmc/compiler.py", line 366, in compile_model
    package_path = tvmc_model.export_package(
  File "/home/josse/phd/tvm-fork/python/tvm/driver/tvmc/model.py", line 332, in export_package
    raise Exception("micro tvm is not enabled. Set USE_MICRO to ON in config.cmake")
Exception: micro tvm is not enabled. Set USE_MICRO to ON in config.cmake

This error seems also related to building the standalone interface: As this option is only set in tvm/cmake/modules/StandaloneCrt.cmake

Can anyone recommend setting this differently? If I just remove the -force_load flag it works, but I’m not sure what this does.

Thanks in advance!

I got the same problem when I built TVM while setting the option USE_MICRO to ON and compiling with GCC.

I delete the -Werror option from the CFLAGS in $TVM_HOME/src/runtime/crt/Makefile manually. And then, I compiled TVM successfully.

Build Environment:

  • Fedora 37
  • GCC Version: 12.2.1
  • LLVM Version: 15.0.4
  • CMake Version: 3.24.2
1 Like