mirror of
https://github.com/golang/go.git
synced 2025-05-20 06:43:26 +00:00
This deletes all sym.Symbol and sym.Reloc references. This is certainly not complete, and there are more cleanups to do. But I feel this makes a good first round. Change-Id: I7621d016957f7ef114be5f0606fcb3ad6aee71c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/234097 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org>
115 lines
2.5 KiB
Go
115 lines
2.5 KiB
Go
// Copyright 2015 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ld
|
|
|
|
import (
|
|
"cmd/link/internal/loader"
|
|
"encoding/binary"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
var atExitFuncs []func()
|
|
|
|
func AtExit(f func()) {
|
|
atExitFuncs = append(atExitFuncs, f)
|
|
}
|
|
|
|
// runAtExitFuncs runs the queued set of AtExit functions.
|
|
func runAtExitFuncs() {
|
|
for i := len(atExitFuncs) - 1; i >= 0; i-- {
|
|
atExitFuncs[i]()
|
|
}
|
|
atExitFuncs = nil
|
|
}
|
|
|
|
// Exit exits with code after executing all atExitFuncs.
|
|
func Exit(code int) {
|
|
runAtExitFuncs()
|
|
os.Exit(code)
|
|
}
|
|
|
|
// Exitf logs an error message then calls Exit(2).
|
|
func Exitf(format string, a ...interface{}) {
|
|
fmt.Fprintf(os.Stderr, os.Args[0]+": "+format+"\n", a...)
|
|
nerrors++
|
|
Exit(2)
|
|
}
|
|
|
|
// afterErrorAction updates 'nerrors' on error and invokes exit or
|
|
// panics in the proper circumstances.
|
|
func afterErrorAction() {
|
|
nerrors++
|
|
if *flagH {
|
|
panic("error")
|
|
}
|
|
if nerrors > 20 {
|
|
Exitf("too many errors")
|
|
}
|
|
}
|
|
|
|
// Errorf logs an error message.
|
|
//
|
|
// If more than 20 errors have been printed, exit with an error.
|
|
//
|
|
// Logging an error means that on exit cmd/link will delete any
|
|
// output file and return a non-zero error code.
|
|
//
|
|
// TODO: remove. Use ctxt.Errof instead.
|
|
// All remaining calls use nil as first arg.
|
|
func Errorf(dummy *int, format string, args ...interface{}) {
|
|
format += "\n"
|
|
fmt.Fprintf(os.Stderr, format, args...)
|
|
afterErrorAction()
|
|
}
|
|
|
|
// Errorf method logs an error message.
|
|
//
|
|
// If more than 20 errors have been printed, exit with an error.
|
|
//
|
|
// Logging an error means that on exit cmd/link will delete any
|
|
// output file and return a non-zero error code.
|
|
func (ctxt *Link) Errorf(s loader.Sym, format string, args ...interface{}) {
|
|
if ctxt.loader != nil {
|
|
ctxt.loader.Errorf(s, format, args...)
|
|
return
|
|
}
|
|
// Note: this is not expected to happen very often.
|
|
format = fmt.Sprintf("sym %d: %s", s, format)
|
|
format += "\n"
|
|
fmt.Fprintf(os.Stderr, format, args...)
|
|
afterErrorAction()
|
|
}
|
|
|
|
func artrim(x []byte) string {
|
|
i := 0
|
|
j := len(x)
|
|
for i < len(x) && x[i] == ' ' {
|
|
i++
|
|
}
|
|
for j > i && x[j-1] == ' ' {
|
|
j--
|
|
}
|
|
return string(x[i:j])
|
|
}
|
|
|
|
func stringtouint32(x []uint32, s string) {
|
|
for i := 0; len(s) > 0; i++ {
|
|
var buf [4]byte
|
|
s = s[copy(buf[:], s):]
|
|
x[i] = binary.LittleEndian.Uint32(buf[:])
|
|
}
|
|
}
|
|
|
|
// contains reports whether v is in s.
|
|
func contains(s []string, v string) bool {
|
|
for _, x := range s {
|
|
if x == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|