Compilation fails when adding option "-trimpath", because change a dependency to require gcc

266 views
Skip to first unread message

Florent Bonneau

unread,
Feb 5, 2020, 12:33:30 PM2/5/20
to golang-nuts
Using docker image golang:1.13-alpine to build our code :
- Compiling with "go install -v oursoftware/..." our build is sucessfull
- Compiling with "go install -v -trimpath oursoftware/..." fails with following error :

...
runtime
runtime/cgo
vendor/golang.org/x/crypto/curve25519
# runtime/cgo
exec: "gcc": executable file not found in $PATH
encoding
...

We can for sure install the build tools upon the base image to solve the issue, but it doesn't seem normal that the "-trimpath" option had this side-effect ?

Can someone explain why it happens ?

The content of our go.mod if it helps :

go 1.13

require (
github.com/BurntSushi/toml v0.3.1
github.com/davecgh/go-spew v1.1.1
github.com/gin-gonic/gin v1.4.0
github.com/go-openapi/errors v0.19.2
github.com/go-openapi/strfmt v0.19.3
github.com/go-openapi/swag v0.19.5
github.com/go-openapi/validate v0.19.4
github.com/gofrs/uuid v3.2.0+incompatible
github.com/google/uuid v1.1.1
github.com/nicksnyder/go-i18n/v2 v2.0.3
github.com/prometheus/client_golang v1.2.1
github.com/rogpeppe/go-charset v0.0.0-20190617161244-0dc95cdf6f31
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.4.0
go.mongodb.org/mongo-driver v1.1.2 // indirect
go.uber.org/atomic v1.4.0
go.uber.org/zap v1.11.0
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
golang.org/x/text v0.3.2
gopkg.in/yaml.v2 v2.2.4
)


Thanks !

Florent Bonneau


Ian Lance Taylor

unread,
Feb 5, 2020, 12:46:59 PM2/5/20
to Florent Bonneau, golang-nuts
On Wed, Feb 5, 2020 at 9:33 AM Florent Bonneau
<tnerolf...@gmail.com> wrote:
>
> Using docker image golang:1.13-alpine to build our code :
> - Compiling with "go install -v oursoftware/..." our build is sucessfull
> - Compiling with "go install -v -trimpath oursoftware/..." fails with following error :
>
>
> ...
>
> runtime
> runtime/cgo
> vendor/golang.org/x/crypto/curve25519
> # runtime/cgo
> exec: "gcc": executable file not found in $PATH
> encoding
> ...
>
> We can for sure install the build tools upon the base image to solve the issue, but it doesn't seem normal that the "-trimpath" option had this side-effect ?
>
> Can someone explain why it happens ?

I haven't verified this, so this is just a guess, but perhaps without
-trimpath the go tool is using the prebuilt runtime/cgo.a, which was
built on a system with a C compiler. When you add -trimpath, the
runtime/cgo package needs to be rebuilt in order to trim the paths.
Unfortunately, that rebuild fails, as the system you are building on
does not have a C compiler.

Ian

Jérôme LAFORGE

unread,
Feb 6, 2020, 2:53:03 AM2/6/20
to golang-nuts

I haven't verified this, so this is just a guess, but perhaps without
-trimpath the go tool is using the prebuilt runtime/cgo.a, which was
built on a system with a C compiler.  When you add -trimpath, the
runtime/cgo package needs to be rebuilt in order to trim the paths.
Unfortunately, that rebuild fails, as the system you are building on
does not have a C compiler.

It would be great to prebuilt runtime/cgo.a also with `-trimpath` option in order  to avoid unobvious dependency with gcc when you have just added `-trimpath` option or at least mention it in `go help build` doc. 

Vladimir Varankin

unread,
Feb 10, 2020, 2:12:46 PM2/10/20
to golang-nuts
I faced the same problem lately. Have open an issue https://github.com/golang/go/issues/37158
Reply all
Reply to author
Forward
0 new messages