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

net: '_GNU_SOURCE' macro redefined in net package when building TinyGo on Linux #66325

Closed
awmorgan opened this issue Mar 15, 2024 · 6 comments
Closed
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@awmorgan
Copy link

Go version

go version go1.22.1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/b/.cache/go-build'
GOENV='/home/b/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/b/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/b/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/b/git/go1.22'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/b/git/go1.22/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang-17'
CXX='clang++-17'
CGO_ENABLED='1'
GOMOD='/home/b/git/tinygo/go.mod'
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-build502953574=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I built TinyGo and got a warning.

To reproduce checkout and build TinyGo

$ git log --oneline -1
6384ecac (HEAD -> dev, tag: v0.31.2, upstream/release, upstream/dev, upstream/HEAD, origin/release, origin/libc-noescape, origin/dev, libc-noescape) docs: update CHANGELOG for 0.31.2 patch release

What did you see happen?

warning is at end of output:

$ make tinygo
CGO_CPPFLAGS="-I/home/b/git/tinygo/llvm-project/llvm/include -I/home/b/git/tinygo/llvm-build/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/b/git/tinygo/llvm-build/tools/clang/include -I/home/b/git/tinygo/llvm-project/clang/include -I/home/b/git/tinygo/llvm-project/lld/include" CGO_CXXFLAGS="-std=c++17" CGO_LDFLAGS="-L/home/b/git/tinygo/llvm-build/lib -lclang -Wl,--start-group -lclangAnalysis -lclangAST -lclangASTMatchers -lclangBasic -lclangCodeGen -lclangCrossTU -lclangDriver -lclangDynamicASTMatchers -lclangEdit -lclangExtractAPI -lclangFormat -lclangFrontend -lclangFrontendTool -lclangHandleCXX -lclangHandleLLVM -lclangIndex -lclangLex -lclangParse -lclangRewrite -lclangRewriteFrontend -lclangSema -lclangSerialization -lclangSupport -lclangTooling -lclangToolingASTDiff -lclangToolingCore -lclangToolingInclusions -Wl,--end-group -lstdc++ -Wl,--start-group -llldCOFF -llldCommon -llldELF -llldMachO -llldMinGW -llldWasm -Wl,--end-group -L/home/b/git/tinygo/llvm-build/lib  -lLLVMWindowsManifest -lLLVMWindowsDriver -lLLVMMCJIT -lLLVMLTO -lLLVMPasses -lLLVMIRPrinter -lLLVMExtensions -lLLVMLibDriver -lLLVMOption -lLLVMInterpreter -lLLVMFrontendHLSL -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMOrcTargetProcess -lLLVMOrcShared -lLLVMCoverage -lLLVMCoroutines -lLLVMXtensaDisassembler -lLLVMXtensaAsmParser -lLLVMXtensaCodeGen -lLLVMXtensaDesc -lLLVMXtensaInfo -lLLVMAVRDisassembler -lLLVMAVRAsmParser -lLLVMAVRCodeGen -lLLVMAVRDesc -lLLVMAVRInfo -lLLVMWebAssemblyDisassembler -lLLVMWebAssemblyAsmParser -lLLVMWebAssemblyCodeGen -lLLVMWebAssemblyUtils -lLLVMWebAssemblyDesc -lLLVMWebAssemblyInfo -lLLVMRISCVTargetMCA -lLLVMRISCVDisassembler -lLLVMRISCVAsmParser -lLLVMRISCVCodeGen -lLLVMRISCVDesc -lLLVMRISCVInfo -lLLVMAArch64Disassembler -lLLVMAArch64AsmParser -lLLVMAArch64CodeGen -lLLVMAArch64Desc -lLLVMAArch64Utils -lLLVMAArch64Info -lLLVMARMDisassembler -lLLVMARMAsmParser -lLLVMARMCodeGen -lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMFrontendOpenMP -lLLVMARMDesc -lLLVMARMUtils -lLLVMARMInfo -lLLVMX86TargetMCA -lLLVMMCA -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMMCDisassembler -lLLVMInstrumentation -lLLVMGlobalISel -lLLVMSelectionDAG -lLLVMCFGuard -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMObjCARCOpts -lLLVMTransformUtils -lLLVMCodeGenTypes -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMSymbolize -lLLVMDebugInfoBTF -lLLVMDebugInfoPDB -lLLVMDebugInfoMSF -lLLVMDebugInfoDWARF -lLLVMObject -lLLVMTextAPI -lLLVMMCParser -lLLVMIRReader -lLLVMAsmParser -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMBitReader -lLLVMCore -lLLVMRemarks -lLLVMBitstreamReader -lLLVMBinaryFormat -lLLVMTargetParser -lLLVMSupport -lLLVMDemangle -lrt -ldl -lm -lstdc++ "  go build -buildmode exe -o build/tinygo -tags "byollvm osusergo" -ldflags="-X github.com/tinygo-org/tinygo/goenv.GitSha1=`git rev-parse --short HEAD`" .
# net
../go1.22/src/net/cgo_unix_cgo.go:10:9: warning: '_GNU_SOURCE' macro redefined [-Wmacro-redefined]
<command line>:1:9: note: previous definition is here

