[go] cmd/link: modify the register used in trampoline

2 views
Skip to first unread message

Meidan Li (Gerrit)

unread,
Dec 2, 2025, 9:27:06 PM (6 hours ago) Dec 2
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Meidan Li has uploaded the change for review

Commit message

cmd/link: modify the register used in trampoline
Change-Id: Ie7bba0caa30a764a45bcb47635c35c829036c5a2

Change diff

diff --git a/src/cmd/internal/obj/loong64/doc.go b/src/cmd/internal/obj/loong64/doc.go
index 19c9e05..80ded5f 100644
--- a/src/cmd/internal/obj/loong64/doc.go
+++ b/src/cmd/internal/obj/loong64/doc.go
@@ -6,6 +6,18 @@
Package loong64 implements an LoongArch64 assembler. Go assembly syntax is different from
GNU LoongArch64 syntax, but we can still follow the general rules to map between them.

+# Register Convention
+
+ Name | Alias | Meaning
+ -------------------------------------------------------------------------------------------------------------------
+ R0 | REGZERO | Constant zero
+ R1 | REGLINK | Return address
+ R3 | REGSP | Stack pointer
+ R12,R13,R14,R15 | | For plt and trampoline, use with caution in assembly code, save before calling function
+ R22 | REGG | Goroutine pointer
+ R29 | REGCTXT | Context for closures
+ R30 | REGTMP | Tmp register used by assembler
+
# Instructions mnemonics mapping rules

1. Bit widths represented by various instruction suffixes and prefixes
diff --git a/src/cmd/link/internal/loong64/asm.go b/src/cmd/link/internal/loong64/asm.go
index dfcf928..a87a93e 100644
--- a/src/cmd/link/internal/loong64/asm.go
+++ b/src/cmd/link/internal/loong64/asm.go
@@ -645,13 +645,6 @@
r := relocs.At(ri)
switch r.Type() {
case objabi.ElfRelocOffset + objabi.RelocType(elf.R_LARCH_B26), objabi.R_CALLLOONG64:
- if ldr.SymType(rs) == sym.SDYNIMPORT {
- // Nothing to do.
- // The plt symbol has not been added. If we add tramp
- // here, plt will not work.
- return
- }
-
var t int64
// ldr.SymValue(rs) == 0 indicates a cross-package jump to a function that is not yet
// laid out. Conservatively use a trampoline. This should be rare, as we lay out packages
@@ -720,7 +713,7 @@
tramp.SetSize(12) // 3 instructions
P := make([]byte, tramp.Size())

- o1 := uint32(0x1a00001e) // pcalau12i $r30, 0
+ o1 := uint32(0x1a00000f) // pcalau12i $r15, 0
ctxt.Arch.ByteOrder.PutUint32(P, o1)
r1, _ := tramp.AddRel(objabi.R_LOONG64_ADDR_HI)
r1.SetOff(0)
@@ -728,7 +721,7 @@
r1.SetSym(target)
r1.SetAdd(offset)

- o2 := uint32(0x02c003de) // addi.d $r30, $r30, 0
+ o2 := uint32(0x02c001ef) // addi.d $r15, $r15, 0
ctxt.Arch.ByteOrder.PutUint32(P[4:], o2)
r2, _ := tramp.AddRel(objabi.R_LOONG64_ADDR_LO)
r2.SetOff(4)
@@ -736,7 +729,7 @@
r2.SetSym(target)
r2.SetAdd(offset)

- o3 := uint32(0x4c0003c0) // jirl $r0, $r30, 0
+ o3 := uint32(0x4c0001e0) // jirl $r0, $r15, 0
ctxt.Arch.ByteOrder.PutUint32(P[8:], o3)

tramp.SetData(P)
@@ -746,21 +739,21 @@
tramp.SetSize(12) // 3 instructions
P := make([]byte, tramp.Size())

- o1 := uint32(0x1a00001e) // pcalau12i $r30, 0
+ o1 := uint32(0x1a00000f) // pcalau12i $r15, 0
ctxt.Arch.ByteOrder.PutUint32(P, o1)
r1, _ := tramp.AddRel(objabi.R_LOONG64_GOT_HI)
r1.SetOff(0)
r1.SetSiz(4)
r1.SetSym(target)

- o2 := uint32(0x28c003de) // ld.d $r30, $r30, 0
+ o2 := uint32(0x28c001ef) // ld.d $r15, $r15, 0
ctxt.Arch.ByteOrder.PutUint32(P[4:], o2)
r2, _ := tramp.AddRel(objabi.R_LOONG64_GOT_LO)
r2.SetOff(4)
r2.SetSiz(4)
r2.SetSym(target)

- o3 := uint32(0x4c0003c0) // jirl $r0, $r30, 0
+ o3 := uint32(0x4c0001e0) // jirl $r0, $r15, 0
ctxt.Arch.ByteOrder.PutUint32(P[8:], o3)

tramp.SetData(P)

Change information

Files:
  • M src/cmd/internal/obj/loong64/doc.go
  • M src/cmd/link/internal/loong64/asm.go
Change size: S
Delta: 2 files changed, 18 insertions(+), 13 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ie7bba0caa30a764a45bcb47635c35c829036c5a2
Gerrit-Change-Number: 726140
Gerrit-PatchSet: 1
Gerrit-Owner: Meidan Li <lime...@loongson.cn>
unsatisfied_requirement
satisfied_requirement
open
diffy

Meidan Li (Gerrit)

unread,
Dec 2, 2025, 10:36:14 PM (5 hours ago) Dec 2
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Cherry Mui, Ian Lance Taylor and Russ Cox

Meidan Li uploaded new patchset

Meidan Li uploaded patch set #2 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • Cherry Mui
  • Ian Lance Taylor
  • Russ Cox
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ie7bba0caa30a764a45bcb47635c35c829036c5a2
Gerrit-Change-Number: 726140
Gerrit-PatchSet: 2
Gerrit-Owner: Meidan Li <lime...@loongson.cn>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Russ Cox <r...@golang.org>
Gerrit-Attention: Cherry Mui <cher...@google.com>
Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages