link.h: add glibc-compatible ElfW(type) macro

Portable ELF code (Mesa util/build_id.c, unwinders) uses ElfW(Nhdr) etc. and
expects <link.h> to define ElfW -> Elf64_type (LP64) / Elf32_type. Without it
those TUs fall back to an undefined Elf_##type and fail to compile.
This commit is contained in:
2026-07-31 17:33:38 +03:00
parent daeca3892e
commit a2f047712e
+14
View File
@@ -12,6 +12,20 @@
#include <elf.h>
#include <stddef.h>
/*
* glibc-compatible `ElfW(type)` macro: expands to the native-word-size ELF type
* (Elf64_type on LP64, Elf32_type otherwise). Portable ELF code (Mesa's
* util/build_id.c, unwinders) uses `ElfW(Nhdr)` etc. and expects <link.h> to
* provide this.
*/
#ifndef ElfW
# if defined(__LP64__) || defined(_LP64) || (__SIZEOF_POINTER__ == 8)
# define ElfW(type) Elf64_##type
# else
# define ElfW(type) Elf32_##type
# endif
#endif
#ifdef __cplusplus
extern "C" {
#endif