[libc-commits] [libc] [libc] Enable socket entrypoints in overlay mode on x86_64 and aarch64 (PR #194603)
via libc-commits
libc-commits at lists.llvm.org
Tue Apr 28 05:20:22 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Pavel Labath (labath)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/194603.diff
3 Files Affected:
- (modified) libc/config/linux/aarch64/entrypoints.txt (+12-12)
- (modified) libc/config/linux/x86_64/entrypoints.txt (+19-19)
- (modified) libc/test/src/sys/socket/linux/socketopt_test.cpp (+1-1)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/194603
More information about the libc-commits
mailing list