/* Find symbols before or equal addr and after addr - in the section sec. If we find two symbols with equal offset prefer one with a valid name. The ELF format may have a better way to detect what type of symbol it is, but this works for now.  */
static Elf_Sym* find_elf_symbol2(struct elf_info *elf, Elf_Addr addr, const char *sec)
/* Find symbols before or equal addr and after addr - in the section sec. If we find two symbols with equal offset prefer one with a valid name. The ELF format may have a better way to detect what type of symbol it is, but this works for now.  */
static Elf_Sym* find_elf_symbol2(struct elf_info *elf, Elf_Addr addr, const char *sec)
{
	Elf_Sym *sym;
	Elf_Sym *near = NULL;
	Elf_Addr distance = ~0;
	for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
		const char *symsec;
		if (sym->st_shndx >= SHN_LORESERVE)
			continue;
		symsec = sec_name(elf, sym->st_shndx);
		if (strcmp(symsec, sec) != 0)
			continue;
		if (!is_valid_name(elf, sym))
			continue;
		if (sym->st_value <= addr) {
			if ((addr - sym->st_value) < distance) {
				distance = addr - sym->st_value;
				near = sym;
			} else if ((addr - sym->st_value) == distance) {
				near = sym;
			}
		}
	}
	return near;
}