From 5aa9b11b613f85cde959ec3b9ba4be0128cb48c3 Mon Sep 17 00:00:00 2001
From: Mark Johnston <markj@FreeBSD.org>
Date: Sat, 21 Jul 2018 22:15:48 +0000
Subject: [PATCH] Take the mapping's segment offset into account when resolving
 symbols.

Reported by:	Jenkins, via asomers
MFC after:	2 weeks
---
 lib/libproc/proc_sym.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/libproc/proc_sym.c b/lib/libproc/proc_sym.c
index 953942544949..5901379b1582 100644
--- a/lib/libproc/proc_sym.c
+++ b/lib/libproc/proc_sym.c
@@ -520,7 +520,8 @@ proc_addr2sym(struct proc_handle *p, uintptr_t addr, char *name,
 	}
 
 	file = mapping->file;
-	off = file->ehdr.e_type == ET_DYN ? mapping->map.pr_vaddr : 0;
+	off = file->ehdr.e_type == ET_DYN ?
+	    mapping->map.pr_vaddr - mapping->map.pr_offset : 0;
 	if (addr < off)
 		return (ENOENT);
 	addr -= off;
@@ -623,7 +624,8 @@ proc_name2sym(struct proc_handle *p, const char *object, const char *symbol,
 	}
 
 	file = mapping->file;
-	off = file->ehdr.e_type == ET_DYN ? mapping->map.pr_vaddr : 0;
+	off = file->ehdr.e_type == ET_DYN ?
+	    mapping->map.pr_vaddr - mapping->map.pr_offset : 0;
 
 	error = lookup_symbol_by_name(file->elf, &file->dynsymtab, symbol,
 	    symcopy, si);