Link CMAKE_DL_LIBS where needed instead of adding -ldl to linker flags (#5702) (#6253)

* Link CMAKE_DL_LIBS where needed instead of adding -ldl to linker flags (#5702)

* Separated out -ldl into a separate bazel target, and added conversion to CMake
diff --git a/build_tools/BUILD b/build_tools/BUILD
index 4947858..3481f91 100644
--- a/build_tools/BUILD
+++ b/build_tools/BUILD
@@ -17,13 +17,24 @@
     linkopts = select({
         "//iree:iree_is_msvc": [],
         "//iree:iree_is_android": [
-            "-ldl",
             # Android provides its own pthreads support with no linking required.
         ],
         "//conditions:default": [
             # Just include libraries that should be presumed in 2020.
-            "-ldl",
             "-lpthread",
         ],
     }),
 )
+
+cc_library(
+    name = "dl",
+    linkopts = select({
+        "//iree:iree_is_msvc": [],
+        "//iree:iree_is_android": [
+            "-ldl",
+        ],
+        "//conditions:default": [
+            "-ldl",
+        ],
+    }),
+)