CMakeLists: Pass sanitizer flags to the linker too.

We were only passing them to the compiler. These should go to the linker as well.

Bug: b/133127573
Change-Id: Ifc02a2c17a164f30c80311fd17d2a6311e3d5cba
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31817
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cd90023..6e41ea1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -224,6 +224,14 @@
     endif()
 endmacro()
 
+macro(set_linker_flag FLAG)
+    if(${ARGC} GREATER 1)
+        set(CMAKE_EXE_LINKER_FLAGS ${ARGV1} "${CMAKE_EXE_LINKER_FLAGS ${ARGV1}} ${FLAG}")
+    else()
+        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}")
+    endif()
+endmacro()
+
 if(MSVC)
     set_cpp_flag("/MP")
     add_definitions(-D_CRT_SECURE_NO_WARNINGS)
@@ -371,12 +379,16 @@
 
     if(MSAN)
         set_cpp_flag("-fsanitize=memory")
+        set_linker_flag("-fsanitize=memory")
     elseif(ASAN)
         set_cpp_flag("-fsanitize=address")
+        set_linker_flag("-fsanitize=address")
     elseif(TSAN)
         set_cpp_flag("-fsanitize=thread")
+        set_linker_flag("-fsanitize=thread")
     elseif(UBSAN)
         set_cpp_flag("-fsanitize=undefined")
+        set_linker_flag("-fsanitize=undefined")
     endif()
 endif()