lockstat: Use gelf.h instead of playing games with the preprocessor

This reverts a portion of 1477dd823e ("Merge OpenZFS support in to
HEAD.").  No functional change intended.

MFC after:	1 week
This commit is contained in:
Mark Johnston 2023-02-24 20:15:21 -05:00
parent f4f5e69c84
commit 49e3972afc

View file

@ -42,6 +42,7 @@
#include <libelf.h>
#include <link.h>
#include <elf.h>
#include <gelf.h>
#ifdef illumos
#include <sys/machelf.h>
@ -54,7 +55,6 @@
#endif
#include <sys/cpuvar.h>
typedef struct syment {
uintptr_t addr;
char *name;
@ -73,11 +73,6 @@ static char maxsymname[64];
#endif
#endif
#define __sElfN(x) typedef __CONCAT(__CONCAT(__CONCAT(Elf,__ELF_WORD_SIZE),_),x) x
__sElfN(Sym);
__sElfN(Shdr);
#define elf_getshdr __elfN(getshdr)
static void
add_symbol(char *name, uintptr_t addr, size_t size)
{
@ -174,7 +169,7 @@ symtab_init(void)
{
Elf *elf;
Elf_Scn *scn = NULL;
Sym *symtab, *symp, *lastsym;
GElf_Sym *symtab, *symp, *lastsym;
char *strtab;
uint_t cnt;
int fd;
@ -198,13 +193,13 @@ symtab_init(void)
(void) elf_version(EV_CURRENT);
elf = elf_begin(fd, ELF_C_READ, NULL);
for (cnt = 1; (scn = elf_nextscn(elf, scn)) != NULL; cnt++) {
Shdr *shdr = elf_getshdr(scn);
if (shdr->sh_type == SHT_SYMTAB) {
symtab = (Sym *)elf_getdata(scn, NULL)->d_buf;
nsyms = shdr->sh_size / shdr->sh_entsize;
strindex = shdr->sh_link;
GElf_Shdr shdr;
(void) gelf_getshdr(scn, &shdr);
if (shdr.sh_type == SHT_SYMTAB) {
symtab = (GElf_Sym *)elf_getdata(scn, NULL)->d_buf;
nsyms = shdr.sh_size / shdr.sh_entsize;
strindex = shdr.sh_link;
}
}