Skip to content

gh-127604: Optimize -ldl usage on platforms that use dlopen for libFFI. #133081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 112 additions & 101 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 16 additions & 9 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2985,15 +2985,6 @@ AC_CHECK_HEADERS([ \
AC_HEADER_DIRENT
AC_HEADER_MAJOR

# for faulthandler
AC_CHECK_HEADERS([execinfo.h link.h dlfcn.h], [
AC_CHECK_FUNCS([backtrace dladdr1], [
# dladdr1 requires -ldl
ac_cv_require_ldl=yes
])
])
AS_VAR_IF([ac_cv_require_ldl], [yes], [AS_VAR_APPEND([LDFLAGS], [" -ldl"])])

# bluetooth/bluetooth.h has been known to not compile with -std=c99.
# http://permalink.gmane.org/gmane.linux.bluez.kernel/22294
SAVE_CFLAGS=$CFLAGS
Expand Down Expand Up @@ -3715,6 +3706,22 @@ AC_CHECK_LIB([dl], [dlopen]) # Dynamic linking for SunOS/Solaris and SYSV
AC_CHECK_LIB([dld], [shl_load]) # Dynamic linking for HP-UX


dnl for faulthandler
AC_CHECK_HEADERS([execinfo.h link.h dlfcn.h], [
AC_CHECK_FUNCS([backtrace dladdr1], [
# dladdr1 requires -ldl
ac_cv_require_ldl=yes
])
])

dnl only add -ldl to LDFLAGS if it isn't already part of LIBS (GH-133081)
AS_VAR_IF([ac_cv_require_ldl], [yes], [
AS_VAR_IF([ac_cv_lib_dl_dlopen], [yes], [], [
AS_VAR_APPEND([LDFLAGS], [" -ldl"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would autoconf be smart enough if we were to just use AC_CHECK_LIB for dladdr1 as we did for dlopen in that it wouldn't readd the -ldl flag or is it the only way to write these extra checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't know - I know enough autoconf to get by, but not much more.

Unfortunately, I don't have ready access to a development platform that would use the dladdr1 check (at least, I don't think I do), so it's difficult for me to experiment with this.

My concern would be whether it would add the flag to LIBS or LDFLAGS though - if it's added to LIBS, we'll be back in the same situation as before. Based on what I'm seeing in other AC_CHECK_LIB usage, it looks like it would get added to LIBS by default, and any strategy that got it into LDFLAGS would essentially be no better than AS_VAR_APPEND.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Let's keep it that way (it works, it's a bit fragile, but we'll manage if there are issues in the future)

])
])


dnl check for uuid dependencies
AH_TEMPLATE([HAVE_UUID_H], [Define to 1 if you have the <uuid.h> header file.])
AH_TEMPLATE([HAVE_UUID_UUID_H], [Define to 1 if you have the <uuid/uuid.h> header file.])
Expand Down
Loading