Fossil SCM

Adjust auto.def so that -ldl is included after -lcrypto on systems that need that.

drh 2025-02-28 00:52 trunk
Commit 8d3b9bf4d49b6e54a4d71bf9c334ac091bf0ae5b8f6de726678670c4ad36785e
1 file changed +40 -5
+40 -5
--- auto.def
+++ auto.def
@@ -339,10 +339,26 @@
339339
# Check for libraries that need to be sorted out early
340340
cc-check-function-in-lib iconv iconv
341341
342342
cc-check-function-in-lib sin m ;# must come before ssl check:
343343
# https://fossil-scm.org/forum/forumpost/afcd42b7fd
344
+
345
+#
346
+# Inclusion (or not) of -ldl interacts in mysterious ways with the libssl
347
+# detection. This is an attempt to work around that on systems which require
348
+# -ldl for dlopen().
349
+#
350
+set ldFlagsDL ""
351
+set hasLDL [cctest -link 1 -code "int foo(void){return 1;}" -libs -ldl]
352
+# ^^^ True if -ldl exists, independently of whether it's needed for dlopen()
353
+cc-with {} {
354
+ if {[cc-check-function-in-lib dlopen dl]} {
355
+ # Some platforms (*BSD) have the dl functions already in libc and no libdl.
356
+ # In such case we can link directly without -ldl.
357
+ set ldFlagsDL [get-define lib_dlopen]
358
+ }
359
+}
344360
345361
# Helper for OpenSSL checking
346362
proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto -lpthread}}} {
347363
msg-checking "Checking for $msg..."
348364
set rc 0
@@ -507,10 +523,12 @@
507523
set ssllibs "$dir/libssl.a $dir/libcrypto.a -lpthread"
508524
if {[check-for-openssl $msg "$cflags $ldflags" $ssllibs]} {
509525
incr found
510526
break
511527
}
528
+ # This test should arguably fail here if --with-openssl=X
529
+ # points to an invalid X.
512530
}
513531
}
514532
}
515533
}
516534
if {$found} {
@@ -947,20 +965,37 @@
947965
948966
handle-with-openssl
949967
950968
# Finally, append libraries that must be last. This matters more on some
951969
# OSes than others, but is most broadly required for static linking.
952
-if {[check-function-in-lib dlopen dl]} {
953
- # Some platforms (*BSD) have the dl functions already in libc and no libdl.
954
- # In such case we can link directly without -ldl.
955
- define-append LIBS [get-define lib_dlopen]
956
-}
970
+define-append LIBS $ldFlagsDL
957971
if {[opt-bool static]} {
958972
# Linux can only infer the dependency on pthread from OpenSSL when
959973
# doing dynamic linkage.
960974
define-append LIBS -lpthread
961975
}
976
+
977
+apply {{} {
978
+ # A kludgy workaround for moving -ldl to the end of the linker
979
+ # flags, if it's set, or adding it to the end if -lcrypto is in LIBS
980
+ # and the system actually has -ldl. This is not a "solution," per
981
+ # se, but an interim workaround for getting the ordering of -ldl
982
+ # right in conjunction with openssl in some environments.
983
+ set libs [get-define LIBS]
984
+ #set libs "-ldl $libs -ldl"; # just for testing
985
+ regsub -all -- -ldl $libs "" sub
986
+ if {$sub ne $libs} {
987
+ # -ldl was in the list, so move it to the end.
988
+ set libs "$sub -ldl"
989
+ } elseif {$::hasLDL && [string first -lcrypto "$libs"] >= 0} {
990
+ # System has -ldl but doesn't need it. We'll add it as a
991
+ # workaround for the fact that -lcrypto needs it on _some_
992
+ # systems. This will be a no-op on builds which don't need -ldl.
993
+ set libs "$sub -ldl"
994
+ }
995
+ define LIBS $libs
996
+}}
962997
963998
# Tag container builds with a prefix of the checkin ID of the version
964999
# of Fossil each one contains. This not only allows multiple images
9651000
# to coexist and multiple containers to be created unamgiguosly from
9661001
# them, it also changes the URL we fetch the source tarball from, so
9671002
--- auto.def
+++ auto.def
@@ -339,10 +339,26 @@
339 # Check for libraries that need to be sorted out early
340 cc-check-function-in-lib iconv iconv
341
342 cc-check-function-in-lib sin m ;# must come before ssl check:
343 # https://fossil-scm.org/forum/forumpost/afcd42b7fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
344
345 # Helper for OpenSSL checking
346 proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto -lpthread}}} {
347 msg-checking "Checking for $msg..."
348 set rc 0
@@ -507,10 +523,12 @@
507 set ssllibs "$dir/libssl.a $dir/libcrypto.a -lpthread"
508 if {[check-for-openssl $msg "$cflags $ldflags" $ssllibs]} {
509 incr found
510 break
511 }
 
 
512 }
513 }
514 }
515 }
516 if {$found} {
@@ -947,20 +965,37 @@
947
948 handle-with-openssl
949
950 # Finally, append libraries that must be last. This matters more on some
951 # OSes than others, but is most broadly required for static linking.
952 if {[check-function-in-lib dlopen dl]} {
953 # Some platforms (*BSD) have the dl functions already in libc and no libdl.
954 # In such case we can link directly without -ldl.
955 define-append LIBS [get-define lib_dlopen]
956 }
957 if {[opt-bool static]} {
958 # Linux can only infer the dependency on pthread from OpenSSL when
959 # doing dynamic linkage.
960 define-append LIBS -lpthread
961 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
962
963 # Tag container builds with a prefix of the checkin ID of the version
964 # of Fossil each one contains. This not only allows multiple images
965 # to coexist and multiple containers to be created unamgiguosly from
966 # them, it also changes the URL we fetch the source tarball from, so
967
--- auto.def
+++ auto.def
@@ -339,10 +339,26 @@
339 # Check for libraries that need to be sorted out early
340 cc-check-function-in-lib iconv iconv
341
342 cc-check-function-in-lib sin m ;# must come before ssl check:
343 # https://fossil-scm.org/forum/forumpost/afcd42b7fd
344
345 #
346 # Inclusion (or not) of -ldl interacts in mysterious ways with the libssl
347 # detection. This is an attempt to work around that on systems which require
348 # -ldl for dlopen().
349 #
350 set ldFlagsDL ""
351 set hasLDL [cctest -link 1 -code "int foo(void){return 1;}" -libs -ldl]
352 # ^^^ True if -ldl exists, independently of whether it's needed for dlopen()
353 cc-with {} {
354 if {[cc-check-function-in-lib dlopen dl]} {
355 # Some platforms (*BSD) have the dl functions already in libc and no libdl.
356 # In such case we can link directly without -ldl.
357 set ldFlagsDL [get-define lib_dlopen]
358 }
359 }
360
361 # Helper for OpenSSL checking
362 proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto -lpthread}}} {
363 msg-checking "Checking for $msg..."
364 set rc 0
@@ -507,10 +523,12 @@
523 set ssllibs "$dir/libssl.a $dir/libcrypto.a -lpthread"
524 if {[check-for-openssl $msg "$cflags $ldflags" $ssllibs]} {
525 incr found
526 break
527 }
528 # This test should arguably fail here if --with-openssl=X
529 # points to an invalid X.
530 }
531 }
532 }
533 }
534 if {$found} {
@@ -947,20 +965,37 @@
965
966 handle-with-openssl
967
968 # Finally, append libraries that must be last. This matters more on some
969 # OSes than others, but is most broadly required for static linking.
970 define-append LIBS $ldFlagsDL
 
 
 
 
971 if {[opt-bool static]} {
972 # Linux can only infer the dependency on pthread from OpenSSL when
973 # doing dynamic linkage.
974 define-append LIBS -lpthread
975 }
976
977 apply {{} {
978 # A kludgy workaround for moving -ldl to the end of the linker
979 # flags, if it's set, or adding it to the end if -lcrypto is in LIBS
980 # and the system actually has -ldl. This is not a "solution," per
981 # se, but an interim workaround for getting the ordering of -ldl
982 # right in conjunction with openssl in some environments.
983 set libs [get-define LIBS]
984 #set libs "-ldl $libs -ldl"; # just for testing
985 regsub -all -- -ldl $libs "" sub
986 if {$sub ne $libs} {
987 # -ldl was in the list, so move it to the end.
988 set libs "$sub -ldl"
989 } elseif {$::hasLDL && [string first -lcrypto "$libs"] >= 0} {
990 # System has -ldl but doesn't need it. We'll add it as a
991 # workaround for the fact that -lcrypto needs it on _some_
992 # systems. This will be a no-op on builds which don't need -ldl.
993 set libs "$sub -ldl"
994 }
995 define LIBS $libs
996 }}
997
998 # Tag container builds with a prefix of the checkin ID of the version
999 # of Fossil each one contains. This not only allows multiple images
1000 # to coexist and multiple containers to be created unamgiguosly from
1001 # them, it also changes the URL we fetch the source tarball from, so
1002

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button