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/link: unusable flag -D #28921

Closed
Helflym opened this issue Nov 22, 2018 · 5 comments
Closed

cmd/link: unusable flag -D #28921

Helflym opened this issue Nov 22, 2018 · 5 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@Helflym
Copy link
Contributor

Helflym commented Nov 22, 2018

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.

@odeke-em odeke-em added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Nov 22, 2018
@odeke-em
Copy link
Member

Thank you for filing this issue @Helflym!

I'll kindly page @ianlancetaylor @thanm for help with this issue.

@ianlancetaylor
Copy link
Contributor

This is an interesting case since it dates back to when the linker was added to the source repo in git revision 0cafb9e. So it's presumably from the Inferno linker.

More to the point, you're right: the linker's -D option has no effect. Since the -D option does nothing, I think we should remove it.

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 22, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.13 milestone Nov 22, 2018
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Nov 22, 2018
@ianlancetaylor ianlancetaylor added help wanted NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Nov 22, 2018
@gopherbot gopherbot removed the NeedsFix The path to resolution is known, but the work has not been done. label Nov 22, 2018
@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 22, 2018
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Nov 22, 2018
@gopherbot
Copy link

Change https://golang.org/cl/151021 mentions this issue: cmd: remove unusable linker flag -D (FlagDataAddr)

@vaibhavchellani
Copy link

I am happy to take this if its open and no one is working on it . We need to remove the -D flag right ?

@agnivade
Copy link
Contributor

As you can see from the comment above, a CL has already been posted for this. So yes, it is being already worked on.

Please do feel free to take up any other issue which doesn't have a CL yet. No need to ask for permission :)

@golang golang locked and limited conversation to collaborators Feb 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants