What version of Go are you using (go version)?
1.9.2
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
What did you do?
package main
type TreeCell struct {
Tabs func() *string
}
func Cell() *string {
s:= ""
return &s
}
func Table(Line *[]TreeCell) {
if Line != nil {
Num["rtt"] = Line
}
}
var (
Num map[string]*[]TreeCell
)
func main() {
Table(&[]TreeCell{
TreeCell{Tabs: Cell},
TreeCell{Tabs: Cell},
...repeat 15000 times
TreeCell{Tabs: Cell},
})
}
go build -a -v -gcflags "-N -l" -ldflags "-s -w"
Size of executable file 1,9Mb
Andreys-Mac-Pro:test andrey$ size -A test
test :
section size addr
__text 1459891 16781312
__rodata 158107 18241216
__symbol_stub1 0 18399323
__typelink 2016 18399328
__itablink 8 18401344
__gosymtab 0 18401352
__gopclntab 194547 18401376
__nl_symbol_ptr 0 18599936
__noptrdata 2584 18599936
__data 1952 18602528
__bss 123400 18604480
__noptrbss 9016 18727904
Total 1951521
if I change the func() *string to the interface{}
type TreeCell struct {
Tabs interface{}
}
then size of executable file 32Mb
Andreys-Mac-Pro:test andrey$ size -A test
test :
section size addr
__text 1864389 16781312
__rodata 30375699 18645728
__symbol_stub1 0 49021427
__typelink 2016 49021440
__itablink 8 49023456
__gosymtab 0 49023464
__gopclntab 319155 49023488
__nl_symbol_ptr 0 49344512
__noptrdata 2584 49344512
__data 1952 49347104
__bss 123400 49349056
__noptrbss 9016 49472480
Total 32698219
If we exclude the -gcflags '-N -l' params, then interface{} is 2MB func() *string is 32MB
Next Step
I increase size of function
func Cell() *string {
s:= "01234567890102345678901234567890123456789012345678900123456789010234567890123456789012345678901234567890"
return &s
}
or
func Cell() *string {
s:= ""
for i := 0; i < 5; i++ {
s= s +s
for j := 0; j < 5; j++ {
s= s +s
for k := 0; k < 5; k++ {
s= s +"df"
}
}
}
return &s
}
But the size remained the same. I think that this is not inline problem.
My questions
- Why increased __rodata 30375699 and not __text?
- Why the flag works differently on func() *string and interface{}?
- I think this is a compiler bug.
https://stackoverflow.com/questions/47968970/inlining-and-output-binary-size
What version of Go are you using (
go version)?1.9.2
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env)?GOHOSTARCH="amd64"
GOHOSTOS="darwin"
What did you do?
go build -a -v -gcflags "-N -l" -ldflags "-s -w"
Size of executable file 1,9Mb
if I change the func() *string to the interface{}
then size of executable file 32Mb
If we exclude the -gcflags '-N -l' params, then interface{} is 2MB func() *string is 32MB
Next Step
I increase size of function
or
But the size remained the same. I think that this is not inline problem.
My questions
https://stackoverflow.com/questions/47968970/inlining-and-output-binary-size