Skip to content
Open
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
5 changes: 2 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ AC_FUNC_VPRINTF
AC_FUNC_MEMCMP
AC_CHECK_FUNCS(strcasecmp strdup strerror snprintf vsnprintf vasprintf open vsyslog strncasecmp setlocale)

if test "$ac_cv_have_decl_isnan" = "yes" ; then
AC_TRY_LINK([#include <math.h>], [float f = 0.0; return isnan(f)], [], [LIBS="$LIBS -lm"])
fi
# Force linking against libm (needed for modf on glibc >= 2.42)
AC_CHECK_LIB([m], [modf], [LIBS="$LIBS -lm"],[AC_MSG_ERROR([libm (math library) is required for modf()])])

Choose a reason for hiding this comment

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

high

This change is insufficient to link libfastjson.so against libm. The LIBS variable is not used by libtool for linking shared libraries; instead, dependencies should be added to the _LIBADD variable in Makefile.am.

To correctly link libfastjson.so against libm, you'll need to modify both configure.ac and Makefile.am.

  1. In configure.ac, create and substitute a variable for the math library. You can replace the current line with:

    LIBM=""
    AC_CHECK_LIB([m], [modf], [LIBM="-lm"], [AC_MSG_ERROR([libm (math library) is required for modf()])])
    AC_SUBST([LIBM])
    LIBS="$LIBS $LIBM"

    This creates a LIBM variable for Makefile.am and also updates LIBS for pkg-config.

  2. In Makefile.am (which you'll need to add to this PR), use this new variable:

    libfastjson_la_LIBADD = libfastjson-internal.la $(LIBM)

This will ensure libfastjson.so is correctly linked against libm, achieving the goal of this pull request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is a false positive. I am matching existing style which already writes directly into $LIBS variable and I verified that the resulting libfastjson.so is now linked against libm:

$ objdump -x /usr/lib64/libfastjson.so.4.3.0 | grep NEEDED | grep libm
  NEEDED               libm.so.6

Copy link
Contributor

Choose a reason for hiding this comment

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

my autotools knowledge is a bit rusty at this point but his looks correct to me. Thanks @Whissi !

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is a false positive. I am matching existing style which already writes directly into $LIBS variable and I verified that the resulting libfastjson.so is now linked against libm:

The generated Makefile.in looks like this:

Makefile.in:    $(AM_V_CCLD)$(libfastjson_internal_la_LINK)  $(libfastjson_internal_la_OBJECTS) $(libfastjson_internal_la_LIBADD) $(LIBS)

Which would confirm that LIBS is actually passed to the linker flags.


#check if .section.gnu.warning accepts long strings (for __warn_references)
AC_LANG_PUSH([C])
Expand Down
2 changes: 1 addition & 1 deletion libfastjson.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Description: a fast JSON implementation in C
Version: @VERSION@
Requires:
Libs.private: @LIBS@
Libs: -L${libdir} -lfastjson -lm
Libs: -L${libdir} -lfastjson
Cflags: -I${includedir}/libfastjson