From patchwork Mon Dec 19 16:59:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 62159 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5AA3F3858401 for ; Mon, 19 Dec 2022 17:00:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5AA3F3858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671469210; bh=5Z9fX2/pm+Yj2TbD+Rm8O3vtz78Qj1q/zipC6jOp0co=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=S7q1rHyXySWGupL5xQTF/SrPTQO06Zvj1Y89e24s/FGjCARegOTWjkcoRPwkpy7G6 VmlWELC4GTbi28uyxqwzozumxwoH+vqwVfEWwDmSvM70mlN3TmEbdHsevlDZdK18Xr 1urCyOM+Jqwq0SB1fqSgiLIvXXuVZJtfYb5mxTfo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from magnesium.8pit.net (magnesium.8pit.net [45.76.88.171]) by sourceware.org (Postfix) with ESMTPS id 5C2283858D28; Mon, 19 Dec 2022 16:59:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5C2283858D28 Received: from localhost ( [2a02:8109:3b40:22d0:5fe7:d6ed:6702:b1ac]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id 5ecae41c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:YES); Mon, 19 Dec 2022 17:59:39 +0100 (CET) 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 Message-Id: <20221219165922.25443-1-soeren@soeren-tempel.net> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: soeren--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: soeren@soeren-tempel.net Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Sören Tempel 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 --- 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])