https://github.com/aarzilli/whydeadcode
https://github.com/aarzilli/whydeadcode
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/aarzilli/whydeadcode
- Owner: aarzilli
- Created: 2023-05-15T17:00:17.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-12-26T17:18:16.000Z (over 1 year ago)
- Last Synced: 2025-04-04T04:41:20.878Z (about 1 year ago)
- Language: Go
- Size: 5.86 KB
- Stars: 28
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SUMMARY
Displays why deadcode elimination was partially disabled by the Go linker.
The Go linker will disable most deadcode elimination if it finds reachable calls to `reflect.Value.MethodByName` or `reflect.Value.Method`. This is done because, using these two methods it is possible to dynamically call any public method in the application.
Whydeadcode uses the call graph produced by the linker to display why `reflect.Value.MethodByName` or `reflect.Value.Method` are reachable. Use it like this:
```
go build -ldflags=-dumpdep your/package |& whydeadcode
```
Needs Go 1.21 or later.
Because of how `-dumpdep` works only the first result output by whydeadcode is real. Because of how `-dumpdep` works anything beyond the first result can be a false positive (i.e. things that look like they will affect deadcode elimination but won't if the first result is taken care of) and it can also have false negatives (i.e. things that will continue to keep deadcode elimination disabled if the first result is taken care of).
# TALK
For a more detailed explanation see the [golab 2023 talk](https://youtu.be/EkG177eRcco) or the [slides](https://github.com/aarzilli/talks/blob/master/golab2023_deadcode.pdf).