diff options
| author | Dominique Lefevre <domingolefevre@gmail.com> | 2023-08-24 10:15:29 +0300 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2023-09-01 15:06:51 +0000 |
| commit | e802f211b0d3f9dac5c4ca56c9f83df0cb745070 (patch) | |
| tree | 4e5c55d1abab256bad81ee7f958ec7287b1dbaae /src/cmd/link/internal/ld/testdata/deadcode | |
| parent | 660feea72f64d9d6d619529f10afd8c042299c65 (diff) | |
| download | go-e802f211b0d3f9dac5c4ca56c9f83df0cb745070.tar.xz | |
cmd/compile: special-case MethodByName(string literal) to keep the DCE enabled.
Normally, a call to MethodByName() disables the DCE because the linker
assumes that any method can be accessed this way. This pessimises
the code generation for k8s.io/apimachinery which needs MethodByName()
to verify whether or not a struct implements DeepCopyInto(). It cannot
cast a struct to `interface { DeepCopyInto() Foo }` because the return
type may vary. Instead, it does the following:
if m := reflect.ValueOf(obj).MethodByName("DeepCopyInto"); ... {
In this case there is no need to disable the DCE altogether. It
suffices to add a relocation to keep methods named DeepCopyInto().
Fixes #62257.
Change-Id: I583c2f04d8309a8807de75cd962c04151baeeb1b
Reviewed-on: https://go-review.googlesource.com/c/go/+/522436
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/link/internal/ld/testdata/deadcode')
0 files changed, 0 insertions, 0 deletions
