cmd/link: add debug print in hostobjCopy

In external linking mode, when the external linker fails to handle
something in a host object file, it usually reports the name of
the host object which is a copied file named 000NNN.o. This is
often not helpful to determine what file it is. Add some debug
print so at least in -v mode it is more helpful.

Change-Id: Ibe762bff6a25640d16ee0dc082736ba5161b7522
Reviewed-on: https://go-review.googlesource.com/c/go/+/458735
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Cherry Mui 2022-12-20 19:31:40 -05:00
parent 08425feae5
commit 780db9a63d

View file

@ -1222,13 +1222,16 @@ func hostlinksetup(ctxt *Link) {
// hostobjCopy creates a copy of the object files in hostobj in a
// temporary directory.
func hostobjCopy() (paths []string) {
func (ctxt *Link) hostobjCopy() (paths []string) {
var wg sync.WaitGroup
sema := make(chan struct{}, runtime.NumCPU()) // limit open file descriptors
for i, h := range hostobj {
h := h
dst := filepath.Join(*flagTmpdir, fmt.Sprintf("%06d.o", i))
paths = append(paths, dst)
if ctxt.Debugvlog != 0 {
ctxt.Logf("host obj copy: %s from pkg %s -> %s\n", h.pn, h.pkg, dst)
}
wg.Add(1)
go func() {
@ -1311,7 +1314,7 @@ func (ctxt *Link) archive() {
}
argv = append(argv, *flagOutfile)
argv = append(argv, filepath.Join(*flagTmpdir, "go.o"))
argv = append(argv, hostobjCopy()...)
argv = append(argv, ctxt.hostobjCopy()...)
if ctxt.Debugvlog != 0 {
ctxt.Logf("archive: %s\n", strings.Join(argv, " "))
@ -1650,7 +1653,7 @@ func (ctxt *Link) hostlink() {
}
argv = append(argv, filepath.Join(*flagTmpdir, "go.o"))
argv = append(argv, hostobjCopy()...)
argv = append(argv, ctxt.hostobjCopy()...)
if ctxt.HeadType == objabi.Haix {
// We want to have C files after Go files to remove
// trampolines csects made by ld.