[libc-commits] [libc] 3fb55b6 - [libc] Add <sys/un.h> header. (#182622)

via libc-commits libc-commits at lists.llvm.org
Sat Mar 7 22:22:40 PST 2026


Author: Alexey Samsonov
Date: 2026-03-08T06:22:36Z
New Revision: 3fb55b6872c1534fb965bd758d3a6f4d5abf495d

URL: https://github.com/llvm/llvm-project/commit/3fb55b6872c1534fb965bd758d3a6f4d5abf495d
DIFF: https://github.com/llvm/llvm-project/commit/3fb55b6872c1534fb965bd758d3a6f4d5abf495d.diff

LOG: [libc] Add <sys/un.h> header. (#182622)

`sockaddr_un` structure is supposed to be provided by the `<sys/un.h>`
header. Add this header to llvm-libc, and move the declaration of
`sockaddr_un` there from `<sys/socket.h>`. See
https://man7.org/linux/man-pages/man0/sys_un.h.0p.html

Add proxy headers for the `<sys/socket.h>` macro (like `AF_UNIX`) and
for the `struct sockaddr_un` so that the tests can be more hermetic and
avoid system header inclusion.

Added: 
    libc/hdr/sys_socket_macros.h
    libc/hdr/types/struct_sockaddr_un.h
    libc/include/sys/un.yaml

Modified: 
    libc/config/linux/aarch64/headers.txt
    libc/config/linux/x86_64/headers.txt
    libc/hdr/CMakeLists.txt
    libc/hdr/types/CMakeLists.txt
    libc/include/CMakeLists.txt
    libc/include/sys/socket.yaml
    libc/test/src/sys/socket/linux/CMakeLists.txt
    libc/test/src/sys/socket/linux/bind_test.cpp

Removed: 
    


################################################################################
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 0669cc30aeadc..543d151465663 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -51,6 +51,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/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index cb8ade0604ba7..20d210c0c443f 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 03e7066f83a03..1832f906d774c 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -371,6 +371,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 5ffee68b5feb3..94c663c7d3917 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -680,7 +680,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(
@@ -759,6 +758,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;
 


        


More information about the libc-commits mailing list