Skip to content

Commit

Permalink
rename _buildModule to initmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
pkujhd committed Feb 7, 2022
1 parent 5cc2629 commit b62c3ed
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
14 changes: 7 additions & 7 deletions gcdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
KindGCProg = 1 << 6
)

func genGCData(linker *Linker, codeModule *CodeModule, symbolMap map[string]uintptr, w *gcprog.Writer, sym *obj.Sym) error {
func generategcdata(linker *Linker, codeModule *CodeModule, symbolMap map[string]uintptr, w *gcprog.Writer, sym *obj.Sym) error {
segment := &codeModule.segment
//if symbol is in loader, ignore generate gc data
if symbolMap[sym.Name] < uintptr(segment.dataBase) || symbolMap[sym.Name] > uintptr(segment.dataBase+segment.sumDataLen) {
Expand Down Expand Up @@ -49,7 +49,7 @@ func genGCData(linker *Linker, codeModule *CodeModule, symbolMap map[string]uint
return nil
}

func getSortSym(symMap map[string]*obj.Sym, kind int) []*obj.Sym {
func sortSym(symMap map[string]*obj.Sym, kind int) []*obj.Sym {
syms := make(map[int]*obj.Sym)
keys := []int{}
for _, sym := range symMap {
Expand All @@ -66,14 +66,14 @@ func getSortSym(symMap map[string]*obj.Sym, kind int) []*obj.Sym {
return symbols
}

func fillGCData(linker *Linker, codeModule *CodeModule, symbolMap map[string]uintptr) error {
func (linker *Linker) addgcdata(codeModule *CodeModule, symbolMap map[string]uintptr) error {
module := codeModule.module
w := gcprog.Writer{}
w.Init(func(x byte) {
codeModule.gcdata = append(codeModule.gcdata, x)
})
for _, sym := range getSortSym(linker.symMap, symkind.SDATA) {
err := genGCData(linker, codeModule, symbolMap, &w, sym)
for _, sym := range sortSym(linker.symMap, symkind.SDATA) {
err := generategcdata(linker, codeModule, symbolMap, &w, sym)
if err != nil {
return err
}
Expand All @@ -88,8 +88,8 @@ func fillGCData(linker *Linker, codeModule *CodeModule, symbolMap map[string]uin
codeModule.gcbss = append(codeModule.gcbss, x)
})

for _, sym := range getSortSym(linker.symMap, symkind.SBSS) {
err := genGCData(linker, codeModule, symbolMap, &w, sym)
for _, sym := range sortSym(linker.symMap, symkind.SBSS) {
err := generategcdata(linker, codeModule, symbolMap, &w, sym)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions ld.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func (linker *Linker) buildModule(codeModule *CodeModule, symbolMap map[string]u
append2Slice(&module.pclntable, uintptr(unsafe.Pointer(&funcbucket[0])), length)
module.findfunctab = (uintptr)(unsafe.Pointer(&module.pclntable[len(module.pclntable)-length]))

if err = fillGCData(linker, codeModule, symbolMap); err != nil {
if err = linker.addgcdata(codeModule, symbolMap); err != nil {
return err
}
for name, addr := range symbolMap {
Expand All @@ -427,7 +427,7 @@ func (linker *Linker) buildModule(codeModule *CodeModule, symbolMap map[string]u
module.typemap[typeOff(addr-module.types)] = addr
}
}
linker._buildModule(codeModule)
initmodule(codeModule.module, linker)

modulesLock.Lock()
addModule(codeModule)
Expand Down
6 changes: 4 additions & 2 deletions module.1.10.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type moduledata struct {
next *moduledata
}

func (linker *Linker) _buildModule(codeModule *CodeModule) {
codeModule.module.filetab = linker.filetab
func initmodule(module *moduledata, linker *Linker) {
module.filetab = linker.filetab
module.hasmain = 0
module.bad = false
}
4 changes: 2 additions & 2 deletions module.1.16.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ type moduledata struct {
next *moduledata
}

func (linker *Linker) _buildModule(codeModule *CodeModule) {
module := codeModule.module
func initmodule(module *moduledata, linker *Linker) {
module.pcHeader = (*pcHeader)(unsafe.Pointer(&(module.pclntable[0])))
module.pcHeader.nfunc = len(module.ftab)
module.pcHeader.nfiles = (uint)(len(module.filetab))
Expand All @@ -79,4 +78,5 @@ func (linker *Linker) _buildModule(codeModule *CodeModule) {
module.cutab = linker.filetab
module.filetab = module.pclntable
module.hasmain = 0
module.bad = false
}
4 changes: 2 additions & 2 deletions module.1.18.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ type moduledata struct {
next *moduledata
}

func (linker *Linker) _buildModule(codeModule *CodeModule) {
module := codeModule.module
func initmodule(module *moduledata, linker *Linker) {
module.pcHeader = (*pcHeader)(unsafe.Pointer(&(module.pclntable[0])))
module.pcHeader.textStart = module.text
module.pcHeader.nfunc = len(module.ftab)
Expand All @@ -83,6 +82,7 @@ func (linker *Linker) _buildModule(codeModule *CodeModule) {
module.cutab = linker.filetab
module.filetab = module.pclntable
module.hasmain = 0
module.bad = false
module.gofunc = module.noptrdata
module.rodata = module.noptrdata
}
4 changes: 2 additions & 2 deletions module.1.8.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ type moduledata struct {
next *moduledata
}

func (linker *Linker) _buildModule(codeModule *CodeModule) {
codeModule.module.filetab = linker.filetab
func initmodule(module *moduledata, linker *Linker) {
module.filetab = linker.filetab
}

0 comments on commit b62c3ed

Please sign in to comment.