[libc-commits] [libc] [libc] Add <sys/un.h> header. (PR #182622)
Alexey Samsonov via libc-commits
libc-commits at lists.llvm.org
Sun Feb 22 12:58:33 PST 2026
https://github.com/vonosmas updated https://github.com/llvm/llvm-project/pull/182622
>From 2c11c954a4a3996aa26e9c4c935180201efe6647 Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <vonosmas at gmail.com>
Date: Fri, 20 Feb 2026 23:29:35 +0000
Subject: [PATCH 1/2] [libc] Add <sys/un.h> header.
---
libc/hdr/CMakeLists.txt | 9 ++++++++
libc/hdr/sys_socket_macros.h | 22 +++++++++++++++++++
libc/hdr/types/CMakeLists.txt | 9 ++++++++
libc/hdr/types/struct_sockaddr_un.h | 21 ++++++++++++++++++
libc/include/CMakeLists.txt | 10 ++++++++-
libc/include/sys/socket.yaml | 1 -
libc/include/sys/un.yaml | 5 +++++
libc/test/src/sys/socket/linux/CMakeLists.txt | 2 ++
libc/test/src/sys/socket/linux/bind_test.cpp | 4 ++--
9 files changed, 79 insertions(+), 4 deletions(-)
create mode 100644 libc/hdr/sys_socket_macros.h
create mode 100644 libc/hdr/types/struct_sockaddr_un.h
create mode 100644 libc/include/sys/un.yaml
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 6362c10788b2b..6cf85c006d93e 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -149,6 +149,15 @@ add_proxy_header_library(
libc.include.llvm-libc-macros.sys_ioctl_macros
)
+add_proxy_header_library(
+ sys_socket_macros
+ HDRS
+ sys_socket_macros.h
+ FULL_BUILD_DEPENDS
+ libc.include.sys_socket
+ libc.include.llvm-libc-macros.sys_socket_macros
+)
+
add_proxy_header_library(
sys_stat_macros
HDRS
diff --git a/libc/hdr/sys_socket_macros.h b/libc/hdr/sys_socket_macros.h
new file mode 100644
index 0000000000000..5d8279b25b786
--- /dev/null
+++ b/libc/hdr/sys_socket_macros.h
@@ -0,0 +1,22 @@
+//===-- Definition of macros from sys/socket.h ----------------------------===//
+//
+// 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_SYS_SOCKET_MACROS_H
+#define LLVM_LIBC_HDR_SYS_SOCKET_MACROS_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-macros/sys-socket-macros.h"
+
+#else // Overlay mode
+
+#include <sys/socket.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_SYS_SOCKET_MACROS_H
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 3385fe81fe223..dc4bb9479b8c5 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -362,6 +362,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
+)
+
add_proxy_header_library(
socklen_t
HDRS
diff --git a/libc/hdr/types/struct_sockaddr_un.h b/libc/hdr/types/struct_sockaddr_un.h
new file mode 100644
index 0000000000000..8ac75598da282
--- /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 c6254aafe3849..65469d03fbfcd 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -666,7 +666,6 @@ add_header_macro(
.llvm-libc-types.struct_iovec
.llvm-libc-types.struct_msghdr
.llvm-libc-types.struct_sockaddr
- .llvm-libc-types.struct_sockaddr_un
)
add_header_macro(
@@ -744,6 +743,15 @@ add_header_macro(
.llvm-libc-types.ssize_t
)
+add_header_macro(
+ sys_un
+ ../libc/include/sys/un.yaml
+ sys/un.h
+ DEPENDS
+ .llvm_libc_common_h
+ .llvm-libc-types.struct_sockaddr_un
+)
+
add_header_macro(
sys_wait
../libc/include/sys/wait.yaml
diff --git a/libc/include/sys/socket.yaml b/libc/include/sys/socket.yaml
index 00d5de6af8a80..945e730413adb 100644
--- a/libc/include/sys/socket.yaml
+++ b/libc/include/sys/socket.yaml
@@ -2,7 +2,6 @@ header: sys/socket.h
header_template: socket.h.def
macros: []
types:
- - type_name: struct_sockaddr_un
- type_name: struct_sockaddr
- type_name: socklen_t
- type_name: sa_family_t
diff --git a/libc/include/sys/un.yaml b/libc/include/sys/un.yaml
new file mode 100644
index 0000000000000..154294ff79cf5
--- /dev/null
+++ b/libc/include/sys/un.yaml
@@ -0,0 +1,5 @@
+header: sys/un.h
+standards:
+ - posix
+types:
+ - type_name: struct_sockaddr_un
diff --git a/libc/test/src/sys/socket/linux/CMakeLists.txt b/libc/test/src/sys/socket/linux/CMakeLists.txt
index de67040122138..1ff814029b330 100644
--- a/libc/test/src/sys/socket/linux/CMakeLists.txt
+++ b/libc/test/src/sys/socket/linux/CMakeLists.txt
@@ -23,6 +23,8 @@ add_libc_unittest(
bind_test.cpp
DEPENDS
libc.include.sys_socket
+ libc.hdr.sys_socket_macros
+ 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 60cd7c0df10f2..03b8c18cfee83 100644
--- a/libc/test/src/sys/socket/linux/bind_test.cpp
+++ b/libc/test/src/sys/socket/linux/bind_test.cpp
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/sys_socket_macros.h"
+#include "hdr/types/struct_sockaddr_un.h"
#include "src/sys/socket/bind.h"
#include "src/sys/socket/socket.h"
@@ -16,8 +18,6 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <sys/socket.h> // For AF_UNIX and SOCK_DGRAM
-
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
using LlvmLibcBindTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
>From 26adbaa8a5f68571b956420830d53da86dafaba0 Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <vonosmas at gmail.com>
Date: Sun, 22 Feb 2026 20:58:21 +0000
Subject: [PATCH 2/2] Add sys/un.h to header list.
---
libc/config/linux/aarch64/headers.txt | 1 +
libc/config/linux/x86_64/headers.txt | 1 +
2 files changed, 2 insertions(+)
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 0573851fbc20b..1c7df25ad930f 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -49,6 +49,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.sys_syscall
libc.include.sys_time
libc.include.sys_types
+ libc.include.sys_un
libc.include.sys_utsname
libc.include.sys_wait
libc.include.sysexits
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index d0f62eb104dcc..5da91a8eb2aa9 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -50,6 +50,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.sys_syscall
libc.include.sys_time
libc.include.sys_types
+ libc.include.sys_un
libc.include.sys_utsname
libc.include.sys_wait
libc.include.sysexits
More information about the libc-commits
mailing list