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

runtime/cgo: Unable to install Go from source with cgo enabled when using tcc on Alpine in Docker ("-Qunused-arguments") #60010

Closed
adamroyjones opened this issue May 5, 2023 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@adamroyjones
Copy link

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

1.20.4 to bootstrap master (a535055).

Does this issue reproduce with the latest release?

Yes.

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

linux/amd64

What did you do?

I was experimenting with small build containers for use with Go and I bumped into a problem that I don't feel I understand. It's possibly a bug or possibly something I misunderstood about the documentation.

In short, the documentation on installing Go from source says the following.

(Optional) Install a C compiler

To build a Go installation with cgo support, which permits Go programs to import C libraries, a C compiler such as gcc or clang must be installed first.

This came up as cgo is needed for the race detector:

The race detector requires cgo to be enabled, and on non-Darwin systems requires an installed C compiler.

I find that this doesn't work with tcc in Alpine (in Docker); when I run the all.bash script, the following error is produced.

# runtime/cgo
tcc: error: invalid option -- '-Qunused-arguments'
go tool dist: FAILED: /usr/local/src/go/pkg/tool/linux_amd64/go_bootstrap install std: exit status 1

The same applies when building everything with gcc and then subsequently running (say)

CC=tcc CGO_ENABLED=1 go build -race .

in a directory containing a Go package.

My question, then: are gcc and clang the only supported C compilers? (Separately: does anyone know why cgo is needed for the race detector?)


To reproduce this (as of commit a535055):

# This is alpine:edge on linux/amd64 as of the time of writing.
docker container run -it alpine@sha256:880fafbab5a7602db21ac37f0d17088a29a9a48f98d581f01ce17312c22ccbb5 sh

echo https://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories
apk --no-cache add bash go git git-daemon musl-dev tcc
export CC=tcc
mkdir /usr/local/src
git clone --depth 1 https://go.googlesource.com/go /usr/local/src/go
cd /usr/local/src/go/src
./all.bash

I'm aware that, in this single-stage example, installing go via apk pulls in gcc. I'm aware that everything would go away if I could do with gcc or do without cgo. This is purely illustrative.

What did you expect to see?

No errors.

What did you see instead?

Errors.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label May 5, 2023
@seankhliao
Copy link
Member

https://www.reddit.com/r/golang/comments/q0yfdg/comment/hfc8px1/

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale May 5, 2023
@adamroyjones
Copy link
Author

Thanks for the reference. I'm sorry for wasting your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

3 participants