aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/symtab.go
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2021-10-07 16:26:29 -0400
committerCherry Mui <cherryyz@google.com>2021-10-07 22:19:51 +0000
commit6436f5c13d6a5ced6cd5f3873f83ebfae32cce36 (patch)
treeb518468e6152051f1c13f2bbc1b9d8191dd0a62e /src/runtime/symtab.go
parentb69f823ece741f21d06591657f4e0a5b17d492e3 (diff)
downloadgo-6436f5c13d6a5ced6cd5f3873f83ebfae32cce36.tar.xz
runtime: handle end PC in textAddr
As the func table contains the end marker of the text section, we sometimes need to get that address from an offset. Currently textAddr doesn't handle that address, as it is not within any text section. Instead of letting the callers not call textAddr with the end offset, just handle it more elegantly in textAddr. For #48837. Change-Id: I6e97e455f6cb66e9680a7aac6152ba6f4cda2e12 Reviewed-on: https://go-review.googlesource.com/c/go/+/354635 Trust: Cherry Mui <cherryyz@google.com> Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Diffstat (limited to 'src/runtime/symtab.go')
-rw-r--r--src/runtime/symtab.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go
index 2de518d2e6..e35d8047a1 100644
--- a/src/runtime/symtab.go
+++ b/src/runtime/symtab.go
@@ -623,9 +623,7 @@ func moduledataverify1(datap *moduledata) {
}
min := datap.textAddr(datap.ftab[0].entryoff)
- // The max PC is outside of the text section.
- // Subtract 1 to get a PC inside the text section, look it up, then add 1 back in.
- max := datap.textAddr(datap.ftab[nftab].entryoff-1) + 1
+ max := datap.textAddr(datap.ftab[nftab].entryoff)
if datap.minpc != min || datap.maxpc != max {
println("minpc=", hex(datap.minpc), "min=", hex(min), "maxpc=", hex(datap.maxpc), "max=", hex(max))
throw("minpc or maxpc invalid")
@@ -660,9 +658,10 @@ func (md *moduledata) textAddr(off32 uint32) uintptr {
off := uintptr(off32)
res := md.text + off
if len(md.textsectmap) > 1 {
- for i := range md.textsectmap {
- if off >= md.textsectmap[i].vaddr && off < md.textsectmap[i].end {
- res = md.textsectmap[i].baseaddr + off - md.textsectmap[i].vaddr
+ for i, sect := range md.textsectmap {
+ // For the last section, include the end address (etext), as it is included in the functab.
+ if off >= sect.vaddr && off < sect.end || (i == len(md.textsectmap)-1 && off == sect.end) {
+ res = sect.baseaddr + off - sect.vaddr
break
}
}