Multiple function with same name

56 views
Skip to first unread message

Charlie Dorian

unread,
Jan 10, 2010, 5:36:33 PM1/10/10
to golang-nuts
In "A Manual for the Plan 9 assembler" is this statement: "Setting the
2 bit allows multiple definitions of the same TEXT symbol in a
program; the loader will place only one such function in the image."

How does the loader decide which version to use?

Russ Cox

unread,
Jan 10, 2010, 5:50:44 PM1/10/10
to Charlie Dorian, golang-nuts
It picks the first one it sees.  Tools that use that bit
(called DUPOK) must make sure it doesn't matter which
gets used.  This was used in Alef for automatically
generated code fragments that could be shared across
multiple objects.

You're probably looking at this because all the assembly
routines use 7 as their bitmask, but they don't really need to.
Really they should all be using 5 (NOPROF+NOSPLIT) but
somehow the idiom of 7 got established.

Russ

Charles Dorian

unread,
Jan 10, 2010, 5:53:20 PM1/10/10
to r...@golang.org, golang-nuts
In that case, if there are, say, CPU-only versus FPU versions of a function, how does the loader know to use the faster one?

Russ Cox

unread,
Jan 10, 2010, 6:05:08 PM1/10/10
to Charles Dorian, golang-nuts
On Sun, Jan 10, 2010 at 14:53, Charles Dorian <cldo...@gmail.com> wrote:
> In that case, if there are, say, CPU-only versus FPU versions of a function,
> how does the loader know to use the faster one?

In that case only one should be included in the archive.
In the specific case of math.Sqrt, the Makefile arranges
to compile either sqrt.go or sqrt_$(GOARCH).s but not both.

Russ

Reply all
Reply to author
Forward
0 new messages