about go tool link, where link get code(text segment) from *.o files and write it to executable files?

91 views
Skip to first unread message

xie cui

unread,
Aug 30, 2020, 10:31:31 AM8/30/20
to golang-nuts
i am trying to understand code of cmd/link,  i need to know where linker get instructions(text segment in executable file) from *o file, and where linker write the binary data (.text segment) to excutable file(in linux it 's a elf file).

Ian Lance Taylor

unread,
Aug 30, 2020, 11:52:06 AM8/30/20
to xie cui, golang-nuts
On Sun, Aug 30, 2020 at 7:32 AM xie cui <cuiw...@gmail.com> wrote:
>
> i am trying to understand code of cmd/link, i need to know where linker get instructions(text segment in executable file) from *o file, and where linker write the binary data (.text segment) to excutable file(in linux it 's a elf file).

The linker was recently rewritten, so I'm describing tip and to some
extent Go 1.15, not earlier releases.

Object files are read by the cmd/link/internal/loader package. The Go
object file format is read by code in cmd/internal/goobj.

All the loadable segments are written out by the asmb function in
cmd/link/internal/asmb.go.

Ian
Reply all
Reply to author
Forward
0 new messages