In addition to the earlier adjustment to elf_find_function making it actually reported file names when possible, I found that it would only report the last out of potentially many filenames. This was correct for compiler and assembler generated object files, but not for ones resulting from ld -r (as used, for example, in the Linux kernel build process). Build and tested on i686-pc-linux-gnu. bfd/ 2004-11-30 Jan Beulich * elf.c (elf_find_function): Don't use the last file symbol ever, seen, but the last one seen prior to the symbol being reported. Don't report a filename at all for global symbols when that might be ambiguous/wrong. --- /home/jbeulich/src/binutils/mainline/2004-11-30.13.31/bfd/elf.c 2004-11-25 08:36:59.000000000 +0100 +++ 2004-11-30.13.31/bfd/elf.c 2004-11-30 13:54:16.377270128 +0100 @@ -6376,13 +6376,16 @@ elf_find_function (bfd *abfd ATTRIBUTE_U const char **functionname_ptr) { const char *filename; - asymbol *func; + asymbol *func, *file; bfd_vma low_func; asymbol **p; + enum { nothing_seen, symbol_seen, file_after_symbol_seen } state; filename = NULL; func = NULL; + file = NULL; low_func = 0; + state = nothing_seen; for (p = symbols; *p != NULL; p++) { @@ -6395,8 +6398,12 @@ elf_find_function (bfd *abfd ATTRIBUTE_U default: break; case STT_FILE: - filename = bfd_asymbol_name (&q->symbol); - break; + file = &q->symbol; + if (state == symbol_seen) + state = file_after_symbol_seen; + continue; + case STT_SECTION: + continue; case STT_NOTYPE: case STT_FUNC: if (bfd_get_section (&q->symbol) == section @@ -6405,9 +6412,18 @@ elf_find_function (bfd *abfd ATTRIBUTE_U { func = (asymbol *) q; low_func = q->symbol.value; + if (file == NULL) + filename = NULL; + else if (ELF_ST_BIND (q->internal_elf_sym.st_info) != STB_LOCAL + && state == file_after_symbol_seen) + filename = NULL; + else + filename = bfd_asymbol_name (file); } break; } + if (state == nothing_seen) + state = symbol_seen; } if (func == NULL)