@@ -3157,18 +3157,18 @@ func gccgoCleanPkgpath(p *load.Package) string {
3157
3157
}
3158
3158
3159
3159
// gcc runs the gcc C compiler to create an object from a single C file.
3160
- func (b * Builder ) gcc (p * load.Package , out string , flags []string , cfile string ) error {
3161
- return b .ccompile (p , out , flags , cfile , b .GccCmd (p .Dir ))
3160
+ func (b * Builder ) gcc (p * load.Package , workdir , out string , flags []string , cfile string ) error {
3161
+ return b .ccompile (p , out , flags , cfile , b .GccCmd (p .Dir , workdir ))
3162
3162
}
3163
3163
3164
3164
// gxx runs the g++ C++ compiler to create an object from a single C++ file.
3165
- func (b * Builder ) gxx (p * load.Package , out string , flags []string , cxxfile string ) error {
3166
- return b .ccompile (p , out , flags , cxxfile , b .GxxCmd (p .Dir ))
3165
+ func (b * Builder ) gxx (p * load.Package , workdir , out string , flags []string , cxxfile string ) error {
3166
+ return b .ccompile (p , out , flags , cxxfile , b .GxxCmd (p .Dir , workdir ))
3167
3167
}
3168
3168
3169
3169
// gfortran runs the gfortran Fortran compiler to create an object from a single Fortran file.
3170
- func (b * Builder ) gfortran (p * load.Package , out string , flags []string , ffile string ) error {
3171
- return b .ccompile (p , out , flags , ffile , b .gfortranCmd (p .Dir ))
3170
+ func (b * Builder ) gfortran (p * load.Package , workdir , out string , flags []string , ffile string ) error {
3171
+ return b .ccompile (p , out , flags , ffile , b .gfortranCmd (p .Dir , workdir ))
3172
3172
}
3173
3173
3174
3174
// ccompile runs the given C or C++ compiler and creates an object from a single source file.
@@ -3211,41 +3211,41 @@ func (b *Builder) ccompile(p *load.Package, outfile string, flags []string, file
3211
3211
}
3212
3212
3213
3213
// gccld runs the gcc linker to create an executable from a set of object files.
3214
- func (b * Builder ) gccld (p * load.Package , out string , flags []string , objs []string ) error {
3214
+ func (b * Builder ) gccld (p * load.Package , objdir , out string , flags []string , objs []string ) error {
3215
3215
var cmd []string
3216
3216
if len (p .CXXFiles ) > 0 || len (p .SwigCXXFiles ) > 0 {
3217
- cmd = b .GxxCmd (p .Dir )
3217
+ cmd = b .GxxCmd (p .Dir , objdir )
3218
3218
} else {
3219
- cmd = b .GccCmd (p .Dir )
3219
+ cmd = b .GccCmd (p .Dir , objdir )
3220
3220
}
3221
3221
return b .run (p .Dir , p .ImportPath , nil , cmd , "-o" , out , objs , flags )
3222
3222
}
3223
3223
3224
3224
// gccCmd returns a gcc command line prefix
3225
3225
// defaultCC is defined in zdefaultcc.go, written by cmd/dist.
3226
- func (b * Builder ) GccCmd (objdir string ) []string {
3227
- return b .compilerCmd ("CC" , cfg .DefaultCC , objdir )
3226
+ func (b * Builder ) GccCmd (incdir , workdir string ) []string {
3227
+ return b .compilerCmd ("CC" , cfg .DefaultCC , incdir , workdir )
3228
3228
}
3229
3229
3230
3230
// gxxCmd returns a g++ command line prefix
3231
3231
// defaultCXX is defined in zdefaultcc.go, written by cmd/dist.
3232
- func (b * Builder ) GxxCmd (objdir string ) []string {
3233
- return b .compilerCmd ("CXX" , cfg .DefaultCXX , objdir )
3232
+ func (b * Builder ) GxxCmd (incdir , workdir string ) []string {
3233
+ return b .compilerCmd ("CXX" , cfg .DefaultCXX , incdir , workdir )
3234
3234
}
3235
3235
3236
3236
// gfortranCmd returns a gfortran command line prefix.
3237
- func (b * Builder ) gfortranCmd (objdir string ) []string {
3238
- return b .compilerCmd ("FC" , "gfortran" , objdir )
3237
+ func (b * Builder ) gfortranCmd (incdir , workdir string ) []string {
3238
+ return b .compilerCmd ("FC" , "gfortran" , incdir , workdir )
3239
3239
}
3240
3240
3241
3241
// compilerCmd returns a command line prefix for the given environment
3242
3242
// variable and using the default command when the variable is empty.
3243
- func (b * Builder ) compilerCmd (envvar , defcmd , objdir string ) []string {
3243
+ func (b * Builder ) compilerCmd (envvar , defcmd , incdir , workdir string ) []string {
3244
3244
// NOTE: env.go's mkEnv knows that the first three
3245
- // strings returned are "gcc", "-I", objdir (and cuts them off).
3245
+ // strings returned are "gcc", "-I", incdir (and cuts them off).
3246
3246
3247
3247
compiler := envList (envvar , defcmd )
3248
- a := []string {compiler [0 ], "-I" , objdir }
3248
+ a := []string {compiler [0 ], "-I" , incdir }
3249
3249
a = append (a , compiler [1 :]... )
3250
3250
3251
3251
// Definitely want -fPIC but on Windows gcc complains
@@ -3279,7 +3279,11 @@ func (b *Builder) compilerCmd(envvar, defcmd, objdir string) []string {
3279
3279
3280
3280
// Tell gcc not to include the work directory in object files.
3281
3281
if b .gccSupportsFlag (compiler , "-fdebug-prefix-map=a=b" ) {
3282
- a = append (a , "-fdebug-prefix-map=" + b .WorkDir + "=/tmp/go-build" )
3282
+ if workdir == "" {
3283
+ workdir = b .WorkDir
3284
+ }
3285
+ workdir = strings .TrimSuffix (workdir , string (filepath .Separator ))
3286
+ a = append (a , "-fdebug-prefix-map=" + workdir + "=/tmp/go-build" )
3283
3287
}
3284
3288
3285
3289
// Tell gcc not to include flags in object files, which defeats the
@@ -3508,15 +3512,15 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
3508
3512
cflags := str .StringList (cgoCPPFLAGS , cgoCFLAGS )
3509
3513
for _ , cfile := range cfiles {
3510
3514
ofile := nextOfile ()
3511
- if err := b .gcc (p , ofile , cflags , objdir + cfile ); err != nil {
3515
+ if err := b .gcc (p , a . Objdir , ofile , cflags , objdir + cfile ); err != nil {
3512
3516
return nil , nil , err
3513
3517
}
3514
3518
outObj = append (outObj , ofile )
3515
3519
}
3516
3520
3517
3521
for _ , file := range gccfiles {
3518
3522
ofile := nextOfile ()
3519
- if err := b .gcc (p , ofile , cflags , file ); err != nil {
3523
+ if err := b .gcc (p , a . Objdir , ofile , cflags , file ); err != nil {
3520
3524
return nil , nil , err
3521
3525
}
3522
3526
outObj = append (outObj , ofile )
@@ -3525,15 +3529,15 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
3525
3529
cxxflags := str .StringList (cgoCPPFLAGS , cgoCXXFLAGS )
3526
3530
for _ , file := range gxxfiles {
3527
3531
ofile := nextOfile ()
3528
- if err := b .gxx (p , ofile , cxxflags , file ); err != nil {
3532
+ if err := b .gxx (p , a . Objdir , ofile , cxxflags , file ); err != nil {
3529
3533
return nil , nil , err
3530
3534
}
3531
3535
outObj = append (outObj , ofile )
3532
3536
}
3533
3537
3534
3538
for _ , file := range mfiles {
3535
3539
ofile := nextOfile ()
3536
- if err := b .gcc (p , ofile , cflags , file ); err != nil {
3540
+ if err := b .gcc (p , a . Objdir , ofile , cflags , file ); err != nil {
3537
3541
return nil , nil , err
3538
3542
}
3539
3543
outObj = append (outObj , ofile )
@@ -3542,7 +3546,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
3542
3546
fflags := str .StringList (cgoCPPFLAGS , cgoFFLAGS )
3543
3547
for _ , file := range ffiles {
3544
3548
ofile := nextOfile ()
3545
- if err := b .gfortran (p , ofile , fflags , file ); err != nil {
3549
+ if err := b .gfortran (p , a . Objdir , ofile , fflags , file ); err != nil {
3546
3550
return nil , nil , err
3547
3551
}
3548
3552
outObj = append (outObj , ofile )
@@ -3577,7 +3581,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
3577
3581
func (b * Builder ) dynimport (p * load.Package , objdir , importGo , cgoExe string , cflags , cgoLDFLAGS , outObj []string ) error {
3578
3582
cfile := objdir + "_cgo_main.c"
3579
3583
ofile := objdir + "_cgo_main.o"
3580
- if err := b .gcc (p , ofile , cflags , cfile ); err != nil {
3584
+ if err := b .gcc (p , objdir , ofile , cflags , cfile ); err != nil {
3581
3585
return err
3582
3586
}
3583
3587
@@ -3589,7 +3593,7 @@ func (b *Builder) dynimport(p *load.Package, objdir, importGo, cgoExe string, cf
3589
3593
if (cfg .Goarch == "arm" && cfg .Goos == "linux" ) || cfg .Goos == "android" {
3590
3594
ldflags = append (ldflags , "-pie" )
3591
3595
}
3592
- if err := b .gccld (p , dynobj , ldflags , linkobj ); err != nil {
3596
+ if err := b .gccld (p , objdir , dynobj , ldflags , linkobj ); err != nil {
3593
3597
return err
3594
3598
}
3595
3599
0 commit comments