From f92c9c0d40d0cd5efe2bc08dbfbf02cf7bc2ed3e Mon Sep 17 00:00:00 2001
From: Greg Steuck <greg@nest.cx>
Date: Sat, 18 Dec 2021 15:40:47 -0800
Subject: [PATCH] Only use -ldl conditionally to fix T3807

OpenBSD doesn't have this library and so the linker complains:
ld.lld: error: unable to find library -ldl
---
 testsuite/mk/boilerplate.mk      | 6 ++++++
 testsuite/tests/dynlibs/Makefile | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/testsuite/mk/boilerplate.mk b/testsuite/mk/boilerplate.mk
index 2f5c23bc0c5a..9b66ee1d1ea5 100644
--- a/testsuite/mk/boilerplate.mk
+++ b/testsuite/mk/boilerplate.mk
@@ -303,3 +303,9 @@ LIBCXX_PLATFORM = YES
 else
 LIBCXX_PLATFORM = NO
 endif
+ifeq "$(HostOS)" "openbsd"
+# None required, dlopen and the like are in libc.
+LIBDL_NAME =
+else
+LIBDL_NAME = -ldl
+endif
diff --git a/testsuite/tests/dynlibs/Makefile b/testsuite/tests/dynlibs/Makefile
index 3de7571f27df..f557a1238a14 100644
--- a/testsuite/tests/dynlibs/Makefile
+++ b/testsuite/tests/dynlibs/Makefile
@@ -15,7 +15,7 @@ T3807:
 	# when linking an executable).
 	# Hence we must explicitly linking with the RTS here.
 	'$(TEST_HC)' $(filter-out -rtsopts,$(TEST_HC_OPTS)) -v0 --make -dynamic -fPIC -shared T3807Export.hs T3807-export.c -o T3807test.so -flink-rts
-	'$(TEST_HC)' $(filter-out -rtsopts,$(TEST_HC_OPTS)) -no-auto-link-packages -no-hs-main T3807-load.c -o T3807-load -ldl
+	'$(TEST_HC)' $(filter-out -rtsopts,$(TEST_HC_OPTS)) -no-auto-link-packages -no-hs-main T3807-load.c -o T3807-load $(LIBDL_NAME)
 	./T3807-load
 
 .PHONY: T4464dyn
-- 
GitLab