golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.7k stars 17.5k forks source link

cmd/link: document default flags passed to extld #24494

Open TocarIP opened 6 years ago

TocarIP commented 6 years ago

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

master

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/localdisk/itocar/gocache/"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/localdisk/itocar/gopath/"
GORACE=""
GOROOT="/localdisk/itocar/golang"
GOTMPDIR=""
GOTOOLDIR="/localdisk/itocar/golang/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build748215444=/tmp/go-build -gno-record-gcc-switches"

What did you do?

go build -ldflags="-extld=/path/to/ld.hugetlbfs -linkmode=external" foo.go I was trying to map code section to huge pages.

What did you expect to see?

Everything works.

What did you see instead?

Linker didn't recognize -m64 option.

Looks like we pass a bunch of gcc/clang specific flags to any external linker. I worked around this by passing -extld=gcc -extldflags="-B /path/to/ld.hugetlbfs", to use gcc as a linker that recognizes -m64 and calls ld.hugetlbfs without passing -m64, but this behavior was surprising to me and should be documented somewhere (in extld documentation?)

ianlancetaylor commented 6 years ago

To be honest, I would prefer to not have to document this. These options are very likely to change in the future. Documenting them would give some presumption of consistency even if we explicitly disclaim it. Since we effectively reserve the right to pass any option that is accepted by the standard linker on the platform, there is nothing useful you can gain from any documentation.

TocarIP commented 6 years ago

reserve the right to pass any option that is accepted by the standard linker on the platform

How about adding this to extld description? Something like "Linker should be option compatible with default linker"