It's been a long-standing problem in gccgo that the testing package does not report the correct file/line information when using a method like t.Error. This is because the testing type uses an embedded type, and methods like t.Error are actually inherited from the embedded type. This means that the method is a stub. In the gc toolchain, stubs are thunks that jump directly to the code and do not remain on the stack. In the gccgo toolchain, they do remain on the stack, which means that code that calls runtime.Caller will see them in places where the gc toolchain does not.
This patch fixes the problem by marking stub functions with $stub in their name, and skipping $stub functions in runtime.Caller. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian
Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 233097) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -a408bef550251926c28673818db2c64302faac1d +c70e74c116d08c6f2e787551eb1366983815c032 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/types.cc =================================================================== --- gcc/go/gofrontend/types.cc (revision 233097) +++ gcc/go/gofrontend/types.cc (working copy) @@ -9632,13 +9632,14 @@ Type::build_stub_methods(Gogo* gogo, con package = NULL; else package = type->named_type()->named_object()->package(); + std::string stub_name = name + "$stub"; Named_object* stub; if (package != NULL) - stub = Named_object::make_function_declaration(name, package, + stub = Named_object::make_function_declaration(stub_name, package, stub_type, location); else { - stub = gogo->start_function(name, stub_type, false, + stub = gogo->start_function(stub_name, stub_type, false, fntype->location()); Type::build_one_stub_method(gogo, m, buf, stub_params, fntype->is_varargs(), location); Index: libgo/runtime/go-callers.c =================================================================== --- libgo/runtime/go-callers.c (revision 232239) +++ libgo/runtime/go-callers.c (working copy) @@ -74,6 +74,8 @@ callback (void *data, uintptr_t pc, cons p = __builtin_strrchr (function, '$'); if (p != NULL && __builtin_strcmp(p, "$recover") == 0) return 0; + if (p != NULL && __builtin_strncmp(p, "$stub", 5) == 0) + return 0; } if (arg->skip > 0)