From cf96d635cc4c1f610137c0391d99c08e74a2e3d1 Mon Sep 17 00:00:00 2001 From: gongsu832 Date: Wed, 1 Jul 2020 03:06:55 -0400 Subject: [PATCH] Compile cruntime with fpic (#188) * Detect llvm-project commit change in utils/clone-mlir.sh and rebuild llvm-project for zLinux Jenkins build bot * Compile libcruntime.a object with -fPIC to avoid segfault when embedded into model.so * Enable unit tests on zLinux Co-authored-by: Alexandre Eichenberger Co-authored-by: Tian Jin --- .buildbot/z13.sh | 3 ++- src/Runtime/CMakeLists.txt | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.buildbot/z13.sh b/.buildbot/z13.sh index c5361fa..3b9b2b5 100755 --- a/.buildbot/z13.sh +++ b/.buildbot/z13.sh @@ -69,6 +69,7 @@ LLVM_PROJ_SRC=${LLVM_PROJECT_ROOT} \ LLVM_PROJ_BUILD=${LLVM_PROJECT_ROOT}/build \ cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} .. \ -make -j$(nproc) onnx-mlir +make -j$(nproc) make -j$(nproc) check-onnx-lit RUNTIME_DIR=$(pwd)/lib make -j$(nproc) check-onnx-backend +RUNTIME_DIR=$(pwd)/lib PATH=$(pwd)/bin:$PATH make -j$(nproc) test diff --git a/src/Runtime/CMakeLists.txt b/src/Runtime/CMakeLists.txt index 410473d..4f3cc9d 100644 --- a/src/Runtime/CMakeLists.txt +++ b/src/Runtime/CMakeLists.txt @@ -1,9 +1,13 @@ -# Create shared libcruntime.so since model.so linkage for backend tests -# will fail on x86 Linux if cruntime is statically linked. +# Create static libcruntime.a to be embedded in model.so to make model.so self contained. +# However, by default object code for static library is not compiled with -fPIC. Embedding +# such static library in a shared library can cause runtime failure on some architectures, +# such as z. So we override the default and explicitly compile with -fPIC. add_library(cruntime STATIC RtMemRef.cpp RtMemRef.h DataType.h) +set_target_properties(cruntime PROPERTIES + POSITION_INDEPENDENT_CODE TRUE) add_library(RtMemRefUtils RtMemRef.h @@ -35,6 +39,7 @@ target_include_directories(PyRuntime PRIVATE ${ONNX_MLIR_BIN_ROOT} ${ONNX_MLIR_SRC_ROOT}) +# See comments above about libcruntime.a add_library(EmbeddedDataLoader STATIC GetEmbeddedConstPool.h GetEmbeddedConstPool.cpp)