Module Name:    src
Committed By:   rin
Date:           Mon Oct 11 14:14:40 UTC 2021

Modified Files:
        src/sys/dev: kloader.c

Log Message:
Zero clear sh_offset to indicate a section is unused.

Avoid kernel text being doubly allocated due to non-zero sh_offset for
unused sections.

None of MD codes and kern_ksyms.c use sh_type == SHT_NULL (yet?) to
determine whether a section is unused.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/kloader.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/kloader.c
diff -u src/sys/dev/kloader.c:1.29 src/sys/dev/kloader.c:1.30
--- src/sys/dev/kloader.c:1.29	Tue Jun 29 22:40:53 2021
+++ src/sys/dev/kloader.c	Mon Oct 11 14:14:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kloader.c,v 1.29 2021/06/29 22:40:53 dholland Exp $	*/
+/*	$NetBSD: kloader.c,v 1.30 2021/10/11 14:14:40 rin Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2004 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kloader.c,v 1.29 2021/06/29 22:40:53 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kloader.c,v 1.30 2021/10/11 14:14:40 rin Exp $");
 
 #include "debug_kloader.h"
 
@@ -263,9 +263,11 @@ kloader_load(void)
 			symndx = i;
 		else if (strcmp(shstrtab + sh[i].sh_name, ".strtab") == 0)
 			strndx = i;
-		else if (i != eh.e_shstrndx)
+		else if (i != eh.e_shstrndx) {
 			/* while here, mark all other sections as unused */
 			sh[i].sh_type = SHT_NULL;
+			sh[i].sh_offset = 0;
+		}
 	}
 
 	if (symndx < 0 || strndx < 0) {

Reply via email to