Skip to content
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/compile: use &runtime.zerobase for static pointer-to-zero-sized-thing #47582

Closed
josharian opened this issue Aug 6, 2021 · 2 comments
Closed
Labels
binary-size FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@josharian
Copy link
Contributor

package p

type I interface{ F() }

var V = []I{
	T{},
}

var P = &T{}

type T struct{}

func (t T) F() {}

go tool compile -S x.go includes:

"".V SDATA size=24
	0x0000 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
	0x0010 01 00 00 00 00 00 00 00                          ........
	rel 0+8 t=1 ""..stmp_0+0
"".P SDATA size=8
	0x0000 00 00 00 00 00 00 00 00                          ........
	rel 0+8 t=1 ""..stmp_2+0
""..stmp_0 SDATA static size=16
	0x0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	rel 0+0 t=24 type."".T+0
	rel 0+8 t=1 go.itab."".T,"".I+0
	rel 8+8 t=1 ""..stmp_1+0
""..stmp_1 SNOPTRBSS static size=0
""..stmp_2 SNOPTRBSS static size=0

Note that we're making static tmp symbols for zero-sized things. We should be able to omit stmp_1 and stmp_2 here and use a pointer to runtime.zerobase instead.

This happens a handful of times in std, but not enough for significant wins. Low priority.

@josharian josharian added this to the Unplanned milestone Aug 6, 2021
@cherrymui
Copy link
Member

The linker would combine all the zero-size static tmps and even with other static tmps. Does it actually matter?

Maybe not because it is not marked readonly? Maybe we could mark all zero-size data read-only.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 10, 2021
@josharian
Copy link
Contributor Author

The linker would combine all the zero-size static tmps and even with other static tmps. Does it actually matter?

Realistically, not very much.

@golang golang locked and limited conversation to collaborators Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
binary-size FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants