Set proper DFLAGS. Make sure C parts are built as PIC. Index: runtime/CMakeLists.txt --- runtime/CMakeLists.txt.orig +++ runtime/CMakeLists.txt @@ -35,7 +35,7 @@ set(MULTILIB OFF set(BUILD_LTO_LIBS OFF CACHE BOOL "Also build the runtime as LLVM bitcode libraries for LTO") set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/d CACHE PATH "Path to install D modules to") set(BUILD_SHARED_LIBS AUTO CACHE STRING "Whether to build the runtime as a shared library (ON|OFF|BOTH)") -set(D_FLAGS -w;-de;-preview=dip1000;-preview=dtorfields;-preview=fieldwise CACHE STRING "Runtime D compiler flags, separated by ';'") +set(D_FLAGS --relocation-model=pic;-w;-de;-preview=dip1000;-preview=dtorfields;-preview=fieldwise CACHE STRING "Runtime D compiler flags, separated by ';'") set(D_EXTRA_FLAGS "" CACHE STRING "Runtime extra D compiler flags, separated by ';'") set(D_FLAGS_DEBUG -g;-link-defaultlib-debug;-d-debug CACHE STRING "Runtime D compiler flags (debug libraries), separated by ';'") set(D_FLAGS_RELEASE -O3;-release;-femit-local-var-lifetime CACHE STRING "Runtime D compiler flags (release libraries), separated by ';'") @@ -576,7 +576,7 @@ function(set_common_library_properties target name out # linker default on Ubuntu 16.10 and above. As we might be building on an # older system (e.g. binary packages), we need to make sure the C parts are # built as PIC as well. - if("${TARGET_SYSTEM}" MATCHES "Linux") + if("${TARGET_SYSTEM}" MATCHES "Linux|OpenBSD") set_target_properties(${target} PROPERTIES POSITION_INDEPENDENT_CODE ON) endif()