From 4a5b806048bb94e2adcd34ea11ae27ca4030051f Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 20 Jan 2017 21:18:37 +0000 Subject: [PATCH] runtime, testing/internal/testdeps: fixes for cgo Some fixes that permit misc/cgo/test in the master gc repository to pass using the current gccgo. Install testing/internal/testdeps.gox; it is needed by `go test`. Export runtime.lockedOSThread to enable calling via go:linkname; it is used by misc/cgo/test. Loop on EAGAIN when creating a new thread; this is what the gc code does, and misc/cgo/test tests that it works. Reviewed-on: https://go-review.googlesource.com/35479 From-SVN: r244733 --- gcc/go/gofrontend/MERGE | 2 +- libgo/Makefile.am | 5 +++++ libgo/Makefile.in | 41 ++++++++++++++++++++++++++++++++++++---- libgo/go/runtime/proc.go | 3 +++ libgo/runtime/proc.c | 16 ++++++++++++++-- 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index df9be07d95e..b4e7b715175 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -907f6e31975443993c47fa45e09cf85d0709b7e6 +b573d4756096523d8bd4bf7b11e56383e5a2cca4 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/Makefile.am b/libgo/Makefile.am index 14ee9bec211..515b61b71e4 100644 --- a/libgo/Makefile.am +++ b/libgo/Makefile.am @@ -360,6 +360,11 @@ toolexeclibgotesting_DATA = \ testing/iotest.gox \ testing/quick.gox +toolexeclibgotestinginternaldir = $(toolexeclibgotestingdir)/internal + +toolexeclibgotestinginternal_DATA = \ + testing/internal/testdeps.gox + toolexeclibgotextdir = $(toolexeclibgodir)/text toolexeclibgotext_DATA = \ diff --git a/libgo/Makefile.in b/libgo/Makefile.in index e3e396caaeb..d6e3eace40c 100644 --- a/libgo/Makefile.in +++ b/libgo/Makefile.in @@ -146,6 +146,7 @@ am__installdirs = "$(DESTDIR)$(toolexeclibdir)" \ "$(DESTDIR)$(toolexeclibgoruntimedir)" \ "$(DESTDIR)$(toolexeclibgosyncdir)" \ "$(DESTDIR)$(toolexeclibgotestingdir)" \ + "$(DESTDIR)$(toolexeclibgotestinginternaldir)" \ "$(DESTDIR)$(toolexeclibgotextdir)" \ "$(DESTDIR)$(toolexeclibgotexttemplatedir)" \ "$(DESTDIR)$(toolexeclibgounicodedir)" @@ -265,7 +266,8 @@ DATA = $(noinst_DATA) $(toolexeclibgo_DATA) \ $(toolexeclibgonetrpc_DATA) $(toolexeclibgoos_DATA) \ $(toolexeclibgopath_DATA) $(toolexeclibgoregexp_DATA) \ $(toolexeclibgoruntime_DATA) $(toolexeclibgosync_DATA) \ - $(toolexeclibgotesting_DATA) $(toolexeclibgotext_DATA) \ + $(toolexeclibgotesting_DATA) \ + $(toolexeclibgotestinginternal_DATA) $(toolexeclibgotext_DATA) \ $(toolexeclibgotexttemplate_DATA) $(toolexeclibgounicode_DATA) RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ distclean-recursive maintainer-clean-recursive @@ -740,6 +742,10 @@ toolexeclibgotesting_DATA = \ testing/iotest.gox \ testing/quick.gox +toolexeclibgotestinginternaldir = $(toolexeclibgotestingdir)/internal +toolexeclibgotestinginternal_DATA = \ + testing/internal/testdeps.gox + toolexeclibgotextdir = $(toolexeclibgodir)/text toolexeclibgotext_DATA = \ text/scanner.gox \ @@ -2645,6 +2651,27 @@ uninstall-toolexeclibgotestingDATA: @list='$(toolexeclibgotesting_DATA)'; test -n "$(toolexeclibgotestingdir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ dir='$(DESTDIR)$(toolexeclibgotestingdir)'; $(am__uninstall_files_from_dir) +install-toolexeclibgotestinginternalDATA: $(toolexeclibgotestinginternal_DATA) + @$(NORMAL_INSTALL) + @list='$(toolexeclibgotestinginternal_DATA)'; test -n "$(toolexeclibgotestinginternaldir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(toolexeclibgotestinginternaldir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(toolexeclibgotestinginternaldir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(toolexeclibgotestinginternaldir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(toolexeclibgotestinginternaldir)" || exit $$?; \ + done + +uninstall-toolexeclibgotestinginternalDATA: + @$(NORMAL_UNINSTALL) + @list='$(toolexeclibgotestinginternal_DATA)'; test -n "$(toolexeclibgotestinginternaldir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + dir='$(DESTDIR)$(toolexeclibgotestinginternaldir)'; $(am__uninstall_files_from_dir) install-toolexeclibgotextDATA: $(toolexeclibgotext_DATA) @$(NORMAL_INSTALL) @list='$(toolexeclibgotext_DATA)'; test -n "$(toolexeclibgotextdir)" || list=; \ @@ -2849,7 +2876,7 @@ all-am: Makefile $(LIBRARIES) $(LTLIBRARIES) all-multi $(DATA) \ config.h installdirs: installdirs-recursive installdirs-am: - for dir in "$(DESTDIR)$(toolexeclibdir)" "$(DESTDIR)$(toolexeclibdir)" "$(DESTDIR)$(toolexeclibgodir)" "$(DESTDIR)$(toolexeclibgoarchivedir)" "$(DESTDIR)$(toolexeclibgocompressdir)" "$(DESTDIR)$(toolexeclibgocontainerdir)" "$(DESTDIR)$(toolexeclibgocryptodir)" "$(DESTDIR)$(toolexeclibgocryptox509dir)" "$(DESTDIR)$(toolexeclibgodatabasedir)" "$(DESTDIR)$(toolexeclibgodatabasesqldir)" "$(DESTDIR)$(toolexeclibgodebugdir)" "$(DESTDIR)$(toolexeclibgoencodingdir)" "$(DESTDIR)$(toolexeclibgoexpdir)" "$(DESTDIR)$(toolexeclibgogodir)" "$(DESTDIR)$(toolexeclibgohashdir)" "$(DESTDIR)$(toolexeclibgohtmldir)" "$(DESTDIR)$(toolexeclibgoimagedir)" "$(DESTDIR)$(toolexeclibgoimagecolordir)" "$(DESTDIR)$(toolexeclibgoindexdir)" "$(DESTDIR)$(toolexeclibgoiodir)" "$(DESTDIR)$(toolexeclibgologdir)" "$(DESTDIR)$(toolexeclibgomathdir)" "$(DESTDIR)$(toolexeclibgomimedir)" "$(DESTDIR)$(toolexeclibgonetdir)" "$(DESTDIR)$(toolexeclibgonethttpdir)" "$(DESTDIR)$(toolexeclibgonetrpcdir)" "$(DESTDIR)$(toolexeclibgoosdir)" "$(DESTDIR)$(toolexeclibgopathdir)" "$(DESTDIR)$(toolexeclibgoregexpdir)" "$(DESTDIR)$(toolexeclibgoruntimedir)" "$(DESTDIR)$(toolexeclibgosyncdir)" "$(DESTDIR)$(toolexeclibgotestingdir)" "$(DESTDIR)$(toolexeclibgotextdir)" "$(DESTDIR)$(toolexeclibgotexttemplatedir)" "$(DESTDIR)$(toolexeclibgounicodedir)"; do \ + for dir in "$(DESTDIR)$(toolexeclibdir)" "$(DESTDIR)$(toolexeclibdir)" "$(DESTDIR)$(toolexeclibgodir)" "$(DESTDIR)$(toolexeclibgoarchivedir)" "$(DESTDIR)$(toolexeclibgocompressdir)" "$(DESTDIR)$(toolexeclibgocontainerdir)" "$(DESTDIR)$(toolexeclibgocryptodir)" "$(DESTDIR)$(toolexeclibgocryptox509dir)" "$(DESTDIR)$(toolexeclibgodatabasedir)" "$(DESTDIR)$(toolexeclibgodatabasesqldir)" "$(DESTDIR)$(toolexeclibgodebugdir)" "$(DESTDIR)$(toolexeclibgoencodingdir)" "$(DESTDIR)$(toolexeclibgoexpdir)" "$(DESTDIR)$(toolexeclibgogodir)" "$(DESTDIR)$(toolexeclibgohashdir)" "$(DESTDIR)$(toolexeclibgohtmldir)" "$(DESTDIR)$(toolexeclibgoimagedir)" "$(DESTDIR)$(toolexeclibgoimagecolordir)" "$(DESTDIR)$(toolexeclibgoindexdir)" "$(DESTDIR)$(toolexeclibgoiodir)" "$(DESTDIR)$(toolexeclibgologdir)" "$(DESTDIR)$(toolexeclibgomathdir)" "$(DESTDIR)$(toolexeclibgomimedir)" "$(DESTDIR)$(toolexeclibgonetdir)" "$(DESTDIR)$(toolexeclibgonethttpdir)" "$(DESTDIR)$(toolexeclibgonetrpcdir)" "$(DESTDIR)$(toolexeclibgoosdir)" "$(DESTDIR)$(toolexeclibgopathdir)" "$(DESTDIR)$(toolexeclibgoregexpdir)" "$(DESTDIR)$(toolexeclibgoruntimedir)" "$(DESTDIR)$(toolexeclibgosyncdir)" "$(DESTDIR)$(toolexeclibgotestingdir)" "$(DESTDIR)$(toolexeclibgotestinginternaldir)" "$(DESTDIR)$(toolexeclibgotextdir)" "$(DESTDIR)$(toolexeclibgotexttemplatedir)" "$(DESTDIR)$(toolexeclibgounicodedir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-recursive @@ -2935,7 +2962,9 @@ install-exec-am: install-multi install-toolexeclibLIBRARIES \ install-toolexeclibgonetrpcDATA install-toolexeclibgoosDATA \ install-toolexeclibgopathDATA install-toolexeclibgoregexpDATA \ install-toolexeclibgoruntimeDATA install-toolexeclibgosyncDATA \ - install-toolexeclibgotestingDATA install-toolexeclibgotextDATA \ + install-toolexeclibgotestingDATA \ + install-toolexeclibgotestinginternalDATA \ + install-toolexeclibgotextDATA \ install-toolexeclibgotexttemplateDATA \ install-toolexeclibgounicodeDATA @@ -3005,6 +3034,7 @@ uninstall-am: uninstall-toolexeclibLIBRARIES \ uninstall-toolexeclibgoruntimeDATA \ uninstall-toolexeclibgosyncDATA \ uninstall-toolexeclibgotestingDATA \ + uninstall-toolexeclibgotestinginternalDATA \ uninstall-toolexeclibgotextDATA \ uninstall-toolexeclibgotexttemplateDATA \ uninstall-toolexeclibgounicodeDATA @@ -3046,7 +3076,9 @@ uninstall-am: uninstall-toolexeclibLIBRARIES \ install-toolexeclibgonetrpcDATA install-toolexeclibgoosDATA \ install-toolexeclibgopathDATA install-toolexeclibgoregexpDATA \ install-toolexeclibgoruntimeDATA install-toolexeclibgosyncDATA \ - install-toolexeclibgotestingDATA install-toolexeclibgotextDATA \ + install-toolexeclibgotestingDATA \ + install-toolexeclibgotestinginternalDATA \ + install-toolexeclibgotextDATA \ install-toolexeclibgotexttemplateDATA \ install-toolexeclibgounicodeDATA installcheck installcheck-am \ installdirs installdirs-am maintainer-clean \ @@ -3080,6 +3112,7 @@ uninstall-am: uninstall-toolexeclibLIBRARIES \ uninstall-toolexeclibgoruntimeDATA \ uninstall-toolexeclibgosyncDATA \ uninstall-toolexeclibgotestingDATA \ + uninstall-toolexeclibgotestinginternalDATA \ uninstall-toolexeclibgotextDATA \ uninstall-toolexeclibgotexttemplateDATA \ uninstall-toolexeclibgounicodeDATA diff --git a/libgo/go/runtime/proc.go b/libgo/go/runtime/proc.go index 958b56e0ecd..ea7f84e9b70 100644 --- a/libgo/go/runtime/proc.go +++ b/libgo/go/runtime/proc.go @@ -43,6 +43,9 @@ import ( //go:linkname runqempty runtime.runqempty //go:linkname runqput runtime.runqput +// Function called by misc/cgo/test. +//go:linkname lockedOSThread runtime.lockedOSThread + // Functions temporarily in C that have not yet been ported. func allocm(*p, bool, *unsafe.Pointer, *uintptr) *m func malg(bool, bool, *unsafe.Pointer, *uintptr) *g diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c index 0ed7ebe0860..60d5bdbc612 100644 --- a/libgo/runtime/proc.c +++ b/libgo/runtime/proc.c @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +#include #include #include #include @@ -216,6 +217,7 @@ runtime_newosproc(M *mp) pthread_attr_t attr; sigset_t clear, old; pthread_t tid; + int tries; int ret; if(pthread_attr_init(&attr) != 0) @@ -234,11 +236,21 @@ runtime_newosproc(M *mp) sigemptyset(&old); pthread_sigmask(SIG_BLOCK, &clear, &old); - ret = pthread_create(&tid, &attr, runtime_mstart, mp); + + for (tries = 0; tries < 20; tries++) { + ret = pthread_create(&tid, &attr, runtime_mstart, mp); + if (ret != EAGAIN) { + break; + } + runtime_usleep((tries + 1) * 1000); // Milliseconds. + } + pthread_sigmask(SIG_SETMASK, &old, nil); - if (ret != 0) + if (ret != 0) { + runtime_printf("pthread_create failed: %d\n", ret); runtime_throw("pthread_create"); + } } // First function run by a new goroutine. This replaces gogocall. -- 2.30.2