Fossil SCM
Adjust auto.def so that -ldl is included after -lcrypto on systems that need that.
Commit
8d3b9bf4d49b6e54a4d71bf9c334ac091bf0ae5b8f6de726678670c4ad36785e
Parent
ea2fbaf05ab1fd0…
1 file changed
+40
-5
M
auto.def
+40
-5
| --- auto.def | ||
| +++ auto.def | ||
| @@ -339,10 +339,26 @@ | ||
| 339 | 339 | # Check for libraries that need to be sorted out early |
| 340 | 340 | cc-check-function-in-lib iconv iconv |
| 341 | 341 | |
| 342 | 342 | cc-check-function-in-lib sin m ;# must come before ssl check: |
| 343 | 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 | +} | |
| 344 | 360 | |
| 345 | 361 | # Helper for OpenSSL checking |
| 346 | 362 | proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto -lpthread}}} { |
| 347 | 363 | msg-checking "Checking for $msg..." |
| 348 | 364 | set rc 0 |
| @@ -507,10 +523,12 @@ | ||
| 507 | 523 | set ssllibs "$dir/libssl.a $dir/libcrypto.a -lpthread" |
| 508 | 524 | if {[check-for-openssl $msg "$cflags $ldflags" $ssllibs]} { |
| 509 | 525 | incr found |
| 510 | 526 | break |
| 511 | 527 | } |
| 528 | + # This test should arguably fail here if --with-openssl=X | |
| 529 | + # points to an invalid X. | |
| 512 | 530 | } |
| 513 | 531 | } |
| 514 | 532 | } |
| 515 | 533 | } |
| 516 | 534 | if {$found} { |
| @@ -947,20 +965,37 @@ | ||
| 947 | 965 | |
| 948 | 966 | handle-with-openssl |
| 949 | 967 | |
| 950 | 968 | # Finally, append libraries that must be last. This matters more on some |
| 951 | 969 | # 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 | |
| 957 | 971 | if {[opt-bool static]} { |
| 958 | 972 | # Linux can only infer the dependency on pthread from OpenSSL when |
| 959 | 973 | # doing dynamic linkage. |
| 960 | 974 | define-append LIBS -lpthread |
| 961 | 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 | +}} | |
| 962 | 997 | |
| 963 | 998 | # Tag container builds with a prefix of the checkin ID of the version |
| 964 | 999 | # of Fossil each one contains. This not only allows multiple images |
| 965 | 1000 | # to coexist and multiple containers to be created unamgiguosly from |
| 966 | 1001 | # them, it also changes the URL we fetch the source tarball from, so |
| 967 | 1002 |
| --- 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 |