Commit 1409c287 authored by Russ Cox's avatar Russ Cox

cmd/go: rename .o files going into final .a

CL 64793 removed the collect step, which took all
the generated .o files and merged them into a single _all.o.
Now the generated .o files all go directly into the final .a.

The only property of the _all.o approach that was lost
in CL 64793 was that before we could be sure that the
one name we used was "ar-compatible", that is, short
enough not to be truncated.

Now that the generated .o files are being kept directly,
this CL gives them guaranteed ar-compatible names.

This doesn't matter for nearly all uses today, but for some
future processing it might help not to lose the .o suffix
or not to end up with two identical entries with truncated
names.

I might not have bothered with this except that it's what's
leftover after syncing my own CL disabling _all.o
(necessary for reproducible builds on macOS) against
Ian's CL 64793, which landed first.

Change-Id: Ic86ed2a51432a5a4c58dc523e092a86d341f1997
Reviewed-on: https://go-review.googlesource.com/67250
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 046c6589
...@@ -3492,10 +3492,22 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo ...@@ -3492,10 +3492,22 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
} }
outGo = append(outGo, gofiles...) outGo = append(outGo, gofiles...)
// Use sequential object file names to keep them distinct
// and short enough to fit in the .a header file name slots.
// We no longer collect them all into _all.o, and we'd like
// tools to see both the .o suffix and unique names, so
// we need to make them short enough not to be truncated
// in the final archive.
oseq := 0
nextOfile := func() string {
oseq++
return objdir + fmt.Sprintf("_x%03d.o", oseq)
}
// gcc // gcc
cflags := str.StringList(cgoCPPFLAGS, cgoCFLAGS) cflags := str.StringList(cgoCPPFLAGS, cgoCFLAGS)
for _, cfile := range cfiles { for _, cfile := range cfiles {
ofile := objdir + cfile[:len(cfile)-1] + "o" ofile := nextOfile()
if err := b.gcc(p, ofile, cflags, objdir+cfile); err != nil { if err := b.gcc(p, ofile, cflags, objdir+cfile); err != nil {
return nil, nil, err return nil, nil, err
} }
...@@ -3503,8 +3515,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo ...@@ -3503,8 +3515,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
} }
for _, file := range gccfiles { for _, file := range gccfiles {
base := filepath.Base(file) ofile := nextOfile()
ofile := objdir + cgoRe.ReplaceAllString(base[:len(base)-1], "_") + "o"
if err := b.gcc(p, ofile, cflags, file); err != nil { if err := b.gcc(p, ofile, cflags, file); err != nil {
return nil, nil, err return nil, nil, err
} }
...@@ -3513,8 +3524,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo ...@@ -3513,8 +3524,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
cxxflags := str.StringList(cgoCPPFLAGS, cgoCXXFLAGS) cxxflags := str.StringList(cgoCPPFLAGS, cgoCXXFLAGS)
for _, file := range gxxfiles { for _, file := range gxxfiles {
// Append .o to the file, just in case the pkg has file.c and file.cpp ofile := nextOfile()
ofile := objdir + cgoRe.ReplaceAllString(filepath.Base(file), "_") + ".o"
if err := b.gxx(p, ofile, cxxflags, file); err != nil { if err := b.gxx(p, ofile, cxxflags, file); err != nil {
return nil, nil, err return nil, nil, err
} }
...@@ -3522,8 +3532,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo ...@@ -3522,8 +3532,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
} }
for _, file := range mfiles { for _, file := range mfiles {
// Append .o to the file, just in case the pkg has file.c and file.m ofile := nextOfile()
ofile := objdir + cgoRe.ReplaceAllString(filepath.Base(file), "_") + ".o"
if err := b.gcc(p, ofile, cflags, file); err != nil { if err := b.gcc(p, ofile, cflags, file); err != nil {
return nil, nil, err return nil, nil, err
} }
...@@ -3532,8 +3541,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo ...@@ -3532,8 +3541,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
fflags := str.StringList(cgoCPPFLAGS, cgoFFLAGS) fflags := str.StringList(cgoCPPFLAGS, cgoFFLAGS)
for _, file := range ffiles { for _, file := range ffiles {
// Append .o to the file, just in case the pkg has file.c and file.f ofile := nextOfile()
ofile := objdir + cgoRe.ReplaceAllString(filepath.Base(file), "_") + ".o"
if err := b.gfortran(p, ofile, fflags, file); err != nil { if err := b.gfortran(p, ofile, fflags, file); err != nil {
return nil, nil, err return nil, nil, err
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment