mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd: linker changes for shared library initialization
Suggested by iant@, this change:
- looks for a symbol _rt0_<GOARCH>_<GOOS>_lib,
- if the symbol is present, adds a new entry into the .init_array ELF
section that points to the symbol.
The end-effect is that the symbol _rt0_<GOARCH>_<GOOS>_lib will be
invoked as soon as the (ELF) shared library is loaded, which will in turn
initialize the runtime. (To be implemented.)
Change-Id: I99911a180215a6df18f8a18483d12b9b497b48f4
Reviewed-on: https://go-review.googlesource.com/7692
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
ff1f3a11e4
commit
8da54a4eec
3 changed files with 22 additions and 0 deletions
|
|
@ -936,6 +936,15 @@ func Addstring(s *LSym, str string) int64 {
|
|||
return int64(r)
|
||||
}
|
||||
|
||||
func addinitarrdata(s *LSym) {
|
||||
p := s.Name + ".ptr"
|
||||
sp := Linklookup(Ctxt, p, 0)
|
||||
sp.Type = SINITARR
|
||||
sp.Size = 0
|
||||
sp.Dupok = 1
|
||||
Addaddr(Ctxt, sp, s)
|
||||
}
|
||||
|
||||
func dosymtype() {
|
||||
for s := Ctxt.Allsym; s != nil; s = s.Allsym {
|
||||
if len(s.P) > 0 {
|
||||
|
|
@ -946,6 +955,11 @@ func dosymtype() {
|
|||
s.Type = SNOPTRDATA
|
||||
}
|
||||
}
|
||||
// Create a new entry in the .init_array section that points to the
|
||||
// library initializer function.
|
||||
if Flag_shared != 0 && s.Name == INITENTRY {
|
||||
addinitarrdata(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue