From 71fcb3c9942c0e4b811af46c5205643e5a8b1a52 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 4 Nov 2021 15:07:28 +0100 Subject: [PATCH] Only link with libdl on Linux Requiring an extra library for dlopen is a Linux non-POSIX-compliance. Signed-off-by: Gilles Peskine --- programs/Makefile | 8 +++++++- programs/test/CMakeLists.txt | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 2a3fd6f25..7b9c5dd0a 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -18,6 +18,12 @@ LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \ -lmbedx509$(SHARED_SUFFIX) \ -lmbedcrypto$(SHARED_SUFFIX) +ifeq ($(shell uname -s),Linux) +DLOPEN_LDFLAGS ?= -ldl +else +DLOPEN_LDFLAGS ?= +endif + include ../3rdparty/Makefile.inc LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES) @@ -328,7 +334,7 @@ test/dlopen$(EXEXT): test/dlopen.c $(DEP) # Do not link any test objects (that would bring in a static dependency on # libmbedcrypto at least). Do not link with libmbed* (that would defeat the # purpose of testing dynamic loading). - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/dlopen.c $(LDFLAGS) -ldl -o $@ + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/dlopen.c $(LDFLAGS) $(DLOPEN_LDFLAGS) -o $@ endif test/query_config.o: test/query_config.c test/query_config.h $(DEP) diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index 6233de423..a30c89c58 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -38,7 +38,9 @@ endif() if(USE_SHARED_MBEDTLS_LIBRARY) add_executable(dlopen "dlopen.c") target_include_directories(dlopen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include) - target_link_libraries(dlopen "-ldl") + if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + target_link_libraries(dlopen "-ldl") + endif() endif() foreach(exe IN LISTS executables_libs executables_mbedcrypto)