Skip to content

Commit

Permalink
add ReadDependPkg function
Browse files Browse the repository at this point in the history
  • Loading branch information
pkujhd committed Jan 13, 2024
1 parent d69b6fd commit 77c1718
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions readobj.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,35 @@ func ReadObjs(files []string, pkgPaths []string) (*Linker, error) {
}
return linker, nil
}

func (linker *Linker) ReadDependPkg(file, pkgPath string, symbolNames []string) error {
//only add unresolved symbol in ObjSymbolMap. use temporary map store read symbols
objSymbolMap := linker.ObjSymbolMap
linker.ObjSymbolMap = make(map[string]*obj.ObjSymbol)
if err := linker.readObj(file, pkgPath); err != nil {
return err
}
initFuncName := getInitFuncName(pkgPath)
if _, ok := linker.ObjSymbolMap[initFuncName]; ok {
if _, err := linker.addSymbol(initFuncName); err != nil {
return err
}
}
for _, name := range symbolNames {
if _, ok := linker.ObjSymbolMap[name]; ok {
delete(linker.SymMap, name)
sym, err := linker.addSymbol(name)
if err != nil {
return err
}
linker.adaptOffset(sym)
}
}
for name, sym := range linker.ObjSymbolMap {
if _, ok := linker.SymMap[name]; ok {
objSymbolMap[name] = sym
}
}
linker.ObjSymbolMap = objSymbolMap
return nil
}

0 comments on commit 77c1718

Please sign in to comment.