Skip to content

cmd/link: -a doesn't work with external linkmode #29807

Closed
@Helflym

Description

@Helflym

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

$ go version
go version devel +c077c74312 Fri Jan 18 03:50:05 2019 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes, with go1.10.4 linux/amd64

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-build080404221=/tmp/go-build -gno-record-gcc-switches"

What did you do?

go build -ldflags='-a -linkmode=external' helloworld.go

What did you see instead?

...
type.runtime.gclinkptr
	0045dd60| 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
	0045dd70| a8 65 c5 1a 07 08 08 8c 00 00 00 00 00 00 00 00
	0045dd80| 00 00 00 00 00 00 00 00 ff 4b 00 00 00 e8 00 00
	0045dd90| 68 10 00 00 01 00 00 00 10 00 00 00 00 00 00 00
	0045dda0| fe 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
	reloc 0045dd78/8 addr runtime.algarray+0x50 [0x4bff30]
	reloc 0045dd80/8 addr runtime.gcbits.+0x0 [0x47b598]
	reloc 0045dd88/4 ? type..namedata.*runtime.gclinkptr-+0x0 [0x4546df]
	reloc 0045dd8c/4 ? type.*runtime.gclinkptr+0x0 [0x45e2e0]
	reloc 0045dd90/4 ? type..importpath.runtime.+0x0 [0x450b48]
	reloc 0045dda0/4 ? type..namedata.ptr-+0x0 [0x44fcde]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x54a9ef]

goroutine 1 [running]:
cmd/link/internal/ld.Datblk(0xc0006be000, 0x45ddb0, 0x2eb27)
	/home/chigotc/go/goroot/src/cmd/link/internal/ld/data.go:839 +0x5ff
cmd/link/internal/amd64.asmb(0xc0006be000)
	/home/chigotc/go/goroot/src/cmd/link/internal/amd64/asm.go:678 +0x196
cmd/link/internal/ld.Main(0x82ad20, 0x10, 0x20, 0x1, 0x7, 0x10, 0x67739a, 0x1b, 0x673f73, 0x14, ...)
	/home/chigotc/go/goroot/src/cmd/link/internal/ld/main.go:244 +0xd36
main.main()
	/home/chigotc/go/goroot/src/cmd/link/main.go:65 +0x1d0

This error comes from data.go where r.Sym.Value should use the same way r.Sym.Name is done.

However, while doing it locally, I've found that these relocations are quite unusual:

type.runtime.gclinkptr
        0045dd60| 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        0045dd70| a8 65 c5 1a 07 08 08 8c 00 00 00 00 00 00 00 00
        0045dd80| 00 00 00 00 00 00 00 00 ff 4b 00 00 00 e8 00 00
        0045dd90| 68 10 00 00 01 00 00 00 10 00 00 00 00 00 00 00
        0045dda0| fe 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        reloc 0045dd78/8 addr runtime.algarray+0x50 [0x4bff30]
        reloc 0045dd80/8 addr runtime.gcbits.+0x0 [0x47b598]
        reloc 0045dd88/4 ? type..namedata.*runtime.gclinkptr-+0x0 [0x4546df]
        reloc 0045dd8c/4 ? type.*runtime.gclinkptr+0x0 [0x45e2e0]
        reloc 0045dd90/4 ? type..importpath.runtime.+0x0 [0x450b48]
        reloc 0045dda0/4 ? type..namedata.ptr-+0x0 [0x44fcde]
        reloc 0045dda4/0 ? +0x0 [-0x1]
        reloc 0045dda8/0 ? +0x0 [-0x1]
        reloc 0045ddac/0 ? +0x0 [-0x1]
        0045ddb0| 00 ...

Does anyone know why these relocations are generated in a first instance ? I didn't manage to find where they come from.

Activity

added this to the Unplanned milestone on Jan 18, 2019
ianlancetaylor

ianlancetaylor commented on Jan 18, 2019

@ianlancetaylor
Contributor

That looks like a type descriptor. The relocs are being generated by dcommontype in cmd/compile/internal/gc/reflect.go.

gopherbot

gopherbot commented on Jan 23, 2019

@gopherbot
Contributor

Change https://golang.org/cl/158998 mentions this issue: cmd/link: fix -a with external linker

locked and limited conversation to collaborators on Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ianlancetaylor@gopherbot@Helflym

        Issue actions

          cmd/link: -a doesn't work with external linkmode · Issue #29807 · golang/go