Fossil SCM

Rework [8d3b9bf4d4] such that (-lm -ldl -lpthread) are always appended to the global LIBS if the libraries exist on the system, even if they're not explicitly needed by a given feature (in which case they become no-ops). If they are already called for in LIBS, they're unconditionally moved to the end of LIBS. Based on /chat discussion.

stephan 2025-02-28 02:50 trunk
Commit 374e73c6f963ba497b348afc8bf8eee49f8b6574c4618328884f13b6abfb87d3
2 files changed +24 -36 +30
+24 -36
--- auto.def
+++ auto.def
@@ -337,28 +337,12 @@
337337
}
338338
339339
# Check for libraries that need to be sorted out early
340340
cc-check-function-in-lib iconv iconv
341341
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
-}
342
+cc-check-function-in-lib sin m
343
+cc-check-function-in-lib dlopen dl
360344
361345
# Helper for OpenSSL checking
362346
proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto -lpthread}}} {
363347
msg-checking "Checking for $msg..."
364348
set rc 0
@@ -965,36 +949,40 @@
965949
966950
handle-with-openssl
967951
968952
# Finally, append libraries that must be last. This matters more on some
969953
# OSes than others, but is most broadly required for static linking.
970
-define-append LIBS $ldFlagsDL
971954
if {[opt-bool static]} {
972955
# Linux can only infer the dependency on pthread from OpenSSL when
973956
# doing dynamic linkage.
974957
define-append LIBS -lpthread
975958
}
976959
977960
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.
961
+ # This started out as a workaround for getting the ordering of -ldl
962
+ # correct in conjunction with openssl in some environments. Then it
963
+ # evolved into a more generic preemptive portability workaround to
964
+ # ensure that certain libraries are always appended to the global
965
+ # LIBS list if they exist on the system. Based on a /chat discussion
966
+ # on 2025-02-27 in the context of check-in [8d3b9bf4d4].
967
+ #
968
+ # Note that [move-lib-to-end] and [lib-actually-exists] are in
969
+ # autosetup/local.tcl.
983970
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
971
+ #puts "**** 1 LIBS: $libs"
972
+ foreach ll {-ldl -lpthread -lm} {
973
+ if {![move-lib-to-end $ll $libs libs]} {
974
+ # $ll was not in the list
975
+ if {[lib-actually-exists $ll]} {
976
+ # Add it to the list "just in case." This will be a no-op on
977
+ # systems where the lib is not actually used.
978
+ lappend libs $ll
979
+ }
980
+ }
981
+ }
982
+ #puts "**** 2 LIBS: $libs"
983
+ define LIBS [join $libs " "]
996984
}}
997985
998986
# Tag container builds with a prefix of the checkin ID of the version
999987
# of Fossil each one contains. This not only allows multiple images
1000988
# to coexist and multiple containers to be created unamgiguosly from
1001989
--- auto.def
+++ auto.def
@@ -337,28 +337,12 @@
337 }
338
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
@@ -965,36 +949,40 @@
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
--- auto.def
+++ auto.def
@@ -337,28 +337,12 @@
337 }
338
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
343 cc-check-function-in-lib dlopen dl
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@@ -965,36 +949,40 @@
949
950 handle-with-openssl
951
952 # Finally, append libraries that must be last. This matters more on some
953 # OSes than others, but is most broadly required for static linking.
 
954 if {[opt-bool static]} {
955 # Linux can only infer the dependency on pthread from OpenSSL when
956 # doing dynamic linkage.
957 define-append LIBS -lpthread
958 }
959
960 apply {{} {
961 # This started out as a workaround for getting the ordering of -ldl
962 # correct in conjunction with openssl in some environments. Then it
963 # evolved into a more generic preemptive portability workaround to
964 # ensure that certain libraries are always appended to the global
965 # LIBS list if they exist on the system. Based on a /chat discussion
966 # on 2025-02-27 in the context of check-in [8d3b9bf4d4].
967 #
968 # Note that [move-lib-to-end] and [lib-actually-exists] are in
969 # autosetup/local.tcl.
970 set libs [get-define LIBS]
971 #puts "**** 1 LIBS: $libs"
972 foreach ll {-ldl -lpthread -lm} {
973 if {![move-lib-to-end $ll $libs libs]} {
974 # $ll was not in the list
975 if {[lib-actually-exists $ll]} {
976 # Add it to the list "just in case." This will be a no-op on
977 # systems where the lib is not actually used.
978 lappend libs $ll
979 }
980 }
981 }
982 #puts "**** 2 LIBS: $libs"
983 define LIBS [join $libs " "]
984 }}
985
986 # Tag container builds with a prefix of the checkin ID of the version
987 # of Fossil each one contains. This not only allows multiple images
988 # to coexist and multiple containers to be created unamgiguosly from
989
--- autosetup/local.tcl
+++ autosetup/local.tcl
@@ -27,5 +27,35 @@
2727
set tclconfig($name) [string trim $value ']
2828
}
2929
}
3030
return [array get tclconfig]
3131
}
32
+
33
+#
34
+# Given a library link flag, e.g. -lfoo, returns 1 if that library can
35
+# actually be linked to, else returns 0.
36
+proc lib-actually-exists {linkFlag} {
37
+ cctest -link 1 -code "void libActuallyExists(void){}" -libs $linkFlag
38
+}
39
+
40
+#
41
+# Given a library flag, e.g. -lfoo, a list of libs, e.g. {-lfoo -lbar
42
+# -lbaz}, and a target variable name, this function appends all
43
+# entries of $libList which do not match $flag to $tgtVar, then
44
+# appends $flag to the end of $tgtVar. Returns the number of matches
45
+# found.
46
+proc move-lib-to-end {flag libList tgtVar} {
47
+ upvar $tgtVar tgt
48
+ set tgt {}
49
+ set found 0
50
+ foreach e $libList {
51
+ if {$flag eq $e} {
52
+ incr found
53
+ } else {
54
+ lappend tgt $e
55
+ }
56
+ }
57
+ if {$found} {
58
+ lappend tgt $flag
59
+ }
60
+ return $found
61
+}
3262
--- autosetup/local.tcl
+++ autosetup/local.tcl
@@ -27,5 +27,35 @@
27 set tclconfig($name) [string trim $value ']
28 }
29 }
30 return [array get tclconfig]
31 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
--- autosetup/local.tcl
+++ autosetup/local.tcl
@@ -27,5 +27,35 @@
27 set tclconfig($name) [string trim $value ']
28 }
29 }
30 return [array get tclconfig]
31 }
32
33 #
34 # Given a library link flag, e.g. -lfoo, returns 1 if that library can
35 # actually be linked to, else returns 0.
36 proc lib-actually-exists {linkFlag} {
37 cctest -link 1 -code "void libActuallyExists(void){}" -libs $linkFlag
38 }
39
40 #
41 # Given a library flag, e.g. -lfoo, a list of libs, e.g. {-lfoo -lbar
42 # -lbaz}, and a target variable name, this function appends all
43 # entries of $libList which do not match $flag to $tgtVar, then
44 # appends $flag to the end of $tgtVar. Returns the number of matches
45 # found.
46 proc move-lib-to-end {flag libList tgtVar} {
47 upvar $tgtVar tgt
48 set tgt {}
49 set found 0
50 foreach e $libList {
51 if {$flag eq $e} {
52 incr found
53 } else {
54 lappend tgt $e
55 }
56 }
57 if {$found} {
58 lappend tgt $flag
59 }
60 return $found
61 }
62

Keyboard Shortcuts

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