public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: soeren@soeren-tempel.net
To: iant@golang.org
Cc: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com
Subject: [PATCH] libgo: check if -lucontext is required for {make,set,get}context
Date: Mon, 19 Dec 2022 17:59:22 +0100	[thread overview]
Message-ID: <20221219165922.25443-1-soeren@soeren-tempel.net> (raw)

From: Sören Tempel <soeren@soeren-tempel.net>

This patch is similar to the existing check for librt. If libucontext
is installed and libucontext.a provides the aforementioned symbols, then
it is added to $LIBS. If not, no error is emitted. We could,
alternatively, also check libc.a for these symbols and thus prefer libc
over libucontext if both are installed and provide the symbols. If
deemed desirable, this could be achieved by changing the invocation
to AC_SEARCH_LIBS([makecontext], [c ucontext]).

This version of this patch has been tested on x86_64 Alpine Linux Edge
(libucontext 1.2 + musl 1.2.3) and Arch Linux (glibc 2.36). On the
latter, the check is a no-op and $LIBS is not modified.

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
---
 libgo/configure    | 178 +++++++++++++++++++++++++++++++++++++++++++++
 libgo/configure.ac |   5 ++
 2 files changed, 183 insertions(+)

diff --git a/libgo/configure b/libgo/configure
index 460fdad7..ac9202dc 100755
--- a/libgo/configure
+++ b/libgo/configure
@@ -14818,6 +14818,184 @@ fi
 
 
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for library containing makecontext" >&5
+printf %s "checking for library containing makecontext... " >&6; }
+if test ${ac_cv_search_makecontext+y}
+then :
+  printf %s "(cached) " >&6
+else $as_nop
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+char makecontext ();
+int
+main (void)
+{
+return makecontext ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' ucontext
+do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"
+then :
+  ac_cv_search_makecontext=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam \
+    conftest$ac_exeext
+  if test ${ac_cv_search_makecontext+y}
+then :
+  break
+fi
+done
+if test ${ac_cv_search_makecontext+y}
+then :
+
+else $as_nop
+  ac_cv_search_makecontext=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_makecontext" >&5
+printf "%s\n" "$ac_cv_search_makecontext" >&6; }
+ac_res=$ac_cv_search_makecontext
+if test "$ac_res" != no
+then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for library containing getcontext" >&5
+printf %s "checking for library containing getcontext... " >&6; }
+if test ${ac_cv_search_getcontext+y}
+then :
+  printf %s "(cached) " >&6
+else $as_nop
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+char getcontext ();
+int
+main (void)
+{
+return getcontext ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' ucontext
+do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"
+then :
+  ac_cv_search_getcontext=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam \
+    conftest$ac_exeext
+  if test ${ac_cv_search_getcontext+y}
+then :
+  break
+fi
+done
+if test ${ac_cv_search_getcontext+y}
+then :
+
+else $as_nop
+  ac_cv_search_getcontext=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_getcontext" >&5
+printf "%s\n" "$ac_cv_search_getcontext" >&6; }
+ac_res=$ac_cv_search_getcontext
+if test "$ac_res" != no
+then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for library containing setcontext" >&5
+printf %s "checking for library containing setcontext... " >&6; }
+if test ${ac_cv_search_setcontext+y}
+then :
+  printf %s "(cached) " >&6
+else $as_nop
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+char setcontext ();
+int
+main (void)
+{
+return setcontext ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' ucontext
+do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"
+then :
+  ac_cv_search_setcontext=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam \
+    conftest$ac_exeext
+  if test ${ac_cv_search_setcontext+y}
+then :
+  break
+fi
+done
+if test ${ac_cv_search_setcontext+y}
+then :
+
+else $as_nop
+  ac_cv_search_setcontext=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_setcontext" >&5
+printf "%s\n" "$ac_cv_search_setcontext" >&6; }
+ac_res=$ac_cv_search_setcontext
+if test "$ac_res" != no
+then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing sched_yield" >&5
 $as_echo_n "checking for library containing sched_yield... " >&6; }
 if ${ac_cv_search_sched_yield+:} false; then :
diff --git a/libgo/configure.ac b/libgo/configure.ac
index 09554a37..cd1ef8f7 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -570,6 +570,11 @@ PTHREAD_LIBS=
 AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS=-lpthread)
 AC_SUBST(PTHREAD_LIBS)
 
+dnl Test if -lucontext is required for makecontext, getcontext, or setcontext.
+AC_SEARCH_LIBS([makecontext], [ucontext])
+AC_SEARCH_LIBS([getcontext], [ucontext])
+AC_SEARCH_LIBS([setcontext], [ucontext])
+
 dnl Test if -lrt is required for sched_yield or nanosleep or clock_gettime.
 AC_SEARCH_LIBS([sched_yield], [rt])
 AC_SEARCH_LIBS([nanosleep], [rt])

             reply	other threads:[~2022-12-19 16:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-19 16:59 soeren [this message]
2022-12-21  3:35 ` Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221219165922.25443-1-soeren@soeren-tempel.net \
    --to=soeren@soeren-tempel.net \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gofrontend-dev@googlegroups.com \
    --cc=iant@golang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).