Build issues when using make [for SGX optimization]

I tried to install TVM with SGX support. When building using CMake the versions seem fine.

This was on Ubuntu 18.04.

-- The C compiler identification is GNU 5.5.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Build with RPC support...
-- Build with Graph runtime support...
-- Build VTA runtime with target: sim
-- Build with SGX support (SIM)
-- Link with dynamic LLVM library
-- Found LLVM_INCLUDE_DIRS=/usr/lib/llvm-6.0/include
-- Found LLVM_DEFINITIONS=-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Found TVM_LLVM_VERSION=60
-- Build with LLVM 6.0.0
-- Set TVM_LLVM_VERSION=60
-- Build with contrib.sort
-- Build with contrib.hybriddump
-- Performing Test SUPPORT_CXX11
-- Performing Test SUPPORT_CXX11 - Success
-- Build with c++11
-- Build with thread support...
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hrishikesh/tvm/build ```

But , when I run ```make -j4``

I get these errors 

```Scanning dependencies of target tvm
[  1%] Building C object CMakeFiles/tvm_t.dir/src/runtime/sgx/trusted/tvm_t.c.o
[  1%] Building CXX object CMakeFiles/vta_fsim.dir/vta/src/device_api.cc.o
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
[  1%] Building CXX object CMakeFiles/vta_tsim.dir/vta/src/device_api.cc.o
In file included from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.h:11:0,
                 from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.c:1:
/usr/include/x86_64-linux-gnu/sys/uio.h: In function ‘readv’:
/usr/include/x86_64-linux-gnu/sys/uio.h:42:3: error: expected declaration specifiers before ‘__wur’
   __wur;
   ^
/usr/include/x86_64-linux-gnu/sys/uio.h:53:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__wur’
   __wur;
   ^
/usr/include/x86_64-linux-gnu/sys/uio.h:68:28: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__wur’
          __off_t __offset) __wur;
                            ^
/usr/include/x86_64-linux-gnu/sys/uio.h:80:22: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__wur’
    __off_t __offset) __wur;
                      ^
/usr/include/x86_64-linux-gnu/sys/uio.h:107:5: error: unknown type name ‘__off64_t’
     __off64_t __offset) __wur;
     ^
/usr/include/x86_64-linux-gnu/sys/uio.h:119:6: error: unknown type name ‘__off64_t’
      __off64_t __offset) __wur;
      ^
/usr/include/x86_64-linux-gnu/sys/uio.h:128:36: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__wur’
    __off_t __offset, int ___flags) __wur;
                                    ^
/usr/include/x86_64-linux-gnu/sys/uio.h:132:36: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__wur’
     __off_t __offset, int __flags) __wur;
                                    ^
/usr/include/x86_64-linux-gnu/sys/uio.h:153:20: error: unknown type name ‘__off64_t’
       int __count, __off64_t __offset,
                    ^
/usr/include/x86_64-linux-gnu/sys/uio.h:158:21: error: unknown type name ‘__off64_t’
        int __count, __off64_t __offset,
                     ^
In file included from /usr/include/x86_64-linux-gnu/sys/uio.h:168:0,
                 from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.h:11,
                 from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.c:1:
/usr/include/x86_64-linux-gnu/bits/uio-ext.h:29:34: error: unknown type name ‘pid_t’
 extern ssize_t process_vm_readv (pid_t __pid, const struct iovec *__lvec,
                                  ^
/usr/include/x86_64-linux-gnu/bits/uio-ext.h:37:35: error: unknown type name ‘pid_t’
 extern ssize_t process_vm_writev (pid_t __pid, const struct iovec *__lvec,
                                   ^
In file included from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.h:13:0,
                 from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.c:1:
/home/hrishikesh/incubator-teaclave-sgx-sdk/edl/inc/dirent.h:21:1: warning: empty declaration
 struct dirent_t
 ^
/home/hrishikesh/incubator-teaclave-sgx-sdk/edl/inc/dirent.h:30:1: warning: empty declaration
 struct dirent64_t
 ^
In file included from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.h:15:0,
                 from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.c:1:
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:58:3: error: storage class specified for parameter ‘div_t’
 } div_t;
   ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:63:3: error: storage class specified for parameter ‘ldiv_t’
 } ldiv_t;
   ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:68:3: error: storage class specified for parameter ‘lldiv_t’
 } lldiv_t;
   ^
In file included from /opt/intel/sgxsdk/sgxsdk/include/tlibc/sys/stdint.h:22:0,
                 from /opt/intel/sgxsdk/sgxsdk/include/tlibc/stdint.h:22,
                 from /home/hrishikesh/tvm/3rdparty/dlpack/include/dlpack/dlpack.h:29,
                 from /home/hrishikesh/tvm/include/tvm/runtime/c_runtime_api.h:68,
                 from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.h:4,
                 from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.c:1:
/opt/intel/sgxsdk/sgxsdk/include/tlibc/sys/cdefs.h:94:28: error: expected declaration specifiers before ‘__attribute__’
 #define _TLIBC_NORETURN_   __attribute__ ((__noreturn__))
                            ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:88:1: note: in expansion of macro ‘_TLIBC_NORETURN_’
 _TLIBC_NORETURN_ void _TLIBC_CDECL_ abort(void);
 ^
In file included from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.h:15:0,
                 from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.c:1:
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:96:1: error: expected declaration specifiers before ‘div_t’
 div_t   _TLIBC_CDECL_ div(int, int);
 ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:99:1: error: expected declaration specifiers before ‘ldiv_t’
 ldiv_t  _TLIBC_CDECL_ ldiv(long, long);
 ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:112:1: error: expected declaration specifiers before ‘lldiv_t’
 lldiv_t
 ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:133:89: error: expected declaration specifiers before ‘;’ token
 _TLIBC_DEPRECATED_FUNCTION_(int     _TLIBC_CDECL_, atexit, void (_TLIBC_CDECL_ *)(void));
                                                                                         ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:134:63: error: expected declaration specifiers before ‘;’ token
 _TLIBC_DEPRECATED_FUNCTION_(int     _TLIBC_CDECL_, rand, void);
                                                               ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:135:68: error: expected declaration specifiers before ‘;’ token
 _TLIBC_DEPRECATED_FUNCTION_(void    _TLIBC_CDECL_, srand, unsigned);
                                                                    ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:136:62: error: expected declaration specifiers before ‘;’ token
 _TLIBC_DEPRECATED_FUNCTION_(void    _TLIBC_CDECL_, exit, int);
                                                              ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:137:63: error: expected declaration specifiers before ‘;’ token
 _TLIBC_DEPRECATED_FUNCTION_(void    _TLIBC_CDECL_, _Exit, int);
                                                               ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:138:73: error: expected declaration specifiers before ‘;’ token
 _TLIBC_DEPRECATED_FUNCTION_(char *  _TLIBC_CDECL_, getenv, const char *);
                                                                         ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdlib.h:139:73: error: expected declaration specifiers before ‘;’ token
 _TLIBC_DEPRECATED_FUNCTION_(int     _TLIBC_CDECL_, system, const char *);
                                                                         ^
In file included from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.c:3:0:
/opt/intel/sgxsdk/sgxsdk/include/sgx_trts.h:71:12: error: section attribute not allowed for ‘sgx_is_enclave_crashed’
 int SGXAPI sgx_is_enclave_crashed(void) __attribute__((section(".nipx")));
            ^
In file included from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.c:4:0:
/opt/intel/sgxsdk/sgxsdk/include/sgx_lfence.h:41:13: error: storage class specified for parameter ‘__builtin_ia32_lfence’
 extern void __builtin_ia32_lfence(void);
             ^
In file included from /opt/intel/sgxsdk/sgxsdk/include/tlibc/mbusafecrt.h:23:0,
                 from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.c:7:
/opt/intel/sgxsdk/sgxsdk/include/tlibc/string.h:48:13: error: storage class specified for parameter ‘errno_t’
 typedef int errno_t;
             ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/string.h:82:1: error: expected declaration specifiers before ‘errno_t’
 errno_t _TLIBC_CDECL_ memset_s(void *s, size_t smax, int c, size_t n);
 ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/string.h:87:80: error: expected declaration specifiers before ‘;’ token
 _TLIBC_DEPRECATED_FUNCTION_(char * _TLIBC_CDECL_, strcat, char *, const char *);
                                                                                ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/string.h:88:80: error: expected declaration specifiers before ‘;’ token
 _TLIBC_DEPRECATED_FUNCTION_(char * _TLIBC_CDECL_, strcpy, char *, const char *);
                                                                                ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/string.h:120:72: error: expected declaration specifiers before ‘;’ token
 _TLIBC_DEPRECATED_FUNCTION_(char * _TLIBC_CDECL_, strdup, const char *);
                                                                        ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/string.h:121:87: error: expected declaration specifiers before ‘;’ token
 _TLIBC_DEPRECATED_FUNCTION_(char * _TLIBC_CDECL_, stpcpy, char *dest, const char *src);
                                                                                       ^
In file included from /opt/intel/sgxsdk/sgxsdk/include/tlibc/mbusafecrt.h:24:0,
                 from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.c:7:
/opt/intel/sgxsdk/sgxsdk/include/tlibc/stdarg.h:41:21: error: storage class specified for parameter ‘va_list’
 typedef __va_list   va_list;
                     ^
In file included from /home/hrishikesh/tvm/src/runtime/sgx/trusted/tvm_t.c:7:0:
/opt/intel/sgxsdk/sgxsdk/include/tlibc/mbusafecrt.h:26:17: error: storage class specified for parameter ‘WCHAR’
 typedef wchar_t WCHAR;
                 ^
/opt/intel/sgxsdk/sgxsdk/include/tlibc/mbusafecrt.h:32:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘strcat_s’
 extern errno_t strcat_s( char* ioDest, size_t inDestBufferSize, const char* inSrc );
                ^

Further

make[2]: *** [CMakeFiles/tvm_t.dir/src/runtime/sgx/trusted/tvm_t.c.o] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/tvm_t.dir/all' failed
make[1]: *** [CMakeFiles/tvm_t.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

Any idea how to resolve it?

This is my config file

   add_compile_options(-std=c++11)
   Whether enable ROCM runtime

#

# Possible values:

# - ON: enable ROCM with cmake's auto search

# - OFF: disable ROCM

# - /path/to/rocm: use specific path to rocm

set(USE_ROCM **OFF** )

# Whether enable SDAccel runtime

set(USE_SDACCEL **OFF** )

# Whether enable Intel FPGA SDK for OpenCL (AOCL) runtime

set(USE_AOCL **OFF** )

# Whether enable OpenCL runtime

set(USE_OPENCL **OFF** )

# Whether enable Metal runtime

set(USE_METAL **OFF** )

# Whether enable Vulkan runtime

#

# Possible values:

# - ON: enable Vulkan with cmake's auto search

# - OFF: disable vulkan

# - /path/to/vulkan-sdk: use specific path to vulkan-sdk

set(USE_VULKAN **OFF** )

# Whether enable OpenGL runtime

set(USE_OPENGL **OFF** )

# Whether enable MicroTVM runtime

set(USE_MICRO **OFF** )

# Whether to enable SGX runtime

#

# Possible values for USE_SGX:

# - /path/to/sgxsdk: path to Intel SGX SDK

# - OFF: disable SGX

#

# SGX_MODE := HW|SIM

set(USE_SGX /opt/intel/sgxsdk/sgxsdk/)

set(SGX_MODE "SIM")

set(RUST_SGX_SDK "/home/hrishikesh/incubator-teaclave-sgx-sdk")

# Whether enable RPC runtime

set(USE_RPC **ON** )

# Whether embed stackvm into the runtime

set(USE_STACKVM_RUNTIME **OFF** )

# Whether enable tiny embedded graph runtime.

set(USE_GRAPH_RUNTIME **ON** )

# Whether enable additional graph debug functions

set(USE_GRAPH_RUNTIME_DEBUG **OFF** )

# Whether enable additional vm profiler functions

set(USE_VM_PROFILER **OFF** )

# Whether enable uTVM standalone runtime

set(USE_MICRO_STANDALONE_RUNTIME **OFF** )

# Whether build with LLVM support

# Requires LLVM version >= 4.0

#

# Possible values:

# - ON: enable llvm with cmake's find search

# - OFF: disable llvm

# - /path/to/llvm-config: enable specific LLVM when multiple llvm-dev is available.

set(USE_LLVM **ON** )

set(LLVM_CONFIG llvm-config-6.0)

#---------------------------------------------

# Contrib libraries

#---------------------------------------------

# Whether use BLAS, choices: openblas, mkl, atlas, apple

set(USE_BLAS none)

# /path/to/mkl: mkl root path when use mkl blas library

# set(USE_MKL_PATH /opt/intel/mkl) for UNIX

# set(USE_MKL_PATH ../IntelSWTools/compilers_and_libraries_2018/windows/mkl) for WIN32

# set(USE_MKL_PATH <path to venv or site-packages directory>) if using `pip install mkl`

set(USE_MKL_PATH none)

# Whether use MKLDNN library, choices: ON, OFF, path to mkldnn library

set(USE_MKLDNN **OFF** )

# Whether use OpenMP thread pool, choices: gnu, intel

# Note: "gnu" uses gomp library, "intel" uses iomp5 library

set(USE_OPENMP none)

# Whether use contrib.random in runtime

set(USE_RANDOM **OFF** )

# Whether use NNPack

set(USE_NNPACK **OFF** )

# Possible values:

# - ON: enable tflite with cmake's find search

# - OFF: disable tflite

# - /path/to/libtensorflow-lite.a: use specific path to tensorflow lite library

set(USE_TFLITE **OFF** )

# /path/to/tensorflow: tensorflow root path when use tflite library

set(USE_TENSORFLOW_PATH /home/hrishikesh/anaconda3/envs/tf2/lib/python3.6/site-packages/tensorflow_core)

# Possible values:

# - OFF: disable tflite support for edgetpu

# - /path/to/edgetpu: use specific path to edgetpu library

set(USE_EDGETPU **OFF** )

# Whether use CuDNN

set(USE_CUDNN **OFF** )

# Whether use cuBLAS

set(USE_CUBLAS **OFF** )

# Whether use MIOpen

set(USE_MIOPEN **OFF** )

# Whether use MPS

set(USE_MPS **OFF** )

# Whether use rocBlas

set(USE_ROCBLAS **OFF** )

# Whether use contrib sort

set(USE_SORT **ON** )

# Whether use MKL-DNN (DNNL) codegen

set(USE_DNNL_CODEGEN **OFF** )

# Build ANTLR parser for Relay text format

# Possible values:

# - ON: enable ANTLR by searching default locations (cmake find_program for antlr4 and /usr/local for jar)

# - OFF: disable ANTLR

set(USE_ANTLR **OFF** )

# Whether use Relay debug mode

set(USE_RELAY_DEBUG **OFF** )

# Whether to build fast VTA simulator driver

set(USE_VTA_FSIM **ON** )

# Whether to build cycle-accurate VTA simulator driver

set(USE_VTA_TSIM **ON** )

# Whether to build VTA FPGA driver (device side only)

set(USE_VTA_FPGA **OFF** )

# Whether to build the example external runtime module

set(USE_EXAMPLE_EXT_RUNTIME **OFF** ) ```

Smells like this issue here https://github.com/apache/incubator-tvm/issues/4946

Do try again and if this is fixed, please mark it as solved.

Thanks, Ramana