--- runtime/CMakeLists.txt.orig	2018-01-05 23:42:10 UTC
+++ runtime/CMakeLists.txt
@@ -430,10 +430,13 @@ endmacro()
 # Sets up the targets for building the Phobos D object files, appending the
 # names of the (bitcode) files to link into the library to outlist_o (outlist_bc).
 macro(compile_phobos2 d_flags lib_suffix path_suffix all_at_once outlist_o outlist_bc)
+    if(NOT ${BUILD_SHARED_LIBS} STREQUAL "OFF")
+        set(RELOCATION_FLAGS -relocation-model=pic)
+    endif()
     get_target_suffix("${lib_suffix}" "${path_suffix}" target_suffix)
     dc("${PHOBOS2_D}"
        "${PHOBOS2_DIR}"
-       "-conf=;${d_flags};-I${RUNTIME_DIR}/src;-I${PHOBOS2_DIR}"
+       "-conf=;${d_flags};${RELOCATION_FLAGS};-I${RUNTIME_DIR}/src;-I${PHOBOS2_DIR}"
        "${PROJECT_BINARY_DIR}/objects${target_suffix}"
        "${all_at_once}"
        ${outlist_o}
