/* Find symbol based on relocation record info. In some cases the symbol supplied is a valid symbol so return refsym. If st_name != 0 we assume this is a valid symbol. In other cases the symbol needs to be looked up in the symbol table based on section and address.  */
static Elf_Sym* find_elf_symbol(struct elf_info *elf, Elf64_Sword addr, Elf_Sym *relsym)
/* Find symbol based on relocation record info. In some cases the symbol supplied is a valid symbol so return refsym. If st_name != 0 we assume this is a valid symbol. In other cases the symbol needs to be looked up in the symbol table based on section and address.  */
static Elf_Sym* find_elf_symbol(struct elf_info *elf, Elf64_Sword addr, Elf_Sym *relsym)
{
	Elf_Sym *sym;
	Elf_Sym *near = NULL;
	Elf64_Sword distance = 20;
	Elf64_Sword d;
	if (relsym->st_name != 0)
		return relsym;
	for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
		if (sym->st_shndx != relsym->st_shndx)
			continue;
		if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
			continue;
		if (sym->st_value == addr)
			return sym;
		d = sym->st_value - addr;
		if (d < 0)
			d = addr - sym->st_value;
		if (d < distance) {
			distance = d;
			near = sym;
		}
	}
	if (distance < 20)
		return near;
	else
		return NULL;
}