[libc-commits] [libc] [libc] Enable socket entrypoints in overlay mode (PR #195035)
via libc-commits
libc-commits at lists.llvm.org
Thu Apr 30 01:14:34 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
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, this includes at least glibc (on all architectures) and musl (on 32-bit architectures). 64-bit musl repacks the [c]msghdr structures to zero out padding fields, and overlaying that can lead to subtle bugs. However, I believe that overlaying musl is not a very interesting use case, so I'm leaving that as a TODO. If someone is interested in doing that, they can either exclude these entrypoints from the overlay or implement the musl-compatible repacking code.
---
Full diff: https://github.com/llvm/llvm-project/pull/195035.diff
4 Files Affected:
- (modified) libc/config/linux/aarch64/entrypoints.txt (+21-12)
- (modified) libc/config/linux/riscv/entrypoints.txt (+21-19)
- (modified) libc/config/linux/x86_64/entrypoints.txt (+21-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..1a14d80497a65 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -278,9 +278,29 @@ 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.recv
+ libc.src.sys.socket.recvfrom
+ libc.src.sys.socket.send
+ 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
+ # TODO: These functions are not compatible with 64-bit musl. They need to
+ # be excluded if overlaying musl.
+ libc.src.sys.socket.recvmsg
+ libc.src.sys.socket.sendmsg
+
# sys/stat.h entrypoints
libc.src.sys.stat.chmod
libc.src.sys.stat.fchmod
@@ -1218,17 +1238,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/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 6478aed3b0391..9955c59fc01bf 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -278,9 +278,29 @@ 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.recv
+ libc.src.sys.socket.recvfrom
+ libc.src.sys.socket.send
+ 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
+ # TODO: These functions are not compatible with 64-bit musl. They need to
+ # be excluded if overlaying musl.
+ libc.src.sys.socket.recvmsg
+ libc.src.sys.socket.sendmsg
+
# sys/stat.h entrypoints
libc.src.sys.stat.chmod
libc.src.sys.stat.fchmod
@@ -1352,24 +1372,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
- libc.src.sys.socket.socketpair
- 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
)
endif()
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index d1c1d9496af67..ee60f1764a9f2 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -294,9 +294,29 @@ 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.send
+ 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
+ # TODO: These functions are not compatible with 64-bit musl. They need to
+ # be excluded if overlaying musl.
+ libc.src.sys.socket.recvmsg
+ libc.src.sys.socket.sendmsg
+
# sys/stat.h entrypoints
libc.src.sys.stat.chmod
libc.src.sys.stat.fchmod
@@ -1429,24 +1449,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/195035
More information about the libc-commits
mailing list