]> gcc.gnu.org Git - gcc.git/commitdiff
compiler, libgo: support bootstrapping gc compiler
authorIan Lance Taylor <iant@golang.org>
Thu, 22 Jun 2023 00:27:39 +0000 (17:27 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 23 Jun 2023 23:17:11 +0000 (16:17 -0700)
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

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/gogo.cc
libgo/Makefile.am
libgo/Makefile.in
libgo/go/internal/abi/abi.go

index a028350ba8ecc1a498f12e1f37947809fd3a4247..ff07b1a1fa6b8dbb005d16b7d591c06b6f13908c 100644 (file)
@@ -1,4 +1,4 @@
-195060166e6045408a2cb95e6aa88c6f0b98f20b
+68a756b6aadc901534cfddddad2b1e73fae9e34f
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 2112de6abfcd54c4190ac144e6446b0c0c1a31f5..d276bd811cc5f8b1ea01417c445a47558ca5cb63 100644 (file)
@@ -12272,7 +12272,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;
index 9197eef3e38e1c4359e20f6616391bb0675f2ed3..980db1ea07e014ff08ece99bda4815d43a48ed43 100644 (file)
@@ -3296,6 +3296,9 @@ class Create_function_descriptors : public Traverse
   int
   expression(Expression**);
 
+  static bool
+  skip_descriptor(Gogo* gogo, const Named_object*);
+
  private:
   Gogo* gogo_;
 };
@@ -3306,6 +3309,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()
@@ -3393,6 +3399,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.
@@ -3414,7 +3442,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<Named_object*>::const_iterator p = fndecls.begin();
index 920f8cc70715eafa2f30f99b3ca610a5152dac2d..c95dc2106cddec5c8a68db74399f3de38f94619f 100644 (file)
@@ -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
 
index 6176eb5827231cb1e4ae2f1e43feb63905c3a5f4..40340bfb7a5a159000d72353513e7215d2287ef4 100644 (file)
@@ -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
 
index c4a108847cab87338e1228f9f21de1334401afea..66251274d978dbd3d1f17fbc950cde165e439080 100644 (file)
@@ -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
This page took 0.088963 seconds and 5 git commands to generate.