[libc-commits] [libc] [libc] Cleaup which entrypoints are fullbuild only (PR #128791)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Tue Feb 25 16:02:36 PST 2025
https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/128791
This patch moves some functions in/out of fullbuild based on if it's
necessary. Specifically:
dlfcn.h: dynamic linker specific, currently stubs, now fullbuild only
arpa/inet.h: The currently implemented functions are standalone
sys/select.h and socket.h: Syscall wrappers, safe to overlay
There's also some cleanup to make sure everything builds.
>From b7904f8082f6ff0fb098a71d23b518e5df6bf42e Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Tue, 25 Feb 2025 15:56:48 -0800
Subject: [PATCH] [libc] Cleaup which entrypoints are fullbuild only
This patch moves some functions in/out of fullbuild based on if it's
necessary. Specifically:
dlfcn.h: dynamic linker specific, currently stubs, now fullbuild only
arpa/inet.h: The currently implemented functions are standalone
sys/select.h and socket.h: Syscall wrappers, safe to overlay
There's also some cleanup to make sure everything builds.
---
libc/config/linux/x86_64/entrypoints.txt | 56 ++++++++++---------
libc/hdr/types/CMakeLists.txt | 9 +++
libc/hdr/types/struct_sockaddr.h | 2 +-
libc/hdr/types/struct_sockaddr_un.h | 21 +++++++
libc/include/CMakeLists.txt | 2 +-
libc/src/CMakeLists.txt | 2 +-
libc/test/src/CMakeLists.txt | 2 +-
libc/test/src/sys/select/select_ui_test.cpp | 14 ++---
libc/test/src/sys/socket/linux/CMakeLists.txt | 2 +
libc/test/src/sys/socket/linux/bind_test.cpp | 9 +--
10 files changed, 76 insertions(+), 43 deletions(-)
create mode 100644 libc/hdr/types/struct_sockaddr_un.h
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index a07393a49e0ad..d8b4627076c9c 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -17,12 +17,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.ctype.tolower
libc.src.ctype.toupper
- # dlfcn.h entrypoints
- libc.src.dlfcn.dlclose
- libc.src.dlfcn.dlerror
- libc.src.dlfcn.dlopen
- libc.src.dlfcn.dlsym
-
# errno.h entrypoints
libc.src.errno.errno
@@ -231,6 +225,12 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.vsprintf
libc.src.stdio.vasprintf
+ # arpa/inet.h entrypoints
+ libc.src.arpa.inet.htonl
+ libc.src.arpa.inet.htons
+ libc.src.arpa.inet.ntohl
+ libc.src.arpa.inet.ntohs
+
# sys/epoll.h entrypoints
libc.src.sys.epoll.epoll_create
libc.src.sys.epoll.epoll_create1
@@ -297,6 +297,20 @@ set(TARGET_LIBC_ENTRYPOINTS
# sys/auxv.h entrypoints
libc.src.sys.auxv.getauxval
+ # sys/select.h entrypoints
+ libc.src.sys.select.select
+
+ # sys/socket.h entrypoints
+ libc.src.sys.socket.socket
+ libc.src.sys.socket.bind
+ 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
+
# termios.h entrypoints
libc.src.termios.cfgetispeed
libc.src.termios.cfgetospeed
@@ -362,6 +376,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sys.uio.readv
)
+# TODO: make this check having malloc instead of scudo specifically
if(LLVM_LIBC_INCLUDE_SCUDO)
list(APPEND TARGET_LIBC_ENTRYPOINTS
# malloc.h external entrypoints
@@ -909,6 +924,15 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.ctype.tolower_l
libc.src.ctype.toupper_l
+ # dlfcn.h entrypoints
+ # currently these are stubs which could work in overlay mode, but once
+ # implemented they'll need to interface with the loader, which would require
+ # fullbuild.
+ libc.src.dlfcn.dlclose
+ libc.src.dlfcn.dlerror
+ libc.src.dlfcn.dlopen
+ libc.src.dlfcn.dlsym
+
# stdlib.h entrypoints
libc.src.stdlib.strtod_l
libc.src.stdlib.strtof_l
@@ -934,12 +958,6 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.dirent.opendir
libc.src.dirent.readdir
- # arpa/inet.h entrypoints
- libc.src.arpa.inet.htonl
- libc.src.arpa.inet.htons
- libc.src.arpa.inet.ntohl
- libc.src.arpa.inet.ntohs
-
# pthread.h entrypoints
libc.src.pthread.pthread_atfork
libc.src.pthread.pthread_attr_destroy
@@ -1156,20 +1174,6 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.unistd.optind
libc.src.unistd.optopt
libc.src.unistd.swab
-
- # sys/select.h entrypoints
- libc.src.sys.select.select
-
- # sys/socket.h entrypoints
- libc.src.sys.socket.socket
- libc.src.sys.socket.bind
- 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/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 84a2647ba664d..6d7b8205fb187 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -286,6 +286,15 @@ add_proxy_header_library(
libc.include.sys_socket
)
+add_proxy_header_library(
+ struct_sockaddr_un
+ HDRS
+ struct_sockaddr_un.h
+ FULL_BUILD_DEPENDS
+ libc.include.llvm-libc-types.struct_sockaddr_un
+ libc.include.sys_socket #TODO: move this to sys/un.h
+)
+
add_proxy_header_library(
socklen_t
HDRS
diff --git a/libc/hdr/types/struct_sockaddr.h b/libc/hdr/types/struct_sockaddr.h
index 0fc31d5374854..02b009d89fc66 100644
--- a/libc/hdr/types/struct_sockaddr.h
+++ b/libc/hdr/types/struct_sockaddr.h
@@ -1,4 +1,4 @@
-//===-- Proxy for struct sockaddr ----------------------------------------===//
+//===-- Proxy for struct sockaddr -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/hdr/types/struct_sockaddr_un.h b/libc/hdr/types/struct_sockaddr_un.h
new file mode 100644
index 0000000000000..84c72669873f9
--- /dev/null
+++ b/libc/hdr/types/struct_sockaddr_un.h
@@ -0,0 +1,21 @@
+//===-- Proxy for struct sockaddr_un --------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_SOCKADDR_UN_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_SOCKADDR_UN_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_sockaddr_un.h"
+
+#else
+
+#include <sys/un.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_SOCKADDR_UN_H
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 867bd1e5ee20f..b16727c91c2fa 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -575,7 +575,7 @@ add_header_macro(
.llvm-libc-types.struct_iovec
.llvm-libc-types.struct_msghdr
.llvm-libc-types.struct_sockaddr
- .llvm-libc-types.struct_sockaddr_un
+ .llvm-libc-types.struct_sockaddr_un #TODO: move this to sys/un.h
)
add_header_macro(
diff --git a/libc/src/CMakeLists.txt b/libc/src/CMakeLists.txt
index 19a354ceee4b6..b602b80960592 100644
--- a/libc/src/CMakeLists.txt
+++ b/libc/src/CMakeLists.txt
@@ -1,5 +1,6 @@
add_subdirectory(__support)
+add_subdirectory(arpa)
add_subdirectory(complex)
add_subdirectory(ctype)
add_subdirectory(dlfcn)
@@ -31,7 +32,6 @@ if(NOT LLVM_LIBC_FULL_BUILD)
return()
endif()
-add_subdirectory(arpa)
add_subdirectory(assert)
add_subdirectory(compiler)
add_subdirectory(locale)
diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index b7c145788c0cd..9d28a45eda6ce 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -56,6 +56,7 @@ function(add_fp_unittest name)
endfunction(add_fp_unittest)
add_subdirectory(__support)
+add_subdirectory(arpa)
add_subdirectory(complex)
add_subdirectory(ctype)
add_subdirectory(errno)
@@ -87,7 +88,6 @@ if(NOT LLVM_LIBC_FULL_BUILD)
return()
endif()
-add_subdirectory(arpa)
add_subdirectory(assert)
add_subdirectory(compiler)
add_subdirectory(dirent)
diff --git a/libc/test/src/sys/select/select_ui_test.cpp b/libc/test/src/sys/select/select_ui_test.cpp
index a158cab8ff058..28c18a5a915f2 100644
--- a/libc/test/src/sys/select/select_ui_test.cpp
+++ b/libc/test/src/sys/select/select_ui_test.cpp
@@ -11,7 +11,7 @@
#include "src/unistd/read.h"
#include "test/UnitTest/Test.h"
-#include <sys/select.h>
+#include <sys/select.h> //TODO: move to hdr/sys_select_macros.h
#include <unistd.h>
// This test is not be run automatically as part of the libc testsuite.
@@ -23,26 +23,22 @@ TEST(LlvmLibcSelectTest, ReadStdinAfterSelect) {
fd_set set;
FD_ZERO(&set);
FD_SET(STDIN_FD, &set);
- struct timeval zero {
- 0, 0
- }; // No wait
- struct timeval hr {
- 3600, 0
- }; // Wait for an hour.
+ struct timeval zero{0, 0}; // No wait
+ struct timeval hr{3600, 0}; // Wait for an hour.
// Zero timeout means we don't wait for input. So, select should return
// immediately.
int count =
LIBC_NAMESPACE::select(STDIN_FD + 1, &set, nullptr, nullptr, &zero);
// The set should indicate that stdin is NOT ready for reading.
- ASSERT_EQ(0, FD_ISSET(STDIN_FD, &set));
+ ASSERT_EQ(0, static_cast<int>(FD_ISSET(STDIN_FD, &set)));
FD_SET(STDIN_FD, &set);
// Wait for an hour and give the user a chance to hit a key.
count = LIBC_NAMESPACE::select(STDIN_FD + 1, &set, nullptr, nullptr, &hr);
ASSERT_EQ(count, 1);
// The set should indicate that stdin is ready for reading.
- ASSERT_EQ(1, FD_ISSET(STDIN_FD, &set));
+ ASSERT_EQ(1, static_cast<int>(FD_ISSET(STDIN_FD, &set)));
// Verify that atleast one character can be read.
char c;
diff --git a/libc/test/src/sys/socket/linux/CMakeLists.txt b/libc/test/src/sys/socket/linux/CMakeLists.txt
index 9149b78631f29..a2a683beac5ad 100644
--- a/libc/test/src/sys/socket/linux/CMakeLists.txt
+++ b/libc/test/src/sys/socket/linux/CMakeLists.txt
@@ -21,6 +21,8 @@ add_libc_unittest(
bind_test.cpp
DEPENDS
libc.include.sys_socket
+ libc.hdr.types.struct_sockaddr
+ libc.hdr.types.struct_sockaddr_un
libc.src.errno.errno
libc.src.sys.socket.socket
libc.src.sys.socket.bind
diff --git a/libc/test/src/sys/socket/linux/bind_test.cpp b/libc/test/src/sys/socket/linux/bind_test.cpp
index e70cbd578290b..b26f1a7562505 100644
--- a/libc/test/src/sys/socket/linux/bind_test.cpp
+++ b/libc/test/src/sys/socket/linux/bind_test.cpp
@@ -6,15 +6,16 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/types/struct_sockaddr.h"
+#include "hdr/types/struct_sockaddr_un.h"
+#include "src/errno/libc_errno.h"
+#include "src/stdio/remove.h"
#include "src/sys/socket/bind.h"
#include "src/sys/socket/socket.h"
-
-#include "src/stdio/remove.h"
#include "src/unistd/close.h"
-
-#include "src/errno/libc_errno.h"
#include "test/UnitTest/Test.h"
+// TODO: move to hdr/sys_socket_macros
#include <sys/socket.h> // For AF_UNIX and SOCK_DGRAM
TEST(LlvmLibcSocketTest, BindLocalSocket) {
More information about the libc-commits
mailing list