NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
kern/59984: Cleanups for ELF note alignment, POSIX macro sync and obsolete XXX comments
>Number: 59984
>Category: kern
>Synopsis: Cleanups for ELF note alignment, POSIX macro sync and obsolete XXX comments
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: kern-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sun Feb 08 16:40:00 +0000 2026
>Originator: João Bonifácio
>Release: NetBSD 11.99.5 (current)
>Organization:
>Environment:
Cross-compiling on Linux (Fedora) for NetBSD/amd64
>Description:
This patch set contains three small but important cleanups for the kernel core:
1. In sys/kern/core_elf32.c: Replaces a hardcoded '4' with sizeof(Elf_Word) for ELF note alignment, following an existing XXX suggestion.
2. In sys/sys/unistd.h: Synchronizes _POSIX_SEMAPHORES version from 0 to 200112L to reflect actual kernel support.
3. In sys/kern/init_sysctl.c: Updates the posix_semaphores sysctl to use the macro and removes several obsolete "XXX _POSIX_VERSION" comments where the macros are already correctly defined as 200112L.
>How-To-Repeat:
Code inspection reveals hardcoded magic numbers (ELF notes) and discrepancies between POSIX support macros in unistd.h and the values reported via sysctl.
>Fix:
The attached patches resolve these issues by using proper type sizes, synchronizing header macros with sysctl values, and removing outdated debt comments.
Patch 1: kern: use sizeof(Elf_Word) for ELF note alignment
>From 37bbb60c631f7dc6426067830bb8bc4dca8e82a0 Mon Sep 17 00:00:00 2001
From: Joao Bonifacio <joaoboni017%gmail.com@localhost>
Date: Sun, 8 Feb 2026 10:32:31 -0300
Subject: [PATCH 1/3] kern: use sizeof(Elf_Word) for ELF note alignment
In core_elf32.c, ELFROUNDSIZE was hardcoded to 4 with a XXX comment questioning if it should use sizeof(Elf_Word). By replacing the literal 4 with sizeof(Elf_Word), we ensure the code follows the ELF specification, maintains binary compatibility, and works correctly for both 32-bit and 64-bit architectures. Verified with a full kernel build (GENERIC) for amd64.
Signed-off-by: Joao Bonifacio <joaoboni017%gmail.com@localhost>
---
sys/kern/core_elf32.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sys/kern/core_elf32.c b/sys/kern/core_elf32.c
index f2fbabfb6..af13c2fd1 100644
--- a/sys/kern/core_elf32.c
+++ b/sys/kern/core_elf32.c
@@ -100,8 +100,8 @@ static int ELFNAMEEND(coredump_getseghdrs)(struct uvm_coredump_state *);
static int ELFNAMEEND(coredump_notes)(struct lwp *, struct note_state *);
static int ELFNAMEEND(coredump_note)(struct lwp *, struct note_state *);
-/* The 'note' section names and data are always 4-byte aligned. */
-#define ELFROUNDSIZE 4 /* XXX Should it be sizeof(Elf_Word)? */
+/* The 'note' section names and data are aligned to the ELF word size. */
+#define ELFROUNDSIZE sizeof(Elf_Word)
#define elf_read_lwpstatus CONCAT(process_read_lwpstatus, ELFSIZE)
#define elf_lwpstatus CONCAT(process_lwpstatus, ELFSIZE)
--
2.53.0
Patch 2: kern: sync _POSIX_SEMAPHORES with the system standard
>From eac5b536595ef9e8ecbf6c0fef770b0585877d05 Mon Sep 17 00:00:00 2001
From: Joao Bonifacio <joaoboni017%gmail.com@localhost>
Date: Sun, 8 Feb 2026 12:41:41 -0300
Subject: [PATCH 2/3] kern: sync _POSIX_SEMAPHORES with the system standard
Update _POSIX_SEMAPHORES in unistd.h from 0 to 200112L to reflect actual support.
In init_sysctl.c, replace the hardcoded magic number 200112 with the
_POSIX_SEMAPHORES macro and add the XXX comment for consistency
with other POSIX nodes.
Signed-off-by: Joao Bonifacio <joaoboni017%gmail.com@localhost>
---
sys/kern/init_sysctl.c | 2 +-
sys/sys/unistd.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/sys/kern/init_sysctl.c b/sys/kern/init_sysctl.c
index 7171c5cd8..deca12129 100644
--- a/sys/kern/init_sysctl.c
+++ b/sys/kern/init_sysctl.c
@@ -452,7 +452,7 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
"Semaphores option to which the system "
"attempts to conform"), NULL,
- 200112, NULL, 0,
+ _POSIX_SEMAPHORES, NULL, 0,
CTL_KERN, KERN_POSIX_SEMAPHORES, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h
index ac3532ffb..4f0194229 100644
--- a/sys/sys/unistd.h
+++ b/sys/sys/unistd.h
@@ -130,7 +130,7 @@
/* regular expressions */
#define _POSIX_REGEXP 1
/* semaphores */
-#define _POSIX_SEMAPHORES 0
+#define _POSIX_SEMAPHORES 200112L
/* shared memory objects */
#define _POSIX_SHARED_MEMORY_OBJECTS 0
/* shell */
--
2.53.0
Patch 3: kern: remove obsolete XXX comments for POSIX options
>From e06f6d0ce3588234501768e0f071bd64019b77e6 Mon Sep 17 00:00:00 2001
From: Joao Bonifacio <joaoboni017%gmail.com@localhost>
Date: Sun, 8 Feb 2026 12:52:21 -0300
Subject: [PATCH 3/3] kern: remove obsolete XXX comments for POSIX options in
sysctl
The XXX comments were removed after verifying that the macros in unistd.h are correctly defined as 200112L, making the doubt expressed in the comments no longer applicable.
Signed-off-by: Joao Bonifacio <joaoboni017%gmail.com@localhost>
---
sys/kern/init_sysctl.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/sys/kern/init_sysctl.c b/sys/kern/init_sysctl.c
index deca12129..bc59e5f7c 100644
--- a/sys/kern/init_sysctl.c
+++ b/sys/kern/init_sysctl.c
@@ -402,7 +402,6 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
CTLTYPE_INT, "monotonic_clock",
SYSCTL_DESCR("Implementation version of the POSIX "
"1003.1b Monotonic Clock Option"),
- /* XXX _POSIX_VERSION */
NULL, _POSIX_MONOTONIC_CLOCK, NULL, 0,
CTL_KERN, KERN_MONOTONIC_CLOCK, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
@@ -443,7 +442,6 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
"Threads option to which the system "
"attempts to conform"),
- /* XXX _POSIX_VERSION */
NULL, _POSIX_THREADS, NULL, 0,
CTL_KERN, KERN_POSIX_THREADS, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
@@ -460,7 +458,6 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
"Barriers option to which the system "
"attempts to conform"),
- /* XXX _POSIX_VERSION */
NULL, _POSIX_BARRIERS, NULL, 0,
CTL_KERN, KERN_POSIX_BARRIERS, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
@@ -469,7 +466,6 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
"Timers option to which the system "
"attempts to conform"),
- /* XXX _POSIX_VERSION */
NULL, _POSIX_TIMERS, NULL, 0,
CTL_KERN, KERN_POSIX_TIMERS, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
@@ -478,7 +474,6 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
SYSCTL_DESCR("Version of IEEE Std 1003.1 and its Spin "
"Locks option to which the system attempts "
"to conform"),
- /* XXX _POSIX_VERSION */
NULL, _POSIX_SPIN_LOCKS, NULL, 0,
CTL_KERN, KERN_POSIX_SPIN_LOCKS, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
@@ -487,7 +482,6 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
"Read-Write Locks option to which the "
"system attempts to conform"),
- /* XXX _POSIX_VERSION */
NULL, _POSIX_READER_WRITER_LOCKS, NULL, 0,
CTL_KERN, KERN_POSIX_READER_WRITER_LOCKS, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
--
2.53.0
Home |
Main Index |
Thread Index |
Old Index