Description
What version of Go are you using (go version
)?
$ go version go version devel +6d5caf38e3 Thu Nov 22 02:59:55 2018 +0000 linux/amd64
Does this issue reproduce with the latest release?
go1.10.4 => -R=0 doesn't trigger a panic, but data section isn't set at the given address.
go1.11.1 => Same as master
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/home/chigotc/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/chigotc/go/gopath" GOPROXY="" GORACE="" GOROOT="/home/chigotc/go/goroot" GOTMPDIR="" GOTOOLDIR="/home/chigotc/go/goroot/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" 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-build822417210=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I was trying to generate an ELF binary using -D flag. However, -D seems to be unusable.
If it's used alone, it's ignored because of flag -R being set by default to 0x1000.
$ go build -ldflags="-D=0x1000000" helloworld.go
# command-line-arguments
warning: -D0x1000000 is ignored because of -R0x1000
If -R is disabled with -R=0, a panic is triggered.
$ go build -ldflags="-D=0x1000000 -R=0" helloworld.go
# command-line-arguments
panic: runtime error: integer divide by zero
goroutine 1 [running]:
cmd/link/internal/ld.(*Link).layout(0xc0006c2000, 0xc001604200, 0x4, 0x4)
/home/chigotc/go/goroot/src/cmd/link/internal/ld/data.go:2197 +0x27a
cmd/link/internal/ld.Main(0x812d20, 0x10, 0x20, 0x1, 0x7, 0x10, 0x66eaf5, 0x1b, 0x66b6e8, 0x14, ...)
/home/chigotc/go/goroot/src/cmd/link/internal/ld/main.go:243 +0xcb5
main.main()
/home/chigotc/go/goroot/src/cmd/link/main.go:65 +0x1cf
Was -R flag aimed to act like "--section-alignment" flag for GNU ld ?
Sets the section alignment. Sections in memory will always begin at addresses which are a multiple of this number.
In this case, -R and -D should be able to be called together.
Otherwise, what's the aim of -R flag?
Looking at the code, data first address is always computed using *FlagRound:
https://github.com/golang/go/blob/master/src/cmd/link/internal/ld/data.go#L2039
Moreover, *FlagDataAddr is used nowhere in cmd/link.
Therefore, is -D a useless flag which aims to be dropped or should it be repaired ?
I've already made some changes to make -D working on aix/ppc64 so I can create a CL quite easily for others GOOS/GOARCH.