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

Comments

@josharian
Copy link
Contributor

@josharian josharian commented Aug 6, 2021

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
Contributor

@cherrymui cherrymui commented Aug 9, 2021

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.

Loading

@josharian
Copy link
Contributor Author

@josharian josharian commented Aug 11, 2021

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

Realistically, not very much.

Loading

@josharian josharian closed this Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants