Skip to content

Commit 1409c28

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 046c658 commit 1409c28

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/cmd/go/internal/work/build.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3492,19 +3492,30 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
34923492
}
34933493
outGo = append(outGo, gofiles...)
34943494

3495+
// Use sequential object file names to keep them distinct
3496+
// and short enough to fit in the .a header file name slots.
3497+
// We no longer collect them all into _all.o, and we'd like
3498+
// tools to see both the .o suffix and unique names, so
3499+
// we need to make them short enough not to be truncated
3500+
// in the final archive.
3501+
oseq := 0
3502+
nextOfile := func() string {
3503+
oseq++
3504+
return objdir + fmt.Sprintf("_x%03d.o", oseq)
3505+
}
3506+
34953507
// gcc
34963508
cflags := str.StringList(cgoCPPFLAGS, cgoCFLAGS)
34973509
for _, cfile := range cfiles {
3498-
ofile := objdir + cfile[:len(cfile)-1] + "o"
3510+
ofile := nextOfile()
34993511
if err := b.gcc(p, ofile, cflags, objdir+cfile); err != nil {
35003512
return nil, nil, err
35013513
}
35023514
outObj = append(outObj, ofile)
35033515
}
35043516

35053517
for _, file := range gccfiles {
3506-
base := filepath.Base(file)
3507-
ofile := objdir + cgoRe.ReplaceAllString(base[:len(base)-1], "_") + "o"
3518+
ofile := nextOfile()
35083519
if err := b.gcc(p, ofile, cflags, file); err != nil {
35093520
return nil, nil, err
35103521
}
@@ -3513,17 +3524,15 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
35133524

35143525
cxxflags := str.StringList(cgoCPPFLAGS, cgoCXXFLAGS)
35153526
for _, file := range gxxfiles {
3516-
// Append .o to the file, just in case the pkg has file.c and file.cpp
3517-
ofile := objdir + cgoRe.ReplaceAllString(filepath.Base(file), "_") + ".o"
3527+
ofile := nextOfile()
35183528
if err := b.gxx(p, ofile, cxxflags, file); err != nil {
35193529
return nil, nil, err
35203530
}
35213531
outObj = append(outObj, ofile)
35223532
}
35233533

35243534
for _, file := range mfiles {
3525-
// Append .o to the file, just in case the pkg has file.c and file.m
3526-
ofile := objdir + cgoRe.ReplaceAllString(filepath.Base(file), "_") + ".o"
3535+
ofile := nextOfile()
35273536
if err := b.gcc(p, ofile, cflags, file); err != nil {
35283537
return nil, nil, err
35293538
}
@@ -3532,8 +3541,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
35323541

35333542
fflags := str.StringList(cgoCPPFLAGS, cgoFFLAGS)
35343543
for _, file := range ffiles {
3535-
// Append .o to the file, just in case the pkg has file.c and file.f
3536-
ofile := objdir + cgoRe.ReplaceAllString(filepath.Base(file), "_") + ".o"
3544+
ofile := nextOfile()
35373545
if err := b.gfortran(p, ofile, fflags, file); err != nil {
35383546
return nil, nil, err
35393547
}

0 commit comments

Comments
 (0)