Index | Thread | Search

From:
Mark Kettenis <mark.kettenis@xs4all.nl>
Subject:
nlsit(3) fix for non-global variables
To:
tech@openbsd.org
Date:
Tue, 23 Jun 2026 17:24:12 +0200

Download raw body.

Thread
I noticed I couldn't use pstat to print the value of a static variable
in the kernel.  After some debugging I found that the nlist(3) lookup
of the variable has only the N_EXT bit set in n_type.  That makes no
sense, as N_EXT is supposed to mark global variables.  To add insult
to injury, it doesn't just set to N_EXT bit, it actually overwrites
the type.

Diff below fixes this and matches what NetBSD does.

ok?


Index: lib/libc/gen/nlist.c
===================================================================
RCS file: /cvs/src/lib/libc/gen/nlist.c,v
retrieving revision 1.72
diff -u -p -r1.72 nlist.c
--- lib/libc/gen/nlist.c	27 Dec 2022 17:10:06 -0000	1.72
+++ lib/libc/gen/nlist.c	23 Jun 2026 15:05:28 -0000
@@ -270,8 +270,8 @@ __fdnlist(int fd, struct nlist *list)
 					p->n_type = N_FN;
 					break;
 				}
-				if (ELF_ST_BIND(s->st_info) == STB_LOCAL)
-					p->n_type = N_EXT;
+				if (ELF_ST_BIND(s->st_info) != STB_LOCAL)
+					p->n_type |= N_EXT;
 				p->n_desc = 0;
 				p->n_other = 0;
 				if (--nent <= 0)