What is dead code elimination? (snippet from here)
The Go linker tries to remove functions that are never called in a step called "deadcode elimination". During this step the linker visits the symbol graph, starting from the entry point of the program, and marks every reachable symbol, i.e. everything that is called either directly or indirectly, through a function pointer or through an interface. All unreachable symbols are then removed and will not be included in the final executable.
However if during this process if the linker sees that one of the following methods are reachable:
- reflect.Value.Method
- reflect.Value.MethodByName
- reflect.Type.Method
- reflect.Type.MethodByName
When these methods are present, the linker bails out and results in an increased binary size.
Follow up from:
#132177 (comment)
What do we need to do:
#132177 (comment)
What do we need to automate:
#132177 (comment)
Let's start with kube-apiserver, we need to build it with -ldflags=-dumpdep and pass the output to https://github.com/aarzilli/whydeadcode.
When we fix all the locations with problematic code, we will not see any output from above. We need to get there, but there are several things to do before we get a clean run. We will need a verify script to make sure new dependency updates will not result in addition of problematic code.
/are code-organization