]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist, cmd/link, internal, runtime: implement buildmode=plugin for linux/loong64
authorWANG Xuerui <git@xen0n.name>
Tue, 13 Dec 2022 08:30:45 +0000 (16:30 +0800)
committerDavid Chase <drchase@google.com>
Tue, 21 Nov 2023 18:56:21 +0000 (18:56 +0000)
According to review, buildmode=shared has unfixed shortcomings and
should be considered legacy at this time. So only buildmode=plugin is
going to be added for loong64 which is a relatively new platform.

Change-Id: Iac0b9f57e4ee01755458e180bb24d1b2a146fdf0
Reviewed-on: https://go-review.googlesource.com/c/go/+/480878
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: WANG Xuerui <git@xen0n.name>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Reviewed-by: Meidan Li <limeidan@loongson.cn>
src/cmd/dist/test.go
src/cmd/link/internal/loong64/asm.go
src/internal/platform/supported.go
src/runtime/asm_loong64.s

index 9635c4fb616ecfd9ab48f8a82909a31bfedeb738..4450129e087a1be8bdf51ecae9a3bcd729379da9 100644 (file)
@@ -1627,7 +1627,7 @@ func buildModeSupported(compiler, buildmode, goos, goarch string) bool {
 
        case "plugin":
                switch platform {
-               case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
+               case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/loong64", "linux/s390x", "linux/ppc64le",
                        "android/amd64", "android/386",
                        "darwin/amd64", "darwin/arm64",
                        "freebsd/amd64":
index fc7bad90398ff42a11d7fa271ae046481d5ce289..6607e5dc6474f14b437525bd63f31e8588b1e0d5 100644 (file)
@@ -14,7 +14,47 @@ import (
        "log"
 )
 
-func gentext(ctxt *ld.Link, ldr *loader.Loader) {}
+func gentext(ctxt *ld.Link, ldr *loader.Loader) {
+       initfunc, addmoduledata := ld.PrepareAddmoduledata(ctxt)
+       if initfunc == nil {
+               return
+       }
+
+       o := func(op uint32) {
+               initfunc.AddUint32(ctxt.Arch, op)
+       }
+
+       // Emit the following function:
+       //
+       //      local.dso_init:
+       //              la.pcrel $a0, local.moduledata
+       //              b runtime.addmoduledata
+
+       //      0000000000000000 <local.dso_init>:
+       //      0:      1a000004        pcalau12i       $a0, 0
+       //                              0: R_LARCH_PCALA_HI20   local.moduledata
+       o(0x1a000004)
+       rel, _ := initfunc.AddRel(objabi.R_ADDRLOONG64U)
+       rel.SetOff(0)
+       rel.SetSiz(4)
+       rel.SetSym(ctxt.Moduledata)
+
+       //      4:      02c00084        addi.d  $a0, $a0, 0
+       //                              4: R_LARCH_PCALA_LO12   local.moduledata
+       o(0x02c00084)
+       rel2, _ := initfunc.AddRel(objabi.R_ADDRLOONG64)
+       rel2.SetOff(4)
+       rel2.SetSiz(4)
+       rel2.SetSym(ctxt.Moduledata)
+
+       //      8:      50000000        b       0
+       //                              8: R_LARCH_B26  runtime.addmoduledata
+       o(0x50000000)
+       rel3, _ := initfunc.AddRel(objabi.R_CALLLOONG64)
+       rel3.SetOff(8)
+       rel3.SetSiz(4)
+       rel3.SetSym(addmoduledata)
+}
 
 func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loader.Sym, r loader.Reloc, rIdx int) bool {
        log.Fatalf("adddynrel not implemented")
index 4589903550c29526299d16285a5a1a60edfe7b48..82c66e21952a741a15fd4f37f1f5ce7a92c67124 100644 (file)
@@ -206,7 +206,7 @@ func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
 
        case "plugin":
                switch platform {
-               case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
+               case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/loong64", "linux/s390x", "linux/ppc64le",
                        "android/amd64", "android/386",
                        "darwin/amd64", "darwin/arm64",
                        "freebsd/amd64":
index 93550b93423c4d6fbf9121bb502eba485d8a6b8a..8a1eae3740c668b292f85321885bcaef39052e13 100644 (file)
@@ -642,6 +642,17 @@ TEXT runtime·goexit(SB),NOSPLIT|NOFRAME|TOPFRAME,$0-0
        // traceback from goexit1 must hit code range of goexit
        NOOP
 
+// This is called from .init_array and follows the platform, not Go, ABI.
+TEXT runtime·addmoduledata(SB),NOSPLIT,$0-0
+       ADDV    $-0x10, R3
+       MOVV    R30, 8(R3) // The access to global variables below implicitly uses R30, which is callee-save
+       MOVV    runtime·lastmoduledatap(SB), R12
+       MOVV    R4, moduledata_next(R12)
+       MOVV    R4, runtime·lastmoduledatap(SB)
+       MOVV    8(R3), R30
+       ADDV    $0x10, R3
+       RET
+
 TEXT ·checkASM(SB),NOSPLIT,$0-1
        MOVW    $1, R19
        MOVB    R19, ret+0(FP)