tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Fixing Elf##_Versym



Hello tech-toolchain,

Many ELF toolkits define an Elf##_Versym to be a 16-bit unsigned
quantity:

  /* Solaris, FreeBSD, Elfutils, Elftoolchain, maybe others. */
  typedef Elf32_Half Elf32_Versym;
  typedef Elf64_Half Elf64_Versym;

NetBSD however defines it as a struct with a sole 16-bit unsigned
member:

  /* NetBSD: <sys/exec_elf.h> */
  typedef struct {
  	Elf32_Half	vs_vers;
  } Elf32_Versym;
  typedef Elf32_Versym	Elf64_Versym;

I would like to align NetBSD's definitions with those in the
other toolkits, so that it becomes easier to port ELF-handling
code to NetBSD.

Would anyone have objections to the below patch?  Per my
understanding, the patch does not change runtime behavior.

Thanks!

Index: sys/sys/exec_elf.h
===================================================================
RCS file: /cvsroot/src/sys/sys/exec_elf.h,v
retrieving revision 1.179
diff -u -r1.179 exec_elf.h
--- sys/sys/exec_elf.h	7 Nov 2025 21:58:21 -0000	1.179
+++ sys/sys/exec_elf.h	10 Nov 2025 09:33:57 -0000
@@ -1018,10 +1018,8 @@
 } Elf32_Vernaux;
 typedef Elf32_Vernaux	Elf64_Vernaux;
 
-typedef struct {
-	Elf32_Half	vs_vers;
-} Elf32_Versym;
-typedef Elf32_Versym	Elf64_Versym;
+typedef Elf32_Half	Elf32_Versym;
+typedef Elf64_Half	Elf64_Versym;
 
 /*
  * Symbols and types that are NetBSD-specific.
Index: libexec/ld.elf_so/rtld.h
===================================================================
RCS file: /cvsroot/src/libexec/ld.elf_so/rtld.h,v
retrieving revision 1.150
diff -u -r1.150 rtld.h
--- libexec/ld.elf_so/rtld.h	2 May 2025 23:04:31 -0000	1.150
+++ libexec/ld.elf_so/rtld.h	10 Nov 2025 09:34:10 -0000
@@ -474,7 +474,7 @@
 	Elf_Half vernum;
 
 	if (obj->vertab) {
-		vernum = VER_NDX(obj->versyms[symnum].vs_vers);
+		vernum = VER_NDX(obj->versyms[symnum]);
 		if (vernum >= obj->vertabnum) {
 			_rtld_error("%s: symbol %s has wrong verneed value %d",
 			    obj->path, &obj->strtab[symnum], vernum);
Index: libexec/ld.elf_so/symbol.c
===================================================================
RCS file: /cvsroot/src/libexec/ld.elf_so/symbol.c,v
retrieving revision 1.77
diff -u -r1.77 symbol.c
--- libexec/ld.elf_so/symbol.c	2 May 2025 23:04:31 -0000	1.77
+++ libexec/ld.elf_so/symbol.c	10 Nov 2025 09:34:10 -0000
@@ -208,7 +208,7 @@
 
 	if (ventry == NULL) {
 		if (obj->versyms != NULL) {
-			verndx = VER_NDX(obj->versyms[symnum].vs_vers);
+			verndx = VER_NDX(obj->versyms[symnum]);
 			if (verndx > obj->vertabnum) {
 				_rtld_error("%s: symbol %s references "
 				    "wrong version %d", obj->path,
@@ -234,7 +234,7 @@
 				*vsymp = symp;
 				return true;
 			} else if (verndx >= VER_NDX_GIVEN) {
-				if (!(obj->versyms[symnum].vs_vers & VER_NDX_HIDDEN)) {
+				if (!(obj->versyms[symnum] & VER_NDX_HIDDEN)) {
 					if (*vsymp == NULL)
 						*vsymp = symp;
 					(*vcount)++;
@@ -254,7 +254,7 @@
 				return false;
 			}
 		} else {
-			verndx = VER_NDX(obj->versyms[symnum].vs_vers);
+			verndx = VER_NDX(obj->versyms[symnum]);
 			if (verndx > obj->vertabnum) {
 				_rtld_error("%s: symbol %s references "
 				    "wrong version %d", obj->path,
@@ -274,7 +274,7 @@
 				* dlvsym wants.
 				*/
 				if ((flags & SYMLOOK_DLSYM) ||
-				    (obj->versyms[symnum].vs_vers & VER_NDX_HIDDEN) ||
+				    (obj->versyms[symnum] & VER_NDX_HIDDEN) ||
 				    (verndx >= VER_NDX_GIVEN))
 					return false;
 			}

-- 
Joseph Koshy | jkoshy%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index