]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link, cmd/internal/obj: fix a remote call failure issue
authorlimeidan <limeidan@loongson.cn>
Mon, 24 Nov 2025 09:28:42 +0000 (17:28 +0800)
committerabner chenc <chenguoqi@loongson.cn>
Thu, 27 Nov 2025 02:59:35 +0000 (18:59 -0800)
When a function call exceeds the immediate value range of the instruction,
a trampoline is required to assist in the jump. Trampoline is only omitted
when plt is needed; otherwise, a check is required.

Change-Id: I7fe2e08d75f6f574475837b560e650bbd4215858
Reviewed-on: https://go-review.googlesource.com/c/go/+/724580
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/cmd/internal/obj/loong64/asm.go
src/cmd/link/internal/loong64/asm.go

index 3fcd6eafd7c21014d8599c0cbb48e46dc2b2323d..f9925180153aeabcc78e2d2aac8b0523c1ed4605 100644 (file)
@@ -2437,6 +2437,9 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
                v := int32(0)
                if p.To.Target() != nil {
                        v = int32(p.To.Target().Pc-p.Pc) >> 2
+                       if v < -1<<25 || v >= 1<<25 {
+                               c.ctxt.Diag("branch too far \n%v", p)
+                       }
                }
                o1 = OP_B_BL(c.opirr(p.As), uint32(v))
                if p.To.Sym != nil {
index 219cfc7196a5485d8727df84a3c5d90999b8b005..142578bcebfb1f8dc632225055f2a89e0df37c80 100644 (file)
@@ -643,11 +643,14 @@ func trampoline(ctxt *ld.Link, ldr *loader.Loader, ri int, rs, s loader.Sym) {
        relocs := ldr.Relocs(s)
        r := relocs.At(ri)
        switch r.Type() {
-       case objabi.ElfRelocOffset + objabi.RelocType(elf.R_LARCH_B26):
-               // Nothing to do.
-               // The plt symbol has not been added. If we add tramp
-               // here, plt will not work.
-       case objabi.R_CALLLOONG64:
+       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