Skip to content
Snippets Groups Projects
loader.go 88.8 KiB
Newer Older
  • Learn to ignore specific revisions
  • 			lists := [2][]sym.LoaderSym{lib.Textp2, lib.DupTextSyms2}
    
    			for i, list := range lists {
    
    					if l.attrReachable.Has(sym) && !assignedToUnit.Has(sym) {
    
    						unit := l.SymUnit(sym)
    						if unit != nil {
    							unit.Textp2 = append(unit.Textp2, s)
    
    							assignedToUnit.Set(sym)
    
    						// Dupok symbols may be defined in multiple packages; the
    						// associated package for a dupok sym is chosen sort of
    						// arbitrarily (the first containing package that the linker
    						// loads). Canonicalizes its Pkg to the package with which
    						// it will be laid down in text.
    						if i == 1 /* DupTextSyms2 */ && l.SymPkg(sym) != lib.Pkg {
    							l.SetSymPkg(sym, lib.Pkg)
    						}
    
    			lib.Textp2 = nil
    			lib.DupTextSyms2 = nil
    
    // ErrorReporter is a helper class for reporting errors.
    type ErrorReporter struct {
    	ldr              *Loader
    	AfterErrorAction func()
    }
    
    // Errorf method logs an error message.
    //
    // After each error, the error actions function will be invoked; this
    // will either terminate the link immediately (if -h option given)
    // or it will keep a count and exit if more than 20 errors have been printed.
    //
    // Logging an error means that on exit cmd/link will delete any
    // output file and return a non-zero error code.
    //
    func (reporter *ErrorReporter) Errorf(s Sym, format string, args ...interface{}) {
    	if s != 0 && reporter.ldr.SymName(s) != "" {
    		format = reporter.ldr.SymName(s) + ": " + format
    	} else {
    		format = fmt.Sprintf("sym %d: %s", s, format)
    	}
    	format += "\n"
    	fmt.Fprintf(os.Stderr, format, args...)
    	reporter.AfterErrorAction()
    }
    
    // GetErrorReporter returns the loader's associated error reporter.
    func (l *Loader) GetErrorReporter() *ErrorReporter {
    	return l.errorReporter
    }
    
    // Errorf method logs an error message. See ErrorReporter.Errorf for details.
    func (l *Loader) Errorf(s Sym, format string, args ...interface{}) {
    
    	l.errorReporter.Errorf(s, format, args...)
    
    // For debugging.
    func (l *Loader) Dump() {
    	fmt.Println("objs")
    	for _, obj := range l.objs {
    		if obj.r != nil {
    			fmt.Println(obj.i, obj.r.unit.Lib)
    		}
    	}
    
    	fmt.Println("Nsyms:", len(l.objSyms))
    
    	for i := Sym(1); i < Sym(len(l.objSyms)); i++ {
    
    		pi := interface{}("")
    		if l.IsExternal(i) {
    			pi = fmt.Sprintf("<ext %d>", l.extIndex(i))
    		}
    		var s *sym.Symbol
    		if int(i) < len(l.Syms) {
    			s = l.Syms[i]
    
    			fmt.Println(i, s, s.Type, pi)
    
    			fmt.Println(i, l.SymName(i), "<not loaded>", pi)
    
    	for name, i := range l.symsByName[0] {
    		fmt.Println(i, name, 0)
    	}
    	for name, i := range l.symsByName[1] {
    		fmt.Println(i, name, 1)
    
    	fmt.Println("payloads:")
    	for i := range l.payloads {
    		pp := l.payloads[i]
    		fmt.Println(i, pp.name, pp.ver, pp.kind)
    	}