From e1cd2e0dedf1b0d0410dd9927319f96f3b319a9b Mon Sep 17 00:00:00 2001 From: Mobin Aydinfar Date: Sat, 26 Sep 2026 23:10:19 +0330 Subject: [PATCH 1/2] configure: be consistent with Makefiles about the linker flags usage Specify the linker flags at the end of the compiler driver invocation in try_link_object(), like how Makefiles do. The ordering of compiler driver flags is important, for example if the linker is invoked with '--as-needed' flag, it would discard any library that doesn't satisfiy a non-weak symbol at the time of being loaded and because 'configure' specified linker flags (and potentially libraries) before the object, it would make the linker discard the specified library, leading to false "undefined symbols" when the linker tries to link the object. See ld(1) for more information. --- configure | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index be25f5a1..b0b8d7cf 100755 --- a/configure +++ b/configure @@ -116,8 +116,8 @@ try_compile_source() # LDFLAGS, LDFLAGS_EXTRA - any predetermined flags try_link_object() { - eval $CXX $LDFLAGS $LDFLAGS_EXTRA ${3:-} '"$configtmpdir"/"$1"' \ - -o '"$configtmpdir"/"$2"' > /dev/null 2>&1 + eval $CXX '"$configtmpdir"/"$1"' -o '"$configtmpdir"/"$2"' $LDFLAGS \ + $LDFLAGS_EXTRA ${3:-} > /dev/null 2>&1 } # Test if the compiler accepts an argument (for compilation only); if so add it to named variable. From 8062e5b1cd118269dff340a9b072c2e4653ed93f Mon Sep 17 00:00:00 2001 From: Mobin Aydinfar Date: Fri, 28 Aug 2026 05:40:55 +0330 Subject: [PATCH 2/2] configure: check if "-lrt" is required for using the Dasynq timers Check if using a Dasynq timer in a test program requires linking with librt, then supply "-lrt" in the LDFLGAS_BASE of the build if it does. Perviously 'configure' only added the "-lrt" flag for the FreeBSD, which was known for requiring it. --- configure | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/configure b/configure index b0b8d7cf..3baeef7a 100755 --- a/configure +++ b/configure @@ -235,6 +235,37 @@ int main() _EOF } +write_librt_check() +{ + cat << _EOF > "$configtmpdir"/librt-check.cc +#include + +using rearm = dasynq::rearm; +using loop_t = dasynq::event_loop_n; + +class my_timer : public loop_t::timer_impl +{ +public: + rearm timer_expiry(loop_t &, int expiry_count) + { + return rearm::REARM; + } +}; + +int main() +{ + loop_t l1; + my_timer t1; + + t1.add_timer(l1); + t1.arm_timer_rel(l1, {1,0}); + l1.run(); + + return 0; +} +_EOF +} + # Quote a string to preserve its original form after shell evaluation (except that an empty # string remains as an empty string). quote_for_shell() @@ -636,8 +667,27 @@ if [ "$AUTO_LDFLAGS" = true ] && [ "$AUTO_CXXFLAGS" = true ]; then HAS_LTO="false" fi fi -if [ "$AUTO_LDFLAGS_BASE" = true ] && [ "$PLATFORM" = FreeBSD ]; then - check_link_argument LDFLAGS_BASE -lrt +if [ "$AUTO_LDFLAGS_BASE" = true ]; then + info "Checking whether linking with librt is required..." + write_librt_check + # CPPFLAGS is included in the following check, because it uses the Dasynq library that can be + # configured by compile-time macros, which can influence the result of this check. For example, + # a user under Linux may specify "-DDASYNQ_HAVE_EPOLL=0" to disable the epoll backend, which + # currently also causes Dasynq to use POSIX timers. + if ! try_compile_source librt-check.cc librt-check.o "$CPPFLAGS -Idasynq/include"; then + sub_info_error "Couldn't compile the test source for the librt check." + fi + if ! try_link_object librt-check.o librt-check; then + if try_link_object librt-check.o librt-check -lrt; then + sub_info "Yes." + LDFLAGS_BASE="$LDFLAGS_BASE -lrt" + LDFLAGS_BASE="${LDFLAGS_BASE# }" + else + sub_info_error "Couldn't link the test object for the librt check." + fi + else + sub_info "No." + fi fi if [ "$SUPPORT_CAPABILITIES" != 0 ]; then if [ "$AUTO_LDFLAGS_LIBCAP" = true ]; then