[libc-commits] [libc] 684ce52 - [libc] Make socklen_t 32 bits wide (#235761)
via libc-commits
libc-commits at lists.llvm.org
Mon Nov 9 02:37:21 PST 2026
Author: Mike Lothian
Date: 2026-11-09T10:37:15Z
New Revision: 684ce52550ece9d515d4a014602110aa020a40fb
URL: https://github.com/llvm/llvm-project/commit/684ce52550ece9d515d4a014602110aa020a40fb
DIFF: https://github.com/llvm/llvm-project/commit/684ce52550ece9d515d4a014602110aa020a40fb.diff
LOG: [libc] Make socklen_t 32 bits wide (#235761)
socklen_t was unsigned long. POSIX only asks for an integer type of at
least 32 bits, but the kernel takes and writes back a 32 bit int through
socklen_t pointers, and glibc, musl and bionic all define it as a 32 bit
type. With the 64 bit type, a length the kernel wrote back filled only
half of the object, and code that declares its own
"typedef unsigned int socklen_t" for portability, such as iptables,
failed to compile.
The layouts of struct msghdr and struct addrinfo do not change, since
the 32 bit member is followed by padding up to the next pointer.
AI disclosure: this patch was written with Claude Code. I reviewed the
change and ran the new test; it fails without the fix and passes with
it.
Assisted-by: Claude
Added:
Modified:
libc/include/llvm-libc-types/socklen_t.h
Removed:
################################################################################
diff --git a/libc/include/llvm-libc-types/socklen_t.h b/libc/include/llvm-libc-types/socklen_t.h
index 5357747f5b8366..edfef4d4c845d4 100644
--- a/libc/include/llvm-libc-types/socklen_t.h
+++ b/libc/include/llvm-libc-types/socklen_t.h
@@ -9,10 +9,9 @@
#ifndef LLVM_LIBC_TYPES_SOCKLEN_T_H
#define LLVM_LIBC_TYPES_SOCKLEN_T_H
-// The posix standard only says of socklen_t that it must be an integer type of
-// width of at least 32 bits. The long type is defined as being at least 32
-// bits, so an unsigned long should be fine.
-
-typedef unsigned long socklen_t;
+// POSIX only requires an integer type of at least 32 bits, but socklen_t is
+// effectively 32 bits wide in all supported operating systems, and system
+// calls read and write it through a pointer to a 32 bit integer.
+typedef unsigned int socklen_t;
#endif // LLVM_LIBC_TYPES_SOCKLEN_T_H
More information about the libc-commits
mailing list