Relative imports and GNU linker... ?

Ian Lance Taylor iant@google.com
Tue Jun 1 06:25:00 GMT 2010


Trojany <troianor@trash-mail.com> writes:

> That new language has a feature which I'm not sure about whether and how it
> can be done with gnu linker:
> In that language it is allowed, when importing symbols from other source
> files, to explicitly specify which imported symbol comes from which source
> file.

That's a tough one.  I faced a similar issue with Go.  Go permits
multiple packages in a single executable with the same name.  Simple
name mangling rule cause collisions in such a case.  For Go, I wimped
out: I added a -fgo-prefix option to the compiler which essentially
sets the name to use.  This name is then recorded in the exported
information, so that other packages which import that package know the
symbol names to use.

Another approach I considered was to give each package a UUID and use
that in the names.  This has the disadvantage of making debugging
harder.

Both these approaches assume that at compile time there is some way to
discover the naming convention used by an imported package.  I don't
know if that is true of your language.

In general, you will need a naming trick of this sort to make your
import statements work with the GNU linker.  The GNU linker does not
rename symbols on the fly.

Ian



More information about the Gcc-help mailing list