Skip to content

gccgo: go test -compiler gccgo github.com/golang/protobuf/proto fails #15738

@mwhudson

Description

@mwhudson

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?

mwhudson@aeglos:~$ gccgo-5 --version
gccgo-5 (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

mwhudson@aeglos:~$ gccgo-6 --version
gccgo-6 (Ubuntu 6.0.1-0ubuntu1) 6.0.0 20160414 (experimental) [trunk revision 234994]
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  1. What operating system and processor architecture are you using (go env)?

Ubuntu 16.04

  1. What did you do?

go get github.com/golang/protobuf/...
go test -compiler gccgo github.com/golang/protobuf/proto

  1. What did you expect to see?

ok github.com/golang/protobuf/proto 0.028s

  1. What did you see instead?
mwhudson@aeglos:~$ go test -compiler gccgo github.com/golang/protobuf/proto
panic: runtime error: assignment to entry in nil map

goroutine 16 [running]:
runtime_dopanic
    ../../../src/libgo/runtime/panic.c:131
__go_panic
    ../../../src/libgo/runtime/go-panic.c:111
runtime_panicstring
    ../../../src/libgo/runtime/panic.c:216
__go_map_index
    ../../../src/libgo/runtime/go-map-index.c:94
github_com_golang_protobuf_proto.RegisterType
    /opt/opensource/gopath/src/github.com/golang/protobuf/proto/properties.go:838
any.$init0
    /opt/opensource/gopath/src/github.com/golang/protobuf/ptypes/any/any.pb.go:94
github_com_golang_protobuf_ptypes_any..import
    /opt/opensource/gopath/src/github.com/golang/protobuf/ptypes/any/any.pb.go:93
__go_init_main
    /tmp/go-build202436886/github.com/golang/protobuf/proto/_test/_testmain.go:2
runtime_main
    ../../../src/libgo/runtime/proc.c:604

goroutine 17 [runnable]:
kickoff
    ../../../src/libgo/runtime/proc.c:232
created by runtime_main
    ../../../src/libgo/runtime/proc.c:598

goroutine 18 [runnable]:
kickoff
    ../../../src/libgo/runtime/proc.c:232
created by runtime_createfing
    ../../../src/libgo/runtime/mgc0.c:2577
FAIL    github.com/golang/protobuf/proto    0.066s

The failing code is from "github.com/golang/protobuf/proto":

// RegisterType is called from generated code and maps from the fully qualified
// proto name to the type (pointer to struct) of the protocol buffer.
func RegisterType(x Message, name string) {
    if _, ok := protoTypes[name]; ok {
        // TODO: Some day, make this a panic.
        log.Printf("proto: duplicate proto type registered: %s", name)
        return
    }
    t := reflect.TypeOf(x)
    protoTypes[name] = t // <---- crashing here!
    revProtoTypes[t] = name
}

protoTypes is initialized in a global var block:

// A registry of all linked message types.
// The string is a fully-qualified proto name ("pkg.Message").
var (
    protoTypes    = make(map[string]reflect.Type)
    revProtoTypes = make(map[reflect.Type]string)
)

It is called from an init function in "github.com/golang/protobuf/ptypes/any/":

func init() {
    proto.RegisterType((*Any)(nil), "google.protobuf.Any")
}

So it looks like this init function is being called before that of "github.com/golang/protobuf/proto", which seems reasonably impossible (and indeed, I can't reproduce this in a trivial test case).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions