$NetBSD: patch-tools_llvm-shlib_CMakeLists.txt,v 1.2 2017/12/01 19:22:12 adam Exp $

Use the Linux style linking everywhere except Darwin and SunOS.

--- tools/llvm-shlib/CMakeLists.txt.orig	2017-07-11 01:17:44.000000000 +0000
+++ tools/llvm-shlib/CMakeLists.txt
@@ -37,15 +37,15 @@ endif()
 add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES})
 
 list(REMOVE_DUPLICATES LIB_NAMES)
-if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU) OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")) # FIXME: It should be "GNU ld for elf"
+if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
+  set(LIB_NAMES -Wl,-all_load ${LIB_NAMES})
+elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
+  set(LIB_NAMES -Wl,-Bsymbolic -Wl,-z -Wl,allextract ${LIB_NAMES} -Wl,-z -Wl,defaultextract)
+else()
   configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in
   ${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map)
-
-  # GNU ld doesn't resolve symbols in the version script.
   set(LIB_NAMES -Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
-elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
-  set(LIB_NAMES -Wl,-all_load ${LIB_NAMES})
 endif()
 
 target_link_libraries(LLVM PRIVATE ${LIB_NAMES})
