Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/link: panic: runtime error: slice bounds out of range #23740
What version of Go are you using (
changed the title from
cmd/link panic: runtime error: slice bounds out of range
cmd/link: panic: runtime error: slice bounds out of range
Feb 8, 2018
TL;DR: we believe this is due to multiple versions of the same package being included in the build. Only one will actually get linked, which means that a dependent library may be compiled against one version and linked against another.
The main way to work around this is to ensure there are no duplicate libraries unless they use
It’d be nice if cmd/link could detect this scenario somehow and issue an appropriate warning, rather than panicking, which will continue to lead to new issues being filed here. I’m not sure how or if that is possible, but reopening this issue for that. Since you understand the issue, do you by chance have a minimal reproduction?
It may be difficult for cmd/link to detect this without a change in the package format. Each .a file produced by the compiler would need to be stamped with a unique id, and it would need to include the ids of the other .a files it was compiled against. The linker would need to verify these ids.
It's the responsibility of the build system (go build or Bazel rules_go in this case) to prevent this situation from happening, so while adding verification to cmd/link would be valuable, I'm not sure it justifies the additional complexity.
go build prevents this from happening by passing
rules_go should prevent this from happening by verifying that no two libraries passed to the linker have the same import path. At the moment, rules_go requires you to set