What did you expect to see?

Expected to see no warning from Go standard library file src/net/cgo_unix_cgo.go

@awmorgan
Copy link
Author

here's the fix:

$ git log --oneline -1
db6097f8cb (HEAD -> release-branch.go1.22, tag: go1.22.1, origin/release-branch.go1.22) [release-branch.go1.22] go1.22.1
b@anakin:~/git/go1.22 (release-branch.go1.22)*
$ git diff
diff --git a/src/net/cgo_unix_cgo.go b/src/net/cgo_unix_cgo.go
index 7c609eddbf..ac86575652 100644
--- a/src/net/cgo_unix_cgo.go
+++ b/src/net/cgo_unix_cgo.go
@@ -7,7 +7,9 @@
 package net
 
 /*
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
 
 #cgo CFLAGS: -fno-stack-protector
 #include <sys/types.h>
b@anakin:~/git/go1.22 (release-branch.go1.22)*
$ 

@gopherbot
Copy link

Change https://go.dev/cl/571875 mentions this issue: net: #define _GNU_SOURCE to 1

@cherrymui cherrymui changed the title Warning: '_GNU_SOURCE' macro redefined in net package when building TinyGo on Linux net: '_GNU_SOURCE' macro redefined in net package when building TinyGo on Linux Mar 15, 2024
@cherrymui cherrymui added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 15, 2024
@cherrymui cherrymui added this to the Backlog milestone Mar 15, 2024
@awmorgan
Copy link
Author

@ianlancetaylor thanks for fixing. I did not know #define _GNU_SOURCE 1 would work. I would have thought that would cause the same warning but no. How did you know that would work? If anything I thought command line -D_GNU_SOURCE and cgo #define _GNU_SOURCE would match but no, -D_GNU_SOURCE matches #define _GNU_SOURCE 1 smh.

@fweimer
Copy link
Contributor

fweimer commented Mar 16, 2024

@awmorgan -D_GNU_SOURCE is equivalent to -D_GNU_SOURCE=1: https://gcc.gnu.org/onlinedocs/cpp/Invocation.html#index-D

@ianlancetaylor
Copy link
Contributor

If you use the C compiler -DVAR option without an = as in -DVAR=VAL, the compiler adds an implied =1. See the description of -D at https://gcc.gnu.org/onlinedocs/gcc-13.2.0/cpp/Invocation.html.

@awmorgan
Copy link
Author

@fweimer @ianlancetaylor thanks!

awmorgan pushed a commit to awmorgan/go that referenced this issue Mar 17, 2024
Makes the build work with CGO_CPPFLAGS=-D_GNU_SOURCE,
as reportedly used by TinyGo.

Fixes golang#66325

Change-Id: I794f1cd89814638fdb6c3066d13bbd7da88c9d93
Reviewed-on: https://go-review.googlesource.com/c/go/+/571875
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Commit-Queue: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
awmorgan pushed a commit to awmorgan/go that referenced this issue Mar 21, 2024
Makes the build work with CGO_CPPFLAGS=-D_GNU_SOURCE,
as reportedly used by TinyGo.

Fixes golang#66325

Change-Id: I794f1cd89814638fdb6c3066d13bbd7da88c9d93
Reviewed-on: https://go-review.googlesource.com/c/go/+/571875
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Commit-Queue: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants