Skip to content

Commit 68a756b

Browse files
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 Change-Id: I6a071e378205e5e90cfaebad23aca33dcfcef074 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/504798 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent 1950601 commit 68a756b

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

go/expressions.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12272,7 +12272,8 @@ Call_expression::intrinsify(Gogo* gogo,
1227212272
return Runtime::make_call(code, loc, 3, a1, a2, a3);
1227312273
}
1227412274
}
12275-
else if (package == "internal/abi")
12275+
else if (package == "internal/abi"
12276+
|| package == "bootstrap/internal/abi") // for bootstrapping gc
1227612277
{
1227712278
if (is_method)
1227812279
return NULL;

go/gogo.cc

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3296,6 +3296,9 @@ class Create_function_descriptors : public Traverse
32963296
int
32973297
expression(Expression**);
32983298

3299+
static bool
3300+
skip_descriptor(Gogo* gogo, const Named_object*);
3301+
32993302
private:
33003303
Gogo* gogo_;
33013304
};
@@ -3306,6 +3309,9 @@ class Create_function_descriptors : public Traverse
33063309
int
33073310
Create_function_descriptors::function(Named_object* no)
33083311
{
3312+
if (Create_function_descriptors::skip_descriptor(this->gogo_, no))
3313+
return TRAVERSE_CONTINUE;
3314+
33093315
if (no->is_function()
33103316
&& no->func_value()->enclosing() == NULL
33113317
&& !no->func_value()->is_method()
@@ -3393,6 +3399,28 @@ Create_function_descriptors::expression(Expression** pexpr)
33933399
return TRAVERSE_CONTINUE;
33943400
}
33953401

3402+
// The gc compiler has some special cases that it always compiles as
3403+
// intrinsics. For those we don't want to generate a function
3404+
// descriptor, as there will be no code for it to refer to.
3405+
3406+
bool
3407+
Create_function_descriptors::skip_descriptor(Gogo* gogo,
3408+
const Named_object* no)
3409+
{
3410+
const std::string& pkgpath(no->package() == NULL
3411+
? gogo->pkgpath()
3412+
: no->package()->pkgpath());
3413+
3414+
// internal/abi is the standard library package,
3415+
// bootstrap/internal/abi is the name used when bootstrapping the gc
3416+
// compiler.
3417+
3418+
return ((pkgpath == "internal/abi"
3419+
|| pkgpath == "bootstrap/internal/abi")
3420+
&& (no->name() == "FuncPCABI0"
3421+
|| no->name() == "FuncPCABIInternal"));
3422+
}
3423+
33963424
// Create function descriptors as needed. We need a function
33973425
// descriptor for all exported functions and for all functions that
33983426
// are referenced without being called.
@@ -3414,7 +3442,8 @@ Gogo::create_function_descriptors()
34143442
if (no->is_function_declaration()
34153443
&& !no->func_declaration_value()->type()->is_method()
34163444
&& !Linemap::is_predeclared_location(no->location())
3417-
&& !Gogo::is_hidden_name(no->name()))
3445+
&& !Gogo::is_hidden_name(no->name())
3446+
&& !Create_function_descriptors::skip_descriptor(this, no))
34183447
fndecls.push_back(no);
34193448
}
34203449
for (std::vector<Named_object*>::const_iterator p = fndecls.begin();

libgo/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ toolexeclibgounicode_DATA = \
417417
# Some internal packages are needed to bootstrap the gc toolchain.
418418
toolexeclibgointernaldir = $(toolexeclibgodir)/internal
419419
toolexeclibgointernal_DATA = \
420+
internal/lazyregexp.gox \
420421
internal/reflectlite.gox \
421422
internal/unsafeheader.gox
422423

libgo/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ toolexeclibgounicode_DATA = \
885885
# Some internal packages are needed to bootstrap the gc toolchain.
886886
toolexeclibgointernaldir = $(toolexeclibgodir)/internal
887887
toolexeclibgointernal_DATA = \
888+
internal/lazyregexp.gox \
888889
internal/reflectlite.gox \
889890
internal/unsafeheader.gox
890891

libgo/go/internal/abi/abi.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ package abi
1717
// compile-time error.
1818
//
1919
// Implemented as a compile intrinsic.
20-
func FuncPCABI0(f any) uintptr {
21-
// The compiler should remove all calls.
22-
panic("FuncPCABI0")
23-
}
20+
func FuncPCABI0(f any) uintptr
2421

2522
// FuncPCABIInternal returns the entry PC of the function f. If f is a
2623
// direct reference of a function, it must be defined as ABIInternal.
@@ -29,7 +26,4 @@ func FuncPCABI0(f any) uintptr {
2926
// the behavior is undefined.
3027
//
3128
// Implemented as a compile intrinsic.
32-
func FuncPCABIInternal(f any) uintptr {
33-
// The compiler should remove all calls.
34-
panic("FuncPCABIInternal")
35-
}
29+
func FuncPCABIInternal(f any) uintptr

0 commit comments

Comments
 (0)