aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2021-10-05 11:26:25 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2021-10-06 19:54:45 +0000
commit058fa255bcbe414011f5b9f469f44ec64a168224 (patch)
treec024b60a5f969bd5e8569156411246a3166054a5 /src/cmd/link
parentb5cdb1b71c2198c6c5e209e77ce3801087a21d62 (diff)
downloadgo-058fa255bcbe414011f5b9f469f44ec64a168224.tar.gz
go-058fa255bcbe414011f5b9f469f44ec64a168224.zip
cmd/link,runtime: make textsectmap fields more convenient for runtime
They're only used in a single place. Instead of calculating the end every time, calculate it in the linker. It'd be nice to recalculate baseaddr-vaddr, but that generates relocations that are too large. While we're here, remove some pointless uintptr -> uintptr conversions. Change-Id: I91758f9bff11b365bc3a63fee172dbdc3d90b966 Reviewed-on: https://go-review.googlesource.com/c/go/+/354089 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/link')
-rw-r--r--src/cmd/link/internal/ld/symtab.go29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go
index 8eca250131..4be2634f44 100644
--- a/src/cmd/link/internal/ld/symtab.go
+++ b/src/cmd/link/internal/ld/symtab.go
@@ -406,22 +406,21 @@ func textsectionmap(ctxt *Link) (loader.Sym, uint32) {
if sect.Name != ".text" {
break
}
- off = t.SetUint(ctxt.Arch, off, sect.Vaddr-textbase)
- off = t.SetUint(ctxt.Arch, off, sect.Length)
- if n == 0 {
- s := ldr.Lookup("runtime.text", 0)
- if s == 0 {
- ctxt.Errorf(s, "Unable to find symbol runtime.text\n")
- }
- off = t.SetAddr(ctxt.Arch, off, s)
-
- } else {
- s := ldr.Lookup(fmt.Sprintf("runtime.text.%d", n), 0)
- if s == 0 {
- ctxt.Errorf(s, "Unable to find symbol runtime.text.%d\n", n)
- }
- off = t.SetAddr(ctxt.Arch, off, s)
+ // The fields written should match runtime/symtab.go:textsect.
+ // They are designed to minimize runtime calculations.
+ vaddr := sect.Vaddr - textbase
+ off = t.SetUint(ctxt.Arch, off, vaddr) // field vaddr
+ end := vaddr + sect.Length
+ off = t.SetUint(ctxt.Arch, off, end) // field end
+ name := "runtime.text"
+ if n != 0 {
+ name = fmt.Sprintf("runtime.text.%d", n)
+ }
+ s := ldr.Lookup(name, 0)
+ if s == 0 {
+ ctxt.Errorf(s, "Unable to find symbol %s\n", name)
}
+ off = t.SetAddr(ctxt.Arch, off, s) // field baseaddr
n++
}
return t.Sym(), uint32(n)