[libc-commits] [libc] [libc] Reapply ELF/LINK header changes (PR #102765)

via libc-commits libc-commits at lists.llvm.org
Sat Aug 10 10:50:02 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Schrodinger ZHU Yifan (SchrodingerZhu)

<details>
<summary>Changes</summary>

This is based on @<!-- -->izaakschroeder  previous patch but I only select macro definitions for now. We need these definitions for VDSO work, which has been delayed for a very long time.

Co-Authored-by: Izaak Schroeder <izaak.schroeder@<!-- -->gmail.com>

---
Full diff: https://github.com/llvm/llvm-project/pull/102765.diff


10 Files Affected:

- (modified) libc/config/linux/aarch64/headers.txt (+2) 
- (modified) libc/config/linux/x86_64/headers.txt (+2) 
- (modified) libc/include/CMakeLists.txt (+17) 
- (added) libc/include/elf.h.def (+17) 
- (added) libc/include/link.h.def (+17) 
- (modified) libc/include/llvm-libc-macros/CMakeLists.txt (+6) 
- (added) libc/include/llvm-libc-macros/elf-macros.h (+18) 
- (modified) libc/include/llvm-libc-macros/link-macros.h (+9-2) 
- (added) libc/newhdrgen/yaml/elf.yaml (+8) 
- (added) libc/newhdrgen/yaml/link.yaml (+8) 


``````````diff
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 8f898f0150905a..ebe053af99d803 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.assert
     libc.include.ctype
     libc.include.dlfcn
+    libc.include.elf
     libc.include.errno
     libc.include.features
     libc.include.fenv
@@ -9,6 +10,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.stdint
     libc.include.inttypes
     libc.include.limits
+    libc.include.link
     libc.include.math
     libc.include.pthread
     libc.include.signal
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index 0294f62bc2f7a0..77e454e64395df 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -3,6 +3,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.ctype
     libc.include.dirent
     libc.include.dlfcn
+    libc.include.elf
     libc.include.errno
     libc.include.fcntl
     libc.include.features
@@ -11,6 +12,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.stdint
     libc.include.inttypes
     libc.include.limits
+    libc.include.link
     libc.include.math
     libc.include.pthread
     libc.include.sched
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index cbde24e17619f6..2b6eb61782a632 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -420,6 +420,23 @@ add_header_macro(
     .llvm-libc-types.posix_spawn_file_actions_t
 )
 
+add_gen_header(
+  link
+  DEF_FILE link.h.def
+  GEN_HDR link.h
+  DEPENDS
+    .llvm_libc_common_h
+    .llvm-libc-macros.link_macros
+)
+
+add_gen_header(
+  elf
+  DEF_FILE elf.h.def
+  GEN_HDR elf.h
+  DEPENDS
+    .llvm-libc-macros.elf_macros
+)
+
 # TODO: Not all platforms will have a include/sys directory. Add the sys
 # directory and the targets for sys/*.h files conditional to the OS requiring
 # them.
diff --git a/libc/include/elf.h.def b/libc/include/elf.h.def
new file mode 100644
index 00000000000000..b9b2604fc7167b
--- /dev/null
+++ b/libc/include/elf.h.def
@@ -0,0 +1,17 @@
+//===-- System V header elf.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_ELF_H
+#define LLVM_LIBC_ELF_H
+
+#include "__llvm-libc-common.h"
+#include "llvm-libc-macros/elf-macros.h"
+
+%%public_api()
+
+#endif // LLVM_LIBC_ELF_H
diff --git a/libc/include/link.h.def b/libc/include/link.h.def
new file mode 100644
index 00000000000000..ebab81c841b8dd
--- /dev/null
+++ b/libc/include/link.h.def
@@ -0,0 +1,17 @@
+//===-- GNU header link.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_LINK_H
+#define LLVM_LIBC_LINK_H
+
+#include "__llvm-libc-common.h"
+#include "llvm-libc-macros/link-macros.h"
+
+%%public_api()
+
+#endif // LLVM_LIBC_LINK_H
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 3c10abef8768c0..60a8725f9ef63f 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -289,3 +289,9 @@ add_macro_header(
   HDR
     dlfcn-macros.h
 )
+
+add_macro_header(
+  elf_macros
+  HDR
+    elf-macros.h
+)
diff --git a/libc/include/llvm-libc-macros/elf-macros.h b/libc/include/llvm-libc-macros/elf-macros.h
new file mode 100644
index 00000000000000..fa4442abf0f5ce
--- /dev/null
+++ b/libc/include/llvm-libc-macros/elf-macros.h
@@ -0,0 +1,18 @@
+//===-- Definition of macros from elf.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_MACROS_ELF_MACROS_H
+#define LLVM_LIBC_MACROS_ELF_MACROS_H
+
+#if __has_include(<linux/elf.h>)
+#include <linux/elf.h>
+#else
+#error "cannot use <sys/elf.h> without proper system headers."
+#endif
+
+#endif // LLVM_LIBC_MACROS_ELF_MACROS_H
diff --git a/libc/include/llvm-libc-macros/link-macros.h b/libc/include/llvm-libc-macros/link-macros.h
index 5c8cadab8e71cb..89e7bb50aa5566 100644
--- a/libc/include/llvm-libc-macros/link-macros.h
+++ b/libc/include/llvm-libc-macros/link-macros.h
@@ -6,8 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_LIBC_MACROS_LINK_MACROS_H
+#define LLVM_LIBC_MACROS_LINK_MACROS_H
+
+#include "elf-macros.h"
+
 #ifdef __LP64__
-#define ElfW(type) Elf64_ ## type
+#define ElfW(type) Elf64_##type
 #else
-#define ElfW(type) Elf32_ ## type
+#define ElfW(type) Elf32_##type
+#endif
+
 #endif
diff --git a/libc/newhdrgen/yaml/elf.yaml b/libc/newhdrgen/yaml/elf.yaml
new file mode 100644
index 00000000000000..2e9db329e22979
--- /dev/null
+++ b/libc/newhdrgen/yaml/elf.yaml
@@ -0,0 +1,8 @@
+header: elf.h
+standards:
+  - Linux
+macros: []
+types: []
+enums: []
+objects: []
+functions: []
diff --git a/libc/newhdrgen/yaml/link.yaml b/libc/newhdrgen/yaml/link.yaml
new file mode 100644
index 00000000000000..d1963a86813af3
--- /dev/null
+++ b/libc/newhdrgen/yaml/link.yaml
@@ -0,0 +1,8 @@
+header: link.h
+standards:
+  - Linux
+macros: []
+types: []
+enums: []
+objects: []
+functions: []

``````````

</details>


https://github.com/llvm/llvm-project/pull/102765


More information about the libc-commits mailing list