Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Jul 2025 20:16:49 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 12bef37a824c - main - dtrace: fix symbol address resolution
Message-ID:  <202507072016.567KGnfd006510@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=12bef37a824c52582ee8f38699b8ae4fde17068d

commit 12bef37a824c52582ee8f38699b8ae4fde17068d
Author:     Jiacong Fang <zldrobit@gmail.com>
AuthorDate: 2025-07-07 18:51:51 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-07-07 20:16:31 +0000

    dtrace: fix symbol address resolution
    
    Dtrace assumes only ELF sections of type SHT_PROGBITS or SHT_NOBITS
    occupy memory space. However, sections with SHF_ALLOC flag also consume
    memory space. Moreover, the symbol address initialization skips symbols
    at the very beginning of a section in ET_REL KLDs.
    
    Fix: Check section flag for calculating section offset, and disable the
    skipping at the beginning of a section.
    
    PR:             288000
    Reviewed by:    markj
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D51188
---
 cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c
index 2a0386c33124..f6a328bb9b39 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c
@@ -109,8 +109,7 @@ dt_module_syminit32(dt_module_t *dmp)
 		if (sym->st_name == 0 || sym->st_name >= ss_size)
 			continue; /* skip null or invalid names */
 
-		if (sym->st_value != 0 &&
-		    (ELF32_ST_BIND(sym->st_info) != STB_LOCAL || sym->st_size)) {
+		if (ELF32_ST_BIND(sym->st_info) != STB_LOCAL || sym->st_size) {
 			asrsv++; /* reserve space in the address map */
 
 #if defined(__FreeBSD__)
@@ -159,8 +158,7 @@ dt_module_syminit64(dt_module_t *dmp)
 		if (sym->st_name == 0 || sym->st_name >= ss_size)
 			continue; /* skip null or invalid names */
 
-		if (sym->st_value != 0 &&
-		    (ELF64_ST_BIND(sym->st_info) != STB_LOCAL || sym->st_size)) {
+		if (ELF64_ST_BIND(sym->st_info) != STB_LOCAL || sym->st_size) {
 			asrsv++; /* reserve space in the address map */
 #if defined(__FreeBSD__)
 			sym->st_value += (Elf_Addr) dmp->dm_reloc_offset;
@@ -245,8 +243,7 @@ dt_module_symsort32(dt_module_t *dmp)
 
 	for (i = 1; i < n; i++, dsp++) {
 		Elf32_Sym *sym = symtab + dsp->ds_symid;
-		if (sym->st_value != 0 &&
-		    (ELF32_ST_BIND(sym->st_info) != STB_LOCAL || sym->st_size))
+		if (ELF32_ST_BIND(sym->st_info) != STB_LOCAL || sym->st_size)
 			*sympp++ = sym;
 	}
 
@@ -269,8 +266,7 @@ dt_module_symsort64(dt_module_t *dmp)
 
 	for (i = 1; i < n; i++, dsp++) {
 		Elf64_Sym *sym = symtab + dsp->ds_symid;
-		if (sym->st_value != 0 &&
-		    (ELF64_ST_BIND(sym->st_info) != STB_LOCAL || sym->st_size))
+		if (ELF64_ST_BIND(sym->st_info) != STB_LOCAL || sym->st_size)
 			*sympp++ = sym;
 	}
 
@@ -1218,7 +1214,7 @@ dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat)
 			continue; /* skip any malformed sections */
 		if (sh.sh_size == 0)
 			continue;
-		if (sh.sh_type == SHT_PROGBITS || sh.sh_type == SHT_NOBITS) {
+		if (sh.sh_flags & SHF_ALLOC) {
 			alignmask = sh.sh_addralign - 1;
 			mapbase += alignmask;
 			mapbase &= ~alignmask;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202507072016.567KGnfd006510>