Commit 66198f447f45a87718b6457756976baa8defb2fd

Authored by Jay Berkenbilt
1 parent 578c5ac6

Use -latomic if needed with gcc

autofiles.sums
1 -e764290be37a921ecba94755b6da22dd9e9b98644b8fdfdd0fa7f1331ce56a05 configure.ac 1 +c9b8555013e70c93572e0be5f5c7c03c6b7e0680de4870010945357a02909eaa configure.ac
2 d3f9ee6f6f0846888d9a10fd3dad2e4b1258be84205426cf04d7cef02d61dad7 aclocal.m4 2 d3f9ee6f6f0846888d9a10fd3dad2e4b1258be84205426cf04d7cef02d61dad7 aclocal.m4
3 b0ce6d1dba8effa47d25154b2bb56eddafc997254a0f3f903cf9b6abffc03616 libqpdf/qpdf/qpdf-config.h.in 3 b0ce6d1dba8effa47d25154b2bb56eddafc997254a0f3f903cf9b6abffc03616 libqpdf/qpdf/qpdf-config.h.in
4 5297971a0ef90bcd5563eb3f7127a032bb76d3ae2af7258bf13479caf8983a60 m4/ax_cxx_compile_stdcxx.m4 4 5297971a0ef90bcd5563eb3f7127a032bb76d3ae2af7258bf13479caf8983a60 m4/ax_cxx_compile_stdcxx.m4
configure
@@ -16975,6 +16975,49 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ @@ -16975,6 +16975,49 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
16975 ac_compiler_gnu=$ac_cv_c_compiler_gnu 16975 ac_compiler_gnu=$ac_cv_c_compiler_gnu
16976 16976
16977 16977
  16978 +ac_ext=cpp
  16979 +ac_cpp='$CXXCPP $CPPFLAGS'
  16980 +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
  16981 +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
  16982 +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
  16983 +
  16984 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use -latomic" >&5
  16985 +$as_echo_n "checking whether to use -latomic... " >&6; }
  16986 +oLDFLAGS="$LDFLAGS"
  16987 +LDFLAGS="$LDFLAGS -Wl,--as-needed -latomic"
  16988 +cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  16989 +/* end confdefs.h. */
  16990 +#include <atomic>
  16991 + int main()
  16992 + {
  16993 + static std::atomic<int> a{0};
  16994 + a = a.fetch_add(1);
  16995 + return 0;
  16996 + }
  16997 +
  16998 +_ACEOF
  16999 +if ac_fn_cxx_try_link "$LINENO"; then :
  17000 + qpdf_USE_ATOMIC=1
  17001 +else
  17002 + qpdf_USE_ATOMIC=0
  17003 +fi
  17004 +rm -f core conftest.err conftest.$ac_objext \
  17005 + conftest$ac_exeext conftest.$ac_ext
  17006 +if test "$qpdf_USE_ATOMIC" = "1"; then
  17007 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
  17008 +$as_echo "yes" >&6; }
  17009 +else
  17010 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
  17011 +$as_echo "no" >&6; }
  17012 + LDFLAGS="$oLDFLAGS"
  17013 +fi
  17014 +ac_ext=c
  17015 +ac_cpp='$CPP $CPPFLAGS'
  17016 +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
  17017 +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
  17018 +ac_compiler_gnu=$ac_cv_c_compiler_gnu
  17019 +
  17020 +
16978 if test "x$qpdf_OS_SECURE_RANDOM" = "x1"; then 17021 if test "x$qpdf_OS_SECURE_RANDOM" = "x1"; then
16979 OLIBS=$LIBS 17022 OLIBS=$LIBS
16980 LIBS="$LIBS Advapi32.lib" 17023 LIBS="$LIBS Advapi32.lib"
configure.ac
@@ -240,6 +240,32 @@ for i in 0 1; do @@ -240,6 +240,32 @@ for i in 0 1; do
240 done 240 done
241 AC_LANG_POP 241 AC_LANG_POP
242 242
  243 +AC_LANG_PUSH([C++])
  244 +AC_MSG_CHECKING(whether to use -latomic)
  245 +dnl On some platforms with some versions of gcc, you have to link with
  246 +dnl -latomic in order for std::atomic to work. Passing --as-needed
  247 +dnl prevents unnecessary linking with -latomic.
  248 +oLDFLAGS="$LDFLAGS"
  249 +LDFLAGS="$LDFLAGS -Wl,--as-needed -latomic"
  250 +AC_LINK_IFELSE([AC_LANG_SOURCE(
  251 + [[#include <atomic>
  252 + int main()
  253 + {
  254 + static std::atomic<int> a{0};
  255 + a = a.fetch_add(1);
  256 + return 0;
  257 + }
  258 + ]])],
  259 + [qpdf_USE_ATOMIC=1],
  260 + [qpdf_USE_ATOMIC=0])
  261 +if test "$qpdf_USE_ATOMIC" = "1"; then
  262 + AC_MSG_RESULT(yes)
  263 +else
  264 + AC_MSG_RESULT(no)
  265 + LDFLAGS="$oLDFLAGS"
  266 +fi
  267 +AC_LANG_POP
  268 +
243 if test "x$qpdf_OS_SECURE_RANDOM" = "x1"; then 269 if test "x$qpdf_OS_SECURE_RANDOM" = "x1"; then
244 OLIBS=$LIBS 270 OLIBS=$LIBS
245 LIBS="$LIBS Advapi32.lib" 271 LIBS="$LIBS Advapi32.lib"