a2f047712e
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.
60 lines
2.1 KiB
C
60 lines
2.1 KiB
C
/*
|
|
* link.h — dynamic-linker introspection (dl_iterate_phdr).
|
|
*
|
|
* Non-POSIX (glibc/BSD extension). The implementation of dl_iterate_phdr lives
|
|
* in relibc's dynamic linker (src/header/link/mod.rs); this header only
|
|
* declares the ABI. Keep `struct dl_phdr_info` in sync with the Rust
|
|
* `DlPhdrInfo` struct in that module.
|
|
*/
|
|
#ifndef _RELIBC_LINK_H
|
|
#define _RELIBC_LINK_H
|
|
|
|
#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
|
|
|
|
struct dl_phdr_info {
|
|
Elf64_Addr dlpi_addr; /* base / load bias of the object */
|
|
const char *dlpi_name; /* object pathname (NUL-terminated) */
|
|
const Elf64_Phdr *dlpi_phdr; /* pointer to the program header array */
|
|
Elf64_Half dlpi_phnum; /* number of program headers */
|
|
/* glibc-compatible extension fields */
|
|
unsigned long long dlpi_adds; /* # objects added since process start */
|
|
unsigned long long dlpi_subs; /* # objects removed since start */
|
|
size_t dlpi_tls_modid; /* TLS module ID (0 if none) */
|
|
void *dlpi_tls_data; /* TLS block for the calling thread */
|
|
};
|
|
|
|
/*
|
|
* Call `callback` once per loaded object. `size` is sizeof(struct dl_phdr_info).
|
|
* Iteration stops as soon as a callback returns non-zero, and that value is
|
|
* returned; otherwise the return value is that of the last callback (or 0 when
|
|
* there are no objects).
|
|
*/
|
|
int dl_iterate_phdr(int (*callback)(struct dl_phdr_info *info,
|
|
size_t size, void *data),
|
|
void *data);
|
|
|
|
#ifdef __cplusplus
|
|
} /* extern "C" */
|
|
#endif
|
|
|
|
#endif /* _RELIBC_LINK_H */
|