From 77c171896e1c39fbf15c436b85bb6c22b9cb4391 Mon Sep 17 00:00:00 2001 From: pkujhd Date: Sat, 13 Jan 2024 14:33:28 +0800 Subject: [PATCH] add ReadDependPkg function --- readobj.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/readobj.go b/readobj.go index 4c5b8160..05c26e5c 100644 --- a/readobj.go +++ b/readobj.go @@ -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 +}