[libc-commits] [libc] [libc] Add ar header (PR #243964)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Wed Nov 18 10:50:46 PST 2026


https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/243964

The ar header is a GNU extension for archiver utilities. Added for
compatibility.

Assisted-by: Automated tooling, human reviewed.


>From 7bfb0071ecb4215dabf41de0577c2fab6627032c Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Wed, 18 Nov 2026 18:49:09 +0000
Subject: [PATCH] [libc] Add ar header

The ar header is a GNU extension for archiver utilities. Added for
compatibility.

Assisted-by: Automated tooling, human reviewed.
---
 libc/config/linux/aarch64/headers.txt        |  1 +
 libc/config/linux/riscv/headers.txt          |  1 +
 libc/config/linux/x86_64/headers.txt         |  1 +
 libc/include/CMakeLists.txt                  |  9 +++++++
 libc/include/ar.yaml                         | 12 +++++++++
 libc/include/llvm-libc-types/CMakeLists.txt  |  1 +
 libc/include/llvm-libc-types/struct_ar_hdr.h | 28 ++++++++++++++++++++
 7 files changed, 53 insertions(+)
 create mode 100644 libc/include/ar.yaml
 create mode 100644 libc/include/llvm-libc-types/struct_ar_hdr.h

diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 30b59c2170493..53ced730e8ff8 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -1,5 +1,6 @@
 set(TARGET_PUBLIC_HEADERS
     libc.include.alloca
+    libc.include.ar
     libc.include.arpa_inet
     libc.include.arpa_nameser
     libc.include.assert
diff --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt
index 729460260484d..4fd6f5e591a6b 100644
--- a/libc/config/linux/riscv/headers.txt
+++ b/libc/config/linux/riscv/headers.txt
@@ -1,5 +1,6 @@
 set(TARGET_PUBLIC_HEADERS
     libc.include.alloca
+    libc.include.ar
     libc.include.arpa_inet
     libc.include.arpa_nameser
     libc.include.assert
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index ab85066f418e7..cd882ec8e3603 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -1,5 +1,6 @@
 set(TARGET_PUBLIC_HEADERS
     libc.include.alloca
+    libc.include.ar
     libc.include.arpa_inet
     libc.include.arpa_nameser
     libc.include.assert
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 1c35510f5d72e..7ca695073e2ab 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -704,6 +704,15 @@ add_header_macro(
     .llvm-libc-types.posix_spawn_file_actions_t
 )
 
+add_header_macro(
+  ar
+  ../libc/include/ar.yaml
+  ar.h
+  DEPENDS
+    .llvm_libc_common_h
+    .llvm-libc-types.struct_ar_hdr
+)
+
 add_header_macro(
   elf
   ../libc/include/elf.yaml
diff --git a/libc/include/ar.yaml b/libc/include/ar.yaml
new file mode 100644
index 0000000000000..65665cfabcc99
--- /dev/null
+++ b/libc/include/ar.yaml
@@ -0,0 +1,12 @@
+header: ar.h
+standards:
+  - bsd
+macros:
+  - macro_name: ARMAG
+    macro_value: '"!<arch>\n"'
+  - macro_name: SARMAG
+    macro_value: 8
+  - macro_name: ARFMAG
+    macro_value: '"`\n"'
+types:
+  - type_name: struct_ar_hdr
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 00fae51cf48f1..485a93d9959f0 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -648,6 +648,7 @@ endif()
 add_type_header(mcontext_t HDR mcontext_t.h)
 add_type_header(ucontext_t HDR ucontext_t.h)
 add_type_header(struct_user_regs_struct HDR struct_user_regs_struct.h)
+add_header(struct_ar_hdr HDR struct_ar_hdr.h)
 
 # UEFI
 add_header(EFI_GUID HDR EFI_GUID.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
diff --git a/libc/include/llvm-libc-types/struct_ar_hdr.h b/libc/include/llvm-libc-types/struct_ar_hdr.h
new file mode 100644
index 0000000000000..caf9ea9bcd9be
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_ar_hdr.h
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct ar_hdr.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_AR_HDR_H
+#define LLVM_LIBC_TYPES_STRUCT_AR_HDR_H
+
+// Archive member header. Every field is ASCII text padded with spaces.
+struct ar_hdr {
+  char ar_name[16]; // Member name, terminated by '/' in the System V format.
+  char ar_date[12]; // Modification time, decimal seconds since the Epoch.
+  char ar_uid[6];   // User ID, decimal.
+  char ar_gid[6];   // Group ID, decimal.
+  char ar_mode[8];  // File mode, octal.
+  char ar_size[10]; // Member size in bytes, decimal.
+  char ar_fmag[2];  // Always ARFMAG.
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_AR_HDR_H



More information about the libc-commits mailing list