nlsit(3) fix for non-global variables

Mark Kettenis <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
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)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.