Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/vgo: fails to build cgo dependant executable with musl (e.g Alpine linux) #24493

Closed
RichyHBM opened this issue Mar 22, 2018 · 2 comments
Closed
Milestone

Comments

@RichyHBM
Copy link

What version of Go are you using (go version)?

Go: go version go1.10 linux/amd64
VGo: go version go1.10 linux/amd64 vgo:2018-02-20.1

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

Go

GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build386422751=/tmp/go-build -gno-record-gcc-switches"

VGo

GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build456813961=/tmp/go-build -gno-record-gcc-switches"
VGOMODROOT=""

What did you do?

Given a basic golang program that makes use of net (thus cgo):

package main

import (
	"fmt"
	"log"
	"net/http"
)

func server(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello golang!")
}

func main() {
	http.HandleFunc("/", server)

	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}

Running it in an Alpine container with standard go tools works fine.

Dockerfile:

FROM golang:1.10.0-alpine3.7 as builder
USER root
ENV GOPATH='/builder'
WORKDIR /builder/src/github.com/richyhbm/go-test
ADD . /builder/src/github.com/richyhbm/go-test
RUN go build

Output of building the docker file:

/gotest $ docker build -t goapp .
Sending build context to Docker daemon  4.096kB
Step 1/6 : FROM golang:1.10.0-alpine3.7 as builder
 ---> 85256d3905e2
Step 2/6 : USER root
 ---> Using cache
 ---> 6fe0b5104cdf
Step 3/6 : ENV GOPATH='/builder'
 ---> Using cache
 ---> b70bb8a6b6a0
Step 4/6 : WORKDIR /builder/src/github.com/richyhbm/go-test
 ---> Using cache
 ---> 4d4707c0e99d
Step 5/6 : ADD . /builder/src/github.com/richyhbm/go-test
 ---> d507c37cf1c2
Step 6/6 : RUN go build
 ---> Running in 12f53eaba187
Removing intermediate container 12f53eaba187
 ---> ad2b407ca361
Successfully built ad2b407ca361
Successfully tagged goapp:latest

However take that same code and build it using vgo, using the following dockerfile:

FROM golang:1.10.0-alpine3.7 as builder
USER root
RUN apk update
RUN apk add git clang
RUN go get -u golang.org/x/vgo
WORKDIR /builder
ADD . /builder
RUN vgo build

And firstly running the vgo test without installing clang gives:

 ---> Running in d43959a0e06c
# runtime/cgo
exec: "clang": executable file not found in $PATH

After installing it you get:

/vgotest $ docker build -t goapp .
Sending build context to Docker daemon   12.8kB
Step 1/8 : FROM golang:1.10.0-alpine3.7 as builder
 ---> 85256d3905e2
Step 2/8 : USER root
 ---> Using cache
 ---> 6fe0b5104cdf
Step 3/8 : RUN apk update
 ---> Using cache
 ---> 808f907f3d65
Step 4/8 : RUN apk add git clang
 ---> Running in 88d527c9f56b
(1/10) Installing libgcc (6.4.0-r5)
(2/10) Installing libstdc++ (6.4.0-r5)
(3/10) Installing clang-libs (5.0.0-r0)
(4/10) Installing libxml2 (2.9.7-r0)
(5/10) Installing clang (5.0.0-r0)
(6/10) Installing libssh2 (1.8.0-r2)
(7/10) Installing libcurl (7.59.0-r0)
(8/10) Installing expat (2.2.5-r0)
(9/10) Installing pcre2 (10.30-r0)
(10/10) Installing git (2.15.0-r1)
Executing busybox-1.27.2-r7.trigger
OK: 200 MiB in 22 packages
Removing intermediate container 88d527c9f56b
 ---> ad5f5c333708
Step 5/8 : RUN go get -u golang.org/x/vgo
 ---> Running in 4e658f3fdcf5
Removing intermediate container 4e658f3fdcf5
 ---> 8a1c38f6f356
Step 6/8 : WORKDIR /builder
Removing intermediate container cfa3153bf761
 ---> fed5be70f790
Step 7/8 : ADD . /builder
 ---> a907cbe009da
Step 8/8 : RUN vgo build
 ---> Running in 73791c7de043
# runtime/cgo
cgo-builtin-prolog:1:10: fatal error: 'stddef.h' file not found
#include <stddef.h> /* for ptrdiff_t and size_t below */
         ^~~~~~~~~~
1 error generated.

Note that compiling it as a statically linked executable with cgo turned off works fine.

CGO_ENABLED=0 GOOS=linux vgo build -a -installsuffix cgo

What did you expect to see?

Program to build as expected

What did you see instead?

Missing header error

@gopherbot gopherbot added this to the vgo milestone Mar 22, 2018
@AlexRouSg
Copy link
Contributor

In your vgo docker you're installing clang while in the go docker you did not. Try installing clang on the go docker to make sure this is indeed vgo related and not a clang issue.

@RichyHBM
Copy link
Author

@AlexRouSg Having clang installed doesnt affect it, but setting CC=clang gives the same error as with vgo.

This seems to just be a duplicate of #23965

@golang golang locked and limited conversation to collaborators Mar 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants