-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/link: add a flag to the linker to do not write function names to runtime.pclntab #36555
Comments
See #36313 |
@networkimprov : thank you. However I saw that ticket. It contains discussion how to reduce UPD: Wrote a comment to #36313 with a proposal to add an option to select a simple GC which does not require so complex |
Removing function names from |
|
I believe the This will also likely break profiling information. I understand that you would find it useful but I'm reluctant to endorse a change that will break code in ways that people will not know how to expect. I would rather find other ways to reduce binary size. |
We can forbid using broken functions via the build-tag (added automatically by |
Ian may be concerned that you'll eventually realize that Go isn't the best choice for an embedded app, and switch to Rust or http://ziglang.org ;-) |
For embedded Go, where size is really important, for the time being, https://tinygo.org/ is the better solution. Rather than having a specific build flag for stripping runtime.pclntab, I think that in the long run, what we need is new GOOS, such as "none" for running on raw iron, and "linux-embedded" for running an on embedded linux OS should be added. The "none" variants then allow building an OS kernel, and the -embedded variants then do a few things differently to save on space. |
I tried tinygo few times for u-root. And tinygo is a nice and interesting project, but it appears it has invalid CGo parser (which has problems with
I believe the community of Golang is wise and will be able to find a solution for cases like mine :) Anyway it would take much more time to port project to Rust than even to port it to tinygo :) |
@xaionaro I think we can try to introduce such -stripfnnames flag to the embeddedgo fork. Can you help? I'd love to test such flag because I've just reached the limit of 1 MiB Flash in STM32L476RG: $ size shell.elf where pclntab is 345 KiB (34%): $ nm --size-sort -S shell.elf|tail -5 The embeddedgo fork adds support for noos/thumb, noos/riscv64 and linux/thumb. I use linux/thumb only to run tests but it is usable and you can give it a try (no cgo support, sorry). It generates compressed Thumb2 instructions instead of ARM instructions so it produces smaller binaries that can be run on almost any ARMv7-A machine. The noos ones are for bare metal programming. |
Sounds very interesting. It could become very useful for https://github.com/u-root/u-root. But I do not understand: why do you do a fork instead of working with the upstream?
I would love to try. How can I help? :) |
You can much easily introduce new things in a fork. Even Go teem itself creates There is clearly no place for rarely used architectures or operating systems in the upstream but linux/thumb can be probably upstreamed as the 32-bit ARM seems to be now mainly used in embedded niche.
Simply send a pull request that implements -stripfnnames flag to the embeddedgo fork. The embeddedgo compiler is released as patches to the original Go source so you can relatively easy see what was added/changed. |
@xaionaro I've just implemented stripfnn flag:
Test results:
Sample panic outputs: stripfn=1
stripfn=2
In case of stripfn=2 panics are almost unusable. But in case of stripfn=1 there is enough information to find the problem. Clone https://github.com/embeddedgo/go and try it. |
Would be nice to have stripfn flag in official Go too 🤔 |
@embeddedgo I clone https://github.com/embeddedgo/go and run all.bash to build go tools, when I do compile with stripfn=2
there are function names , my system is my test code is
I don't know why is there any configuration that needs to do? |
I didn't tested the func A(s string) {
B(s)
}
func B(s string) {
panic(s)
}
func main() {
A("hello!")
} stripfn=0
stripfn=1
stripfn=2
It seems the Bellow are the numbers for the above code (linux/amd64):
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
Proposal
I found here https://groups.google.com/d/msg/golang-nuts/hEdGYnqokZc/zQojaoWlAgAJ that a binary size could be reduced by avoiding of wasting space on function names within
runtime.pclntab
. So I propose to add a linker flag (for example-stripfnnames
) to do that. We need such feature for applying Golang into embedded environments (with very limited total space).I would like to prepare a PR if it will be approved.
The text was updated successfully, but these errors were encountered: