> To this end, I am trying to understand the import statement in
> gccgo's .go_export output that one gets when compiling a package to an
> ELF object file.
The .go_export output has changed in the past and will change in the
future. I'm not making any commitment to keeping the same format.
Please bear that in mind if you want to parse it directly.
> I am parsing this output to establish dependencies between packages so
> that SCons only rebuilds what is needed and so that I can construct
> the parameters needed for linking automatically.
The gccgo compiler is going to want to do this too, so at some point
there will be a better way to determine which packages are imported.
That is not very high on my personal priority list, but of course it
would be great if somebody else wanted to tackle it.
> With a project called foo and a package called bar, and using the -fgo-
> prefix=foo option, I get the following in bar.o:
>
> package bar;
> prefix foo_bar;
> priority 10;
> import bar foo_bar.bar..import 10 math libgo_math.math..import 1
> unicode libgo_unicode.unicode..import 1 syscall
> libgo__.syscall..import 3 os libgo_os.os..import 4 io
> libgo_io.io..import 5 strconv libgo_strconv.strconv..import 7 time
> libgo_time.time..import 9;
>
> Firstly,
>
> import 1 syscall libgo__.syscall
>
> seems a bit strange. Seems the go_prefix went missing there. Was that
> intentional?
It was probably just a mistake on my part. I'm about to commit a patch
to fix it.
> Then, I am trying to understand why package bar contains
>
> import bar foo_bar.bar
>
> again. This doesn't seem to happen for all my packages, though. If I
> have a package baz the imports bar, baz doesn't have a
>
> import baz foo_baz.baz
>
> in its import line.
The import line lists all the initialization functions which must be run
at program startup time if you import that package. The numbers give
the order in which the import functions must be run, lowest to highest.
The list includes the initialization function for the current package,
but only if the current package actually has an initialization function.
A package with no init function and with no global variables that
require runtime initialization will not have an initialization function.
The list for a given package is the union of the lists for all imported
packages, plus the initialization function for the package itself if
any.
Note that in particular this means that not all imported packages are
listed on that line. There is currently no reliable way to determine
the set of imported packages.
Ian
> What's the current thinking behind gccgo in the Go team? Should we be
> looking to use it as our production compiler in the next 3 to 6
> months, or are we better off sticking to the standard toolchain for a
> while?
I don't think there is one answer to that, as it depends on your plans
and expectations. What is preventing you from using it as your
production compiler now? It would be helpful if you reported them in
the issue tracker, to make it more likely that they will get fixed.
I'm currently the sole developer on gccgo so it's hard for me to predict
when any particular fixes will occur. Right now I'm working to get
gccgo merged into the mainline gcc distribution, and it should be part
of gcc 4.6. But of course the gcc release will inevitably lag language
and library changes in 6g.
> Another problem I've run into in my experiments is that we already
> depend on libraries outside the Go distribution, like goprotobuf,
> which doesn't have a gccgo build yet (AFAIK). A common build system
> (included in the Go distribution?) is probably necessary to make it
> easy to switch between the two toolchains across multiple projects.
Yes, that would be great. I haven't thought about that at all myself.
Ian
Another approach is to write a tool to read the dependancies from Go
source files. The packages under go/ in the standard library will help
you parse Go code. Also check out src/cmd/goinstall/parse.go.
Andrew
If I may revisit an old discussion...
On Sep 20 2010, 7:17 pm, Ian Lance Taylor <i...@google.com> wrote:
> The import line lists all the initialization functions which must be run
> at program startup time if you import that package. The numbers give
> the order in which the import functions must be run, lowest to highest.
> The list includes the initialization function for the current package,
> but only if the current package actually has an initialization function.
> A package with no init function and with no global variables that
> require runtime initialization will not have an initialization function.
> The list for a given package is the union of the lists for all imported
> packages, plus the initialization function for the package itself if
> any.
> Note that in particular this means that not all imported packages are
> listed on that line. There is currently no reliable way to determine
> the set of imported packages.
We've been building some of our code with gccgo for a while and the
only real pain point is this issue.
Do you have any new ideas on how to determine the set of imported
packages when dealing with a mix of source and binaries?
I think GCC 4.6 is in bugfix mode now, so an extra feature like this
will probably have to wait, right?
Regards
Albert
gccgo is a new feature, so it can still be changed.
While it's obviously easy to get the list of imports from the source
code, there is no way to reliably get it from the binaries. It will
require a change to the export data. Want to try writing a patch? You
would need to change how imported_init_fns_ works, probably by renaming
it, and add a way for the imports line in export data to indicate an
imported package with no initialization function.
Ian