From patchwork Sun Feb 13 19:05:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1592128 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=hrC6xoVz; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JxcJb6Qplz9s8s for ; Mon, 14 Feb 2022 06:06:06 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC4D3385802B for ; Sun, 13 Feb 2022 19:06:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC4D3385802B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644779163; bh=Ekhz3sB2Rcgiy+jrI/O9xrqnz4wZJTJrv44uW+RkwRk=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=hrC6xoVzTUkbqiQcUdJhDHkNKtbrfClP00QGZxBrchBr93TOB50Wl3Tt9V0wCu2aO 14qKw+JNljQOd14ksOJdtNTAxn8q6DQBToz4RolnMvvnDdzEsrRFs+T4e3zpSTmDz/ dxegkUJibVhc/l1Vz0Yifjt6k8a9EtGbp29L6TYg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 5354C3858D1E for ; Sun, 13 Feb 2022 19:05:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5354C3858D1E Received: by mail-ed1-x529.google.com with SMTP id cf2so24001943edb.9 for ; Sun, 13 Feb 2022 11:05:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Ekhz3sB2Rcgiy+jrI/O9xrqnz4wZJTJrv44uW+RkwRk=; b=1gVWQ+TWWpOka54sWDjYQm6UZ2F5dJcIcGvIxVnG7Fg4l/k4C+0gQEc6XM1kEBzZhF niFvDninwDmEAmLiLcRFu2k8kAXnDToK8aOEQgThTqYewjIvSKp5pWklFJkaAyuZXbGu jfsFLByLIVi8gJ0P8Vlbn9TAqzY7m5B9lMiIFH+ftWmIbJEEQL+0YoQ4U4wV/C/RrD8e P3jSwOEDf7YWLjoVnAcmK125bYCuxtBTraZiT+d0Cb3/nGrVqOxnqSn4Z4l+b8SjdjSK gtJSNgNzdZ6fe2oRkBZYkRd/V7sOsJBtnVv6DIc9uNzugXYJNeyvGPgM3+KjLIuCKQwX 2MWw== X-Gm-Message-State: AOAM530HTs/uRPoFtCN6xnT4sBV+79MMrQT3QoNxPvR8dE5gNSOS3DG4 vGgxyBOODLWyw56iEzyxtbvTYw0PddzSmVtdZMCXW3Ur3aozgg== X-Google-Smtp-Source: ABdhPJyFzx5lytCHbBvKkRNRlpqrivvEG0wVuWtlqvcR40UsO4oWVXKVBwHkRifRyQtfna/K4lgE05buNeoPx83ebXM= X-Received: by 2002:aa7:c70b:: with SMTP id i11mr9310061edq.285.1644779117206; Sun, 13 Feb 2022 11:05:17 -0800 (PST) MIME-Version: 1.0 Date: Sun, 13 Feb 2022 11:05:05 -0800 Message-ID: Subject: Go patch committed: Call timer function via syscall. To: gcc-patches , gofrontend-dev X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Ian Lance Taylor via Gcc-patches From: Ian Lance Taylor Reply-To: Ian Lance Taylor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" It turns out to be painful to require linking against -lrt on GNU/Linux, as that makes it harder to link Go code into C programs. Instead just call the timer syscalls directly. That is what the upstream library does anyhow. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian gcc/go/ * gospec.cc: Revert 2022-02-09 change: (RTLIB, RT_LIBRARY): Don't define. (lang_specific_driver): Don't add -lrt if linking statically on GNU/Linux. gotools/ * configure.ac: Revert 2022-02-09 change: (RT_LIBS): Don't define. * Makefile.am (check-runtime): Don't set GOLIBS to $(RT_LIBS). * configure, Makefile.in: Regenerate. 2bb0e6232ac1dbfb0a93b5bbd0144b80f9d76cd3 diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 02a6e1d661d..745132a3d9d 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -7f8fee099d6de4a5a857765e0ddfae356ead554c +0af68c0552341a44f1fb12301f9eff954b9dde88 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gospec.cc b/gcc/go/gospec.cc index ba7ba4ea09d..df92b62d8e6 100644 --- a/gcc/go/gospec.cc +++ b/gcc/go/gospec.cc @@ -29,12 +29,10 @@ along with GCC; see the file COPYING3. If not see #define MATHLIB (1<<2) /* This bit is set if they did `-lpthread'. */ #define THREADLIB (1<<3) -/* This bit is set if they did `-lrt'. */ -#define RTLIB (1<<4) /* This bit is set if they did `-lc'. */ -#define WITHLIBC (1<<5) +#define WITHLIBC (1<<4) /* Skip this option. */ -#define SKIPOPT (1<<6) +#define SKIPOPT (1<<5) #ifndef MATH_LIBRARY #define MATH_LIBRARY "m" @@ -46,8 +44,6 @@ along with GCC; see the file COPYING3. If not see #define THREAD_LIBRARY "pthread" #define THREAD_LIBRARY_PROFILE THREAD_LIBRARY -#define RT_LIBRARY "rt" - #define LIBGO "go" #define LIBGO_PROFILE LIBGO #define LIBGOBEGIN "gobegin" @@ -78,9 +74,6 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, /* "-lpthread" if it appears on the command line. */ const struct cl_decoded_option *saw_thread = 0; - /* "-lrt" if it appears on the command line. */ - const struct cl_decoded_option *saw_rt = 0; - /* "-lc" if it appears on the command line. */ const struct cl_decoded_option *saw_libc = 0; @@ -91,9 +84,6 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, /* Whether we need the thread library. */ int need_thread = 0; - /* Whether we need the rt library. */ - int need_rt = 0; - /* By default, we throw on the math library if we have one. */ int need_math = (MATH_LIBRARY[0] != '\0'); @@ -166,8 +156,6 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, } else if (strcmp (arg, THREAD_LIBRARY) == 0) args[i] |= THREADLIB; - else if (strcmp (arg, RT_LIBRARY) == 0) - args[i] |= RTLIB; else if (strcmp (arg, "c") == 0) args[i] |= WITHLIBC; else @@ -272,7 +260,7 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, #endif /* Make sure to have room for the trailing NULL argument. */ - num_args = argc + need_math + shared_libgcc + (library > 0) * 6 + 10; + num_args = argc + need_math + shared_libgcc + (library > 0) * 5 + 10; new_decoded_options = XNEWVEC (struct cl_decoded_option, num_args); i = 0; @@ -326,12 +314,6 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, saw_thread = &decoded_options[i]; } - if (!saw_rt && (args[i] & RTLIB) && library > 0) - { - --j; - saw_rt = &decoded_options[i]; - } - if (!saw_libc && (args[i] & WITHLIBC) && library > 0) { --j; @@ -413,23 +395,9 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, #endif /* When linking libgo statically we also need to link with the - pthread and (on GNU/Linux) the rt library. */ + pthread library. */ if (library > 1 || static_link) - { - need_thread = 1; - if (strstr (DEFAULT_TARGET_MACHINE, "linux") != NULL) - need_rt = 1; - } - } - - if (saw_rt) - new_decoded_options[j++] = *saw_rt; - else if (library > 0 && need_rt) - { - generate_option (OPT_l, RT_LIBRARY, 1, CL_DRIVER, - &new_decoded_options[j]); - added_libraries++; - j++; + need_thread = 1; } if (saw_thread) diff --git a/gotools/Makefile.am b/gotools/Makefile.am index 46481cb5173..7b5302990f8 100644 --- a/gotools/Makefile.am +++ b/gotools/Makefile.am @@ -248,14 +248,12 @@ check-runtime: go$(EXEEXT) $(noinst_PROGRAMS) check-head check-gccgo check-gcc GOARCH=`$(abs_builddir)/go$(EXEEXT) env GOARCH`; \ GOOS=`$(abs_builddir)/go$(EXEEXT) env GOOS`; \ files=`$(SHELL) $(libgosrcdir)/../match.sh --goarch=$${GOARCH} --goos=$${GOOS} --srcdir=$(libgosrcdir)/runtime --extrafiles="$(libgodir)/runtime_linknames.go $(libgodir)/runtime_sysinfo.go $(libgodir)/sigtab.go $(libgodir)/goroot.go" --tag=libffi`; \ - echo "$(ECHO_ENV) GC='$(abs_builddir)/check-gccgo -fgo-compiling-runtime' GOARCH=$${GOARCH} GOOS=$${GOOS} GOLIBS='$(RT_LIBS)' $(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles='$${files}' $(GOTESTFLAGS) -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v" > runtime-testlog + echo "$(ECHO_ENV) GC='$(abs_builddir)/check-gccgo -fgo-compiling-runtime' GOARCH=$${GOARCH} GOOS=$${GOOS} $(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles='$${files}' $(GOTESTFLAGS) -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v" > runtime-testlog $(CHECK_ENV) \ GC="$${GCCGO} -fgo-compiling-runtime"; \ export GC; \ GOARCH=`$(abs_builddir)/go$(EXEEXT) env GOARCH`; \ GOOS=`$(abs_builddir)/go$(EXEEXT) env GOOS`; \ - GOLIBS="$(RT_LIBS)"; \ - export GOLIBS; \ files=`$(SHELL) $(libgosrcdir)/../match.sh --goarch=$${GOARCH} --goos=$${GOOS} --srcdir=$(libgosrcdir)/runtime --extrafiles="$(libgodir)/runtime_linknames.go $(libgodir)/runtime_sysinfo.go $(libgodir)/sigtab.go $(libgodir)/goroot.go" --tag=libffi`; \ $(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles="$${files}" $(GOTESTFLAGS) -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v >> runtime-testlog 2>&1 || echo "--- $${fl}: go test runtime (0.00s)" >> runtime-testlog grep '^--- ' runtime-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' | sort -k 2 diff --git a/gotools/configure.ac b/gotools/configure.ac index bf2395f7cf6..f0a73eca782 100644 --- a/gotools/configure.ac +++ b/gotools/configure.ac @@ -85,15 +85,6 @@ dnl Test if -lrt is required for sched_yield and/or nanosleep. AC_SEARCH_LIBS([sched_yield], [rt]) AC_SEARCH_LIBS([nanosleep], [rt]) -dnl On GNU/Linux we need to link the runtime package against -lrt. -dnl This is a target test, unlike sched_yield/nanosleep above -dnl which is a host test. -RT_LIBS= -case ${target} in - *-*-linux*) RT_LIBS=-lrt ;; -esac -AC_SUBST(RT_LIBS) - AC_CONFIG_FILES(Makefile) AC_OUTPUT diff --git a/libgo/Makefile.am b/libgo/Makefile.am index be889f2a984..9318f38714a 100644 --- a/libgo/Makefile.am +++ b/libgo/Makefile.am @@ -832,8 +832,7 @@ libgo_ldflags = \ libgo_libadd = \ $(libgo_go_objs) ../libbacktrace/libbacktrace.la \ - $(LIBATOMIC) $(LIBFFI) $(PTHREAD_LIBS) $(MATH_LIBS) \ - $(NET_LIBS) $(RT_LIBS) + $(LIBATOMIC) $(LIBFFI) $(PTHREAD_LIBS) $(MATH_LIBS) $(NET_LIBS) libgo_la_SOURCES = $(runtime_files) libgo_la_LDFLAGS = $(libgo_ldflags) @@ -924,7 +923,7 @@ GOBENCH = CHECK = \ GC="$(GOC) $(GOCFLAGS) $($(subst /,_,$@)_GOCFLAGS) -L `${PWD_COMMAND}` -L `${PWD_COMMAND}`/.libs"; \ export GC; \ - GOLIBS="$(extra_check_libs_$(subst .,_,$(subst /,_,$(@D)))) $(PTHREAD_LIBS) $(MATH_LIBS) $(NET_LIBS) $(RT_LIBS) $(LIBS)"; \ + GOLIBS="$(extra_check_libs_$(subst .,_,$(subst /,_,$(@D)))) $(PTHREAD_LIBS) $(MATH_LIBS) $(NET_LIBS) $(LIBS)"; \ export GOLIBS; \ RUNTESTFLAGS="$(RUNTESTFLAGS)"; \ export RUNTESTFLAGS; \ diff --git a/libgo/configure.ac b/libgo/configure.ac index 1b44b226f62..7e2b98ba67c 100644 --- a/libgo/configure.ac +++ b/libgo/configure.ac @@ -549,12 +549,6 @@ AC_CACHE_CHECK([for socket libraries], libgo_cv_lib_sockets, NET_LIBS="$libgo_cv_lib_sockets" AC_SUBST(NET_LIBS) -RT_LIBS= -case ${host} in - *-*-linux*) RT_LIBS=-lrt ;; -esac -AC_SUBST(RT_LIBS) - dnl Test whether the compiler supports the -pthread option. AC_CACHE_CHECK([whether -pthread is supported], [libgo_cv_lib_pthread], diff --git a/libgo/go/runtime/os_linux.go b/libgo/go/runtime/os_linux.go index 6ffd8980c5f..96fb178870e 100644 --- a/libgo/go/runtime/os_linux.go +++ b/libgo/go/runtime/os_linux.go @@ -18,7 +18,7 @@ type mOS struct { // creates and manages its own timer, and these fields are read and written // only by this thread. But because some of the reads on profileTimerValid // are in signal handling code, access to that field uses atomic operations. - profileTimer uintptr + profileTimer int32 profileTimerValid uint32 } @@ -243,16 +243,17 @@ func osinit() { physHugePageSize = getHugePageSize() } -//go:noescape -//extern-sysinfo timer_create -func timer_create(clockid int32, sevp *_sigevent, timerid *uintptr) int32 +func timer_create(clockid int32, sevp *_sigevent, timerid *int32) int32 { + return int32(syscall(_SYS_timer_create, uintptr(clockid), uintptr(unsafe.Pointer(sevp)), uintptr(unsafe.Pointer(timerid)), 0, 0, 0)) +} -//go:noescape -//extern-sysinfo timer_settime -func timer_settime(timerid uintptr, flags int32, new, old *_itimerspec) int32 +func timer_settime(timerid int32, flags int32, new, old *_itimerspec) int32 { + return int32(syscall(_SYS_timer_settime, uintptr(timerid), uintptr(flags), uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)), 0, 0)) +} -//extern-sysinfo timer_delete -func timer_delete(timerid uintptr) int32 +func timer_delete(timerid int32) int32 { + return int32(syscall(_SYS_timer_delete, uintptr(timerid), 0, 0, 0, 0, 0)) +} // go118UseTimerCreateProfiler enables the per-thread CPU profiler. const go118UseTimerCreateProfiler = true @@ -360,7 +361,7 @@ func setThreadCPUProfiler(hz int32) { spec.it_value.setNsec(1 + int64(fastrandn(uint32(1e9/hz)))) spec.it_interval.setNsec(1e9 / int64(hz)) - var timerid uintptr + var timerid int32 var sevp _sigevent sevp.sigev_notify = _SIGEV_THREAD_ID sevp.sigev_signo = _SIGPROF diff --git a/libgo/testsuite/Makefile.in b/libgo/testsuite/Makefile.in index 6e143fa3bab..7869265851c 100644 --- a/libgo/testsuite/Makefile.in +++ b/libgo/testsuite/Makefile.in @@ -215,7 +215,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_LIBS = @PTHREAD_LIBS@ RANLIB = @RANLIB@ -RT_LIBS = @RT_LIBS@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@