From 5bf6ee5d8e06aea64a2b20c47afe5062da1a7848 Mon Sep 17 00:00:00 2001
From: Josh Triplett <josh@joshtriplett.org>
Date: Sat, 19 Sep 2020 20:46:25 -0700
Subject: [PATCH] Consolidate handling of libdl, and handle crt-static

Move the link line for `libdl` up to `src/unix/mod.rs`, making it easier
to see all the libraries `libc` links to.

This also makes `libdl` respect `target-feature=+crt-static`.
---
 src/unix/linux_like/linux/gnu/mod.rs | 1 -
 src/unix/mod.rs                      | 3 +++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs
index 9ea34dec..6ead42fe 100644
--- a/src/unix/linux_like/linux/gnu/mod.rs
+++ b/src/unix/linux_like/linux/gnu/mod.rs
@@ -1435,7 +1435,6 @@ extern "C" {
     ) -> ::c_int;
 }
 
-#[link(name = "dl")]
 extern "C" {
     pub fn dlmopen(
         lmid: Lmid_t,
diff --git a/src/unix/mod.rs b/src/unix/mod.rs
index 32e8d932..21439c8a 100644
--- a/src/unix/mod.rs
+++ b/src/unix/mod.rs
@@ -309,6 +309,8 @@ cfg_if! {
             cfg(target_feature = "crt-static"))]
         #[link(name = "m", kind = "static-nobundle",
             cfg(target_feature = "crt-static"))]
+        #[link(name = "dl", kind = "static-nobundle",
+            cfg(target_feature = "crt-static"))]
         #[link(name = "c", kind = "static-nobundle",
             cfg(target_feature = "crt-static"))]
         #[link(name = "gcc_eh", kind = "static-nobundle",
@@ -319,6 +321,7 @@ cfg_if! {
         #[link(name = "rt", cfg(not(target_feature = "crt-static")))]
         #[link(name = "pthread", cfg(not(target_feature = "crt-static")))]
         #[link(name = "m", cfg(not(target_feature = "crt-static")))]
+        #[link(name = "dl", cfg(not(target_feature = "crt-static")))]
         #[link(name = "c", cfg(not(target_feature = "crt-static")))]
         extern {}
     } else if #[cfg(target_env = "musl")] {
-- 
GitLab