how linker decide addr of sym in a circle call?

77 views
Skip to first unread message

xie cui

unread,
Jan 13, 2021, 10:39:28 AM1/13/21
to golang-nuts
in linker,
the code is like this:

func f() {
   g()
}

func g() {
    f()
}
when gen binary code of func f, need func g, and gen g need f,
how linker deal with this situation, and where is the code?
is dynrelocsym do this job? it seem that it can deal with circles calls?

Ian Lance Taylor

unread,
Jan 13, 2021, 6:16:39 PM1/13/21
to xie cui, golang-nuts
The linker gets code for f that has a relocation that says "here
insert a call to g", and gets code for g that has a relocation that
says "here insert a call to f". The linker places the code for f and
g into the output. Then it walks over all the relocations, and, for
this example, inserts a call to the appropriate address.

Ian
Reply all
Reply to author
Forward
0 new messages