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

cmd/cgo: building with clang 13 errors out with unknown warning group '-Wunaligned-access' #64943

Closed
bjackman opened this issue Jan 3, 2024 · 8 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bjackman
Copy link

bjackman commented Jan 3, 2024

Go version

go version go1.22-20230908-RC04 cl/563875016 +2fe2f08542 X:fieldtrack,boringcrypto linux/amd64

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

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/usr/local/google/home/jackmanb/.cache/go-build'
GOENV='/usr/local/google/home/jackmanb/.config/go/env'
GOEXE=''
GOEXPERIMENT='fieldtrack,boringcrypto'
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/usr/local/google/home/jackmanb/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/usr/local/google/home/jackmanb/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/google-golang'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/google-golang/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22-20230908-RC04 cl/563875016 +2fe2f08542 X:fieldtrack,boringcrypto'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2390478846=/tmp/go-build -gno-record-gcc-switches'

What did you do?

mkdir /tmp/go-rand
cd /tmp/go-rand
cat > tst.go << EOF
package main

import (
        "crypto/rand"
)

func main() {
        var r rand.Reader
}
EOF
go build tst.go

What did you expect to see?

Successful build

What did you see instead?

_cgo_export.c:9:32: error: unknown warning group '-Wunaligned-access', ignored [-Werror,-Wunknown-warning-option]

Exit code 1.

In case it's not obvious - I'm a Googler and this is gLinux. I'm reporting via Github per the internal instructions. Apologies if I've misunderstood there!

@bjackman
Copy link
Author

bjackman commented Jan 3, 2024

See also #62580 which has the same error message. But the CL of my version is way out of that range that Ian mentioned in the final comment.

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. compiler/runtime Issues related to the Go compiler and/or runtime. labels Jan 3, 2024
@bcmills
Copy link
Contributor

bcmills commented Jan 3, 2024

The CL mentioned in #62580 was reapplied in https://go.dev/cl/528935 with an additional -Wunknown-warning-option pragma. Perhaps the version of Clang you're using also doesn't support -Wunknown-warning-option, or doesn't handle that pragma in the same way?

(What does clang --version report for you?)

@bjackman
Copy link
Author

bjackman commented Jan 3, 2024

$ clang --version
clang version 13.0.0 (https://github.com/llvm/llvm-project.git 28ab7ff2d732fb0580486baa02b1383a72cec0cb)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

Sounds like a good explanation

@bjackman
Copy link
Author

bjackman commented Jan 4, 2024

Not sure if this was already obvious but just to confirm, this is not actually specific to package crypto/rand - I get the same thing whenever I import "C" myself too.

@bjackman bjackman changed the title crypto/rand: unknown warning group '-Wunaligned-access', ignored [-Werror,-Wunknown-warning-option] cgo with older Clang: unknown warning group '-Wunaligned-access', ignored [-Werror,-Wunknown-warning-option] Jan 4, 2024
@bjackman
Copy link
Author

bjackman commented Jan 4, 2024

Workaround: Get a newer Clang and set the CC environment variable to the clang binary path. Googlers can try go/crosstool-outside-google3#wrapper-scripts.

For anyone else here are some commands I have previously used to successfully build/install Clang from master on a Debian-alike system:

sudo apt install -y cmake && \
git clone https://github.com/llvm/llvm-project.git  && cd llvm-project && \
mkdir build && \
cd build && \
cmake -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../llvm && \
make -j $(nproc) && \
sudo make install

@bjackman
Copy link
Author

bjackman commented Jan 8, 2024

Was wondering why this isn't affecting more people - suddenly noticed the InstalledDir: /usr/local/bin in #64943 (comment). Apparently at some point I did a system-wide installation of Clang from source (probably when I ran those commands in #64943 (comment)!). So my combination of Clang and Go versions is weird and unusual. So probably this can be deprioritised or maybe it's even WAI.

@bcmills bcmills changed the title cgo with older Clang: unknown warning group '-Wunaligned-access', ignored [-Werror,-Wunknown-warning-option] cmd/cgo: building with clang 13 errors out with unknown warning group '-Wunaligned-access' Jan 9, 2024
@mknyszek mknyszek added this to the Backlog milestone Jan 10, 2024
@mknyszek
Copy link
Contributor

@bjackman Given that this seems to possibly related to your particular version of Clang, I'm going to optimistically close this for now. If you run into any problems with a more stable (?) version of Clang, feel free to comment. Thanks.

@mknyszek mknyszek closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2024
@bjackman
Copy link
Author

Just to be clear I don't think this is a case of Clang instability, I think this is probably a genuine incompatibility between Go version 1.22 and Clang version 13.0.0.

However I think it's likely nobody else will ever have that combination of versions so optimistically closing still makes sense.

bjackman added a commit to google/page-alloc-bench that referenced this issue Feb 9, 2024
The custom generator was a workaround for
golang/go#64943.
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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants