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: need to handle new-style LoongArch relocs #54222

Closed
xen0n opened this issue Aug 3, 2022 · 6 comments
Closed

cmd/link: need to handle new-style LoongArch relocs #54222

xen0n opened this issue Aug 3, 2022 · 6 comments
Assignees
Labels
arch-loong64 Issues solely affecting the loongson architecture. compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@xen0n
Copy link
Member

xen0n commented Aug 3, 2022

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

$ go version
go version go1.19 linux/loong64

Does this issue reproduce with the latest release?

Yes (found during packaging testing)

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

Gentoo Linux, Loongson 3A5000.

go env Output
$ go env
GO111MODULE=""
GOARCH="loong64"
GOBIN=""
GOCACHE="/home/xenon/.cache/go-build"
GOENV="/home/xenon/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="loong64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/xenon/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/xenon/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_loong64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
AR="ar"
CC="loongarch64-unknown-linux-gnu-gcc"
CXX="loongarch64-unknown-linux-gnu-g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -mabi=lp64d -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2883565165=/tmp/go-build -gno-record-gcc-switches"

What did you do?

cd $GOROOT/src/cmd/link && go test ./...

What did you expect to see?

all tests pass

What did you see instead?

--- FAIL: TestMinusRSymsWithSameName (0.34s)
    elf_test.go:166: gcc [-fPIC -mabi=lp64d -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2982345155=/tmp/go-build -gno-record-gcc-switches] -c -o /tmp/TestMinusRSymsWithSameName2770862762/001/x0.o /tmp/TestMinusRSymsWithSameName2770862762/001/x0.c
    elf_test.go:166: gcc [-fPIC -mabi=lp64d -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2982345155=/tmp/go-build -gno-record-gcc-switches] -c -o /tmp/TestMinusRSymsWithSameName2770862762/001/x1.o /tmp/TestMinusRSymsWithSameName2770862762/001/x1.c
    elf_test.go:174: gcc [-fPIC -mabi=lp64d -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2982345155=/tmp/go-build -gno-record-gcc-switches] -nostdlib -r -o /tmp/TestMinusRSymsWithSameName2770862762/001/ldr.syso [/tmp/TestMinusRSymsWithSameName2770862762/001/x0.o /tmp/TestMinusRSymsWithSameName2770862762/001/x1.o]
    elf_test.go:194: /home/xenon/src/go/bin/go build
    elf_test.go:199: # elf_test
        /tmp/go-build846848018/b001/_pkg_.a(ldr.syso): unknown relocation type 99; compiled without -fpic?
    elf_test.go:200: exit status 2
FAIL
FAIL    cmd/link        0.340s

This is because I'm using the next iteration of LoongArch GNU toolchain that includes support for the "new-style" relocs, producing relocs unknown to cmd/link/internal/loadelf.
debug/elf and several other places need syncing.

I don't plan to immediately change codegen and remove support for generating old-style relocs, since doing so will break compatibility with the binutils-{2.38,2.39} and gcc-12.1 combo that doesn't recognize the new reloc types.

This might need backporting but I fear the change is too big for a 1.19.x point release.

EDIT: toolchain versions

$ ld --version
GNU ld (Gentoo 9999 p0) 2.39.50.20220729
Copyright (C) 2022 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

$ gcc --version
gcc (Gentoo 13.0.0 p, commit 1a5882abf01ae085e999ddcf4d208105e21e1a0d) 13.0.0 20220729 (experimental)
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 3, 2022
@xen0n xen0n added the arch-loong64 Issues solely affecting the loongson architecture. label Aug 3, 2022
@xen0n xen0n self-assigned this Aug 3, 2022
@gopherbot
Copy link

Change https://go.dev/cl/420982 mentions this issue: debug/elf: add new-style LoongArch reloc types

@gopherbot
Copy link

Change https://go.dev/cl/420983 mentions this issue: cmd/link: recognize the new R_LARCH_32_PCREL type on loong64

@dmitshur dmitshur added this to the Go1.20 milestone Aug 3, 2022
gopherbot pushed a commit that referenced this issue Aug 11, 2022
LoongArch ELF psABI spec update:
loongson/LoongArch-Documentation#57

Corresponding binutils implementation:
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=6d13722a97cee3fd397e116bde3bcedbb1e220be
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9801120721c3a702ce3bd50433ef920f92a83502

For #54222

Change-Id: I51e72294205847a69c01d741a3126248f7a7e41c
Reviewed-on: https://go-review.googlesource.com/c/go/+/420982
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 15, 2022
@gopherbot
Copy link

Change https://go.dev/cl/458836 mentions this issue: [release-branch.go1.19] cmd/link: recognize the new R_LARCH_32_PCREL type on loong64

@dr2chase
Copy link
Contributor

@gopherbot please open backport issues.

@gopherbot
Copy link

Backport issue(s) opened: #57443 (for 1.18), #57444 (for 1.19).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

gopherbot pushed a commit that referenced this issue Dec 28, 2022
…type on loong64

This is a minimum backport of CL 420983 without an API change in
debug/elf.

Original CL description:

Due to the latest binutils change [1], at least for certain 32-bit
relocs in .eh_frame section, this new type of relocation record is
emitted, leading to breakage on systems with bleeding-edge toolchain
when trying to link with object(s) with such new-style relocs.

Simply treating it the same as the existing reloc types seems enough.

Updates #54222.
Fixes #57444.

[1]: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=f09482a8747b6fd4c2d59a6a64677d3a3fe1e092

Change-Id: Idd86294a11c1d13b88acbca59e537656a57d8109
Reviewed-on: https://go-review.googlesource.com/c/go/+/458836
Reviewed-by: WANG Xuerui <git@xen0n.name>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
@gopherbot
Copy link

Change https://go.dev/cl/459876 mentions this issue: dashboard: enable linux/loong64 builder on 1.19 release branches

gopherbot pushed a commit to golang/build that referenced this issue Jan 3, 2023
It made sense for the linux/loong64 builder to only test the main branch
during the port's development. Now that it's complete, update the policy
to test all supported Go versions (starting with Go 1.19, when the port
was added) instead of just tip.

This will increase the volume of work for the builder by some amount,
hopefully that's fine, it seems to have enough resources to handle it.

Updates golang/go#54222.

Change-Id: Ic774b9890fc4826e56613f360d6edd03f50e3deb
Reviewed-on: https://go-review.googlesource.com/c/build/+/459876
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
@golang golang locked and limited conversation to collaborators Dec 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-loong64 Issues solely affecting the loongson architecture. compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants