From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2116) id F1BA53858C3A; Fri, 23 Jun 2023 23:16:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1BA53858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687562208; bh=I1KY/1Qwr0gks3NbZD4OfIxJ/o1kCobMblVxVnDLWM0=; h=From:To:Subject:Date:From; b=EcycDdU4mNHjxfWGkByUkQfa8Is+X8Jh6nNRrnuo4ynzbsGxFqHqpy7w4NRHbs5h5 i15fgSdHqKTSDpX8cxgqIpIMIuQk8AYUoHpMttIi4QykILgpYj7VQPPdvesk61LkVD hqMjoNfEDvQcLbnvgC2G/QRVQZiOMinE6mQ9JC/0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Ian Lance Taylor To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-9725] compiler, libgo: support bootstrapping gc compiler X-Act-Checkin: gcc X-Git-Author: Ian Lance Taylor X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 72ceed08d45137b0f1a9b4ea8ca533aa6489bc39 X-Git-Newrev: f4d011b4aa0fc7a9e3df0dada2fd3e1e95e32a6c Message-Id: <20230623231648.F1BA53858C3A@sourceware.org> Date: Fri, 23 Jun 2023 23:16:48 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f4d011b4aa0fc7a9e3df0dada2fd3e1e95e32a6c commit r12-9725-gf4d011b4aa0fc7a9e3df0dada2fd3e1e95e32a6c Author: Ian Lance Taylor Date: Fri Jun 23 16:16:06 2023 -0700 compiler, libgo: support bootstrapping gc compiler In the Go 1.21 release the package internal/profile imports internal/lazyregexp. That works when bootstrapping with Go 1.17, because that compiler has internal/lazyregep and permits importing it. We also have internal/lazyregexp in libgo, but since it is not installed it is not available for importing. This CL adds internal/lazyregexp to the list of internal packages that are installed for bootstrapping. The Go 1.21, and earlier, releases have a couple of functions in the internal/abi package that are always fully intrinsified. The gofrontend recognizes and intrinsifies those functions as well. However, the gofrontend was also building function descriptors for references to the functions without calling them, which failed because there was nothing to refer to. That is OK for the gc compiler, which guarantees that the functions are only called, not referenced. This CL arranges to not generate function descriptors for these functions. For golang/go#60913 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/504798 Diff: --- gcc/go/gofrontend/expressions.cc | 3 ++- gcc/go/gofrontend/gogo.cc | 31 ++++++++++++++++++++++++++++++- libgo/Makefile.am | 1 + libgo/Makefile.in | 1 + libgo/go/internal/abi/abi.go | 10 ++-------- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 1b3b3bf135e..88b4ceacc07 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -12325,7 +12325,8 @@ Call_expression::intrinsify(Gogo* gogo, return Runtime::make_call(code, loc, 3, a1, a2, a3); } } - else if (package == "internal/abi") + else if (package == "internal/abi" + || package == "bootstrap/internal/abi") // for bootstrapping gc { if (is_method) return NULL; diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc index d35c6baf582..cca03dcdc35 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -3331,6 +3331,9 @@ class Create_function_descriptors : public Traverse int expression(Expression**); + static bool + skip_descriptor(Gogo* gogo, const Named_object*); + private: Gogo* gogo_; }; @@ -3341,6 +3344,9 @@ class Create_function_descriptors : public Traverse int Create_function_descriptors::function(Named_object* no) { + if (Create_function_descriptors::skip_descriptor(this->gogo_, no)) + return TRAVERSE_CONTINUE; + if (no->is_function() && no->func_value()->enclosing() == NULL && !no->func_value()->is_method() @@ -3428,6 +3434,28 @@ Create_function_descriptors::expression(Expression** pexpr) return TRAVERSE_CONTINUE; } +// The gc compiler has some special cases that it always compiles as +// intrinsics. For those we don't want to generate a function +// descriptor, as there will be no code for it to refer to. + +bool +Create_function_descriptors::skip_descriptor(Gogo* gogo, + const Named_object* no) +{ + const std::string& pkgpath(no->package() == NULL + ? gogo->pkgpath() + : no->package()->pkgpath()); + + // internal/abi is the standard library package, + // bootstrap/internal/abi is the name used when bootstrapping the gc + // compiler. + + return ((pkgpath == "internal/abi" + || pkgpath == "bootstrap/internal/abi") + && (no->name() == "FuncPCABI0" + || no->name() == "FuncPCABIInternal")); +} + // Create function descriptors as needed. We need a function // descriptor for all exported functions and for all functions that // are referenced without being called. @@ -3449,7 +3477,8 @@ Gogo::create_function_descriptors() if (no->is_function_declaration() && !no->func_declaration_value()->type()->is_method() && !Linemap::is_predeclared_location(no->location()) - && !Gogo::is_hidden_name(no->name())) + && !Gogo::is_hidden_name(no->name()) + && !Create_function_descriptors::skip_descriptor(this, no)) fndecls.push_back(no); } for (std::vector::const_iterator p = fndecls.begin(); diff --git a/libgo/Makefile.am b/libgo/Makefile.am index b03e6553e90..c273d94d111 100644 --- a/libgo/Makefile.am +++ b/libgo/Makefile.am @@ -417,6 +417,7 @@ toolexeclibgounicode_DATA = \ # Some internal packages are needed to bootstrap the gc toolchain. toolexeclibgointernaldir = $(toolexeclibgodir)/internal toolexeclibgointernal_DATA = \ + internal/lazyregexp.gox \ internal/reflectlite.gox \ internal/unsafeheader.gox diff --git a/libgo/Makefile.in b/libgo/Makefile.in index 16ed62a82ed..04fdb60d497 100644 --- a/libgo/Makefile.in +++ b/libgo/Makefile.in @@ -885,6 +885,7 @@ toolexeclibgounicode_DATA = \ # Some internal packages are needed to bootstrap the gc toolchain. toolexeclibgointernaldir = $(toolexeclibgodir)/internal toolexeclibgointernal_DATA = \ + internal/lazyregexp.gox \ internal/reflectlite.gox \ internal/unsafeheader.gox diff --git a/libgo/go/internal/abi/abi.go b/libgo/go/internal/abi/abi.go index c4a108847ca..66251274d97 100644 --- a/libgo/go/internal/abi/abi.go +++ b/libgo/go/internal/abi/abi.go @@ -17,10 +17,7 @@ package abi // compile-time error. // // Implemented as a compile intrinsic. -func FuncPCABI0(f any) uintptr { - // The compiler should remove all calls. - panic("FuncPCABI0") -} +func FuncPCABI0(f any) uintptr // FuncPCABIInternal returns the entry PC of the function f. If f is a // direct reference of a function, it must be defined as ABIInternal. @@ -29,7 +26,4 @@ func FuncPCABI0(f any) uintptr { // the behavior is undefined. // // Implemented as a compile intrinsic. -func FuncPCABIInternal(f any) uintptr { - // The compiler should remove all calls. - panic("FuncPCABIInternal") -} +func FuncPCABIInternal(f any) uintptr