1From 02a44ee1df8176c72e75fd706d1a8f063d3196d5 Mon Sep 17 00:00:00 2001
2From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
3Date: Mon, 5 Nov 2018 22:50:40 +0100
4Subject: Fix linkage with a system libatomic_ops shared library
5
6Issue #247 (bdwgc).
7
8When bdwgc is linked with the external libatomic_ops, bdw-gc.pc must
9contain the needed dynamic libraries (such as -latomic_ops) otherwise
10build of applications could fail on the link stage on some hosts:
11* libgc.so: undefined reference to 'AO_fetch_compare_and_swap_emulation'
12* libgc.so: undefined reference to 'AO_store_full_emulation'
13
14So, this commit sets ATOMIC_OPS_LIBS to "-latomic_ops" when a system
15atomic_ops library is used and uses ATOMIC_OPS_LIBS in bdw-gc.pc.in.
16
17* bdw-gc.pc.in (Libs): Add @ATOMIC_OPS_LIBS@.
18* configure.ac [$with_libatomic_ops!=no && $with_libatomic_ops!=none
19&& $THREADS!=none] (ATOMIC_OPS_LIBS): Set to -latomic_ops; do AC_SUBST.
20
21Fix is cherry-picked from bdwgc upstream
22
23Link to original commit https://github.com/ivmai/bdwgc/commit/02a44ee1df8176c72e75fd706d1a8f063d3196d5?branch=02a44ee1df8176c72e75fd706d1a8f063d3196d5&diff=unified
24
25Signed-off-by: Illia Bitkov <illia.bitkov@mind.be>
26
27diff --git a/external/bdwgc/bdw-gc.pc.in b/external/bdwgc/bdw-gc.pc.in
28index ef4c2341..a32e7598 100644
29--- a/external/bdwgc/bdw-gc.pc.in
30+++ b/external/bdwgc/bdw-gc.pc.in
31@@ -6,5 +6,5 @@ includedir=@includedir@
32 Name: Boehm-Demers-Weiser Conservative Garbage Collector
33 Description: A garbage collector for C and C++
34 Version: @PACKAGE_VERSION@
35-Libs: -L${libdir} -lgc
36+Libs: -L${libdir} @ATOMIC_OPS_LIBS@ -lgc
37 Cflags: -I${includedir}
38diff --git a/external/bdwgc/configure.ac b/external/bdwgc/configure.ac
39index 21abe8fa..9ffe81de 100644
40--- a/external/bdwgc/configure.ac
41+++ b/external/bdwgc/configure.ac
42@@ -1081,7 +1081,9 @@ AS_IF([test x"$with_libatomic_ops" = xno \
43 AC_MSG_CHECKING([which libatomic_ops to use])
44 AS_IF([test x"$with_libatomic_ops" != xno],
45   [ AS_IF([test x"$with_libatomic_ops" != xnone -a x"$THREADS" != xnone],
46-          [ AC_MSG_RESULT([external]) ],
47+          [ AC_MSG_RESULT([external])
48+            ATOMIC_OPS_LIBS="-latomic_ops"
49+            AC_SUBST([ATOMIC_OPS_LIBS]) ],
50           [ AC_MSG_RESULT([none])
51             AS_IF([test x"$THREADS" != xnone],
52                   [ AC_DEFINE([GC_BUILTIN_ATOMIC], [1],
53