[libc-commits] [libc] [libc] Enable socket entrypoints in overlay mode on x86_64 and aarch64 (PR #194603)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Tue Apr 28 05:19:43 PDT 2026


https://github.com/labath created https://github.com/llvm/llvm-project/pull/194603

This is slightly tricky in that many of these functions depend on types (struct sockaddrs, msghdr, ...) and we cannot overlay types. However, this works because these functions are simple syscall wrappers which simply forward the data to the kernel -- so it's really the kernel that's defining these structures.

This approach is compatible with libraries which implement these functions the same way, which includes at least glibc (on all architectures) and musl (on 64-bit architectures). 32-bit musl repacks the [c]msghdr structures to zero out padding fields, and overlaying that could lead to very subtle bugs. I don't know if anyone uses the overlay mode with musl, but I'm playing it safe and enabling the entrypoints on 64-bit architectures only.

>From 5b188fa5acc777de30b2e5adf4891d38deb75395 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Tue, 28 Apr 2026 09:55:26 +0000
Subject: [PATCH] [libc] Enable socket entrypoints in overlay mode on x86_64
 and aarch64

This is slightly tricky in that many of these functions depend on types
(struct sockaddrs, msghdr, ...) and we cannot overlay types. However,
this works because these functions are simple syscall wrappers which
simply forward the data to the kernel -- so it's really the kernel
that's defining these structures.

This approach is compatible with libraries which implement these
functions the same way, this includes at least glibc (on all
architectures) and musl (on 64-bit architectures). 32-bit musl repacks
the [c]msghdr structures to zero out padding fields, and overlaying that
could lead to very subtle bugs. I don't know if anyone uses the overlay
mode with musl, but I'm playing it safe and enabling the entrypoints on
64-bit architectures only.
---
 libc/config/linux/aarch64/entrypoints.txt     | 24 ++++++------
 libc/config/linux/x86_64/entrypoints.txt      | 38 +++++++++----------
 .../src/sys/socket/linux/socketopt_test.cpp   |  2 +-
 3 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index b15edc5e3e102..db03270f25232 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -278,9 +278,20 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.sys.resource.getrlimit
     libc.src.sys.resource.setrlimit
 
-    # sys/sendfile entrypoints
+    # sys/sendfile.h entrypoints
     libc.src.sys.sendfile.sendfile
 
+    # sys/socket.h entrypoints
+    libc.src.sys.socket.accept
+    libc.src.sys.socket.accept4
+    libc.src.sys.socket.bind
+    libc.src.sys.socket.connect
+    libc.src.sys.socket.getsockopt
+    libc.src.sys.socket.listen
+    libc.src.sys.socket.setsockopt
+    libc.src.sys.socket.shutdown
+    libc.src.sys.socket.socket
+
     # sys/stat.h entrypoints
     libc.src.sys.stat.chmod
     libc.src.sys.stat.fchmod
@@ -1218,17 +1229,6 @@ if(LLVM_LIBC_FULL_BUILD)
 
     # sys/select.h entrypoints
     libc.src.sys.select.select
-
-    # sys/socket.h entrypoints
-    libc.src.sys.socket.accept
-    libc.src.sys.socket.accept4
-    libc.src.sys.socket.bind
-    libc.src.sys.socket.connect
-    libc.src.sys.socket.getsockopt
-    libc.src.sys.socket.listen
-    libc.src.sys.socket.setsockopt
-    libc.src.sys.socket.shutdown
-    libc.src.sys.socket.socket
   )
 endif()
 
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index d1c1d9496af67..d65a5a2998745 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -294,9 +294,27 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.sys.sem.semctl
     libc.src.sys.sem.semop
 
-    # sys/sendfile entrypoints
+    # sys/sendfile.h entrypoints
     libc.src.sys.sendfile.sendfile
 
+    # sys/socket.h entrypoints
+    libc.src.sys.socket.accept
+    libc.src.sys.socket.accept4
+    libc.src.sys.socket.bind
+    libc.src.sys.socket.connect
+    libc.src.sys.socket.getsockopt
+    libc.src.sys.socket.listen
+    libc.src.sys.socket.recv
+    libc.src.sys.socket.recvfrom
+    libc.src.sys.socket.recvmsg
+    libc.src.sys.socket.send
+    libc.src.sys.socket.sendmsg
+    libc.src.sys.socket.sendto
+    libc.src.sys.socket.setsockopt
+    libc.src.sys.socket.shutdown
+    libc.src.sys.socket.socket
+    libc.src.sys.socket.socketpair
+
     # sys/stat.h entrypoints
     libc.src.sys.stat.chmod
     libc.src.sys.stat.fchmod
@@ -1429,24 +1447,6 @@ if(LLVM_LIBC_FULL_BUILD)
     # sys/select.h entrypoints
     libc.src.sys.select.select
 
-    # sys/socket.h entrypoints
-    libc.src.sys.socket.accept
-    libc.src.sys.socket.accept4
-    libc.src.sys.socket.socket
-    libc.src.sys.socket.bind
-    libc.src.sys.socket.connect
-    libc.src.sys.socket.getsockopt
-    libc.src.sys.socket.listen
-    libc.src.sys.socket.shutdown
-    libc.src.sys.socket.socketpair
-    libc.src.sys.socket.setsockopt
-    libc.src.sys.socket.send
-    libc.src.sys.socket.sendto
-    libc.src.sys.socket.sendmsg
-    libc.src.sys.socket.recv
-    libc.src.sys.socket.recvfrom
-    libc.src.sys.socket.recvmsg
-
     # wchar.h entrypoints
     libc.src.wchar.mblen
     libc.src.wchar.mbrlen
diff --git a/libc/test/src/sys/socket/linux/socketopt_test.cpp b/libc/test/src/sys/socket/linux/socketopt_test.cpp
index e069a7bd35fa6..0e132a877d0c7 100644
--- a/libc/test/src/sys/socket/linux/socketopt_test.cpp
+++ b/libc/test/src/sys/socket/linux/socketopt_test.cpp
@@ -48,7 +48,7 @@ TEST_F(LlvmLibcSocketOptTest, BasicSocketOpt) {
   ASSERT_THAT(
       LIBC_NAMESPACE::getsockopt(sock, SOL_SOCKET, SO_TYPE, &optval, &optlen),
       Succeeds(0));
-  ASSERT_EQ(optval, SOCK_STREAM);
+  ASSERT_EQ(optval, static_cast<int>(SOCK_STREAM));
   ASSERT_EQ(optlen, static_cast<socklen_t>(sizeof(optval)));
 
   optval = SOCK_DGRAM;



More information about the libc-commits mailing list