On Mon, Jun 8, 2015 at 3:05 AM, Leff Ivanov <
droid...@gmail.com> wrote:
>
> Well, to be fare, I'm very new to Go and I'm coming from the C/C++
> background. I compiled Go 1.4.2
> compiler from sources to be able to crosscompile from my Linux box to
> Windows and Mac OSX, and
> it works pretty fine (more to say Go has the easiest crosscompiler setup
> I've ever seen). But even the
> helloworld executables are huge (1.0-1.5 Mb for helloworld executable).
In part Go binaries are large because they are, by default, statically
linked.
The overall issue for binary size is
http://golang.org/6853 .
> What is the purpose of empty ".symtab" section on Windows? Can I make Golang
> compiler not
> generate this section for the output windows executable?
I don't know.
> It seems that debug information can not be stripped for Mac OSX executables,
> is it some kind of
> bug or something ("-ldflags -s" works for Windows and Linux, but doesn't
> work for Mac)?
I think this is fixed in Go 1.5. I haven't checked, though.
> By using autoanalysis in IDA Pro I can see that several runtime functions
> that are linked in aren't
> in fact used by the code, is there something like LTO (link time
> optimization), that would remove
> unused functions from the output executable?
Unused functions should be removed by the linker. However, note that
it's hard for the linker to tell whether a method is used, since if
the value is converted to an interface type, such as by passing the
value to fmt.Print, then the method is retained.
> There are a lot of strings in the executable that looks like
> /home/<user>/go/scr/<gosrcfile.go>,
> these strings point to the sources of Golang's runtime and stdlib. What are
> these strings used
> for in the executable? Can I get rid of them, or at least make them contain
> only the file name
> without full path to the place where runtime and stdlib were built? I
> understand that this stuff
> can be used for debugging, but I can't imagine the situation when some
> compiler user needs
> to debug runtime or standard library.
These strings are used in backtraces, and it's quite normal to see a
backtrace for the runtime or standard library.
> There are a lot of strings in the executable that contains names and
> declarations for types and
> functions, I guess it is part of the RTTI (runtime type information) spec
> for Golang. Where are
> these string used in the executable? Can I safely get rid of them (knowing
> that I won't be using
> functions that needs runtime type information)?
These strings are used by the reflect package, which is used by basic
packages like fmt. There is no safe way to remove them.
> Is it possible to create my own custom and slim runtime library by cutting
> off things that I don't
> need from original runtime library, and make Golang compiler use it instead
> of original one? I'm
> asking about main Golang compiler, not the GCCGo one. The size of the
> executable doesn't
> mean much these days, but I want to be able to get rid of the stuff I don't
> actually need in the
> final executable, as Golang compiler by default seems to include too much
> stuff in it.
This is possible, I suppose, but there is no supported way to do it.
Hope this helps.
Ian