bfd_error_handler extension
Alan Modra
amodra@bigpond.net.au
Thu Aug 12 03:58:00 GMT 2004
Seeing HJ's patch to report unrecognized i386 relocations reminded me
of an idea I had about extending _bfd_default_error_handler to
handle the common cases of printing a bfd filename (which might be
an archive) and a section name (which might need group info).
The main difficulty in extending a printf style function is that
vfprintf doesn't return any info on how far its va_list arg has
been incremented. You can't call vfprintf passing part of the format
string, do some processing on a special % specifier, then call vprintf
again. That is, not without duplicating a lot of the work vfprintf does
in parsing the format string.
So my idea was to always pass extension args first. A call might look
like
(*_bfd_error_handler)
(_("%B: bad reloc symbol index (0x%lx >= 0x%lx) for offset 0x%lx in section `%S'"),
abfd, sec,
(unsigned long) r_symndx, (unsigned long) nsyms, irela->r_offset);
instead of the existing code (from elf_link_read_relocs_from_section)
char *sec_name = bfd_get_section_ident (sec);
(*_bfd_error_handler)
(_("%s: bad reloc symbol index (0x%lx >= 0x%lx) for offset 0x%lx in section `%s'"),
bfd_archive_filename (abfd), (unsigned long) r_symndx,
(unsigned long) nsyms, irela->r_offset,
sec_name ? sec_name : sec->name);
if (sec_name)
free (sec_name);
_bfd_default_error_handler then would process any %B or %S in the format
string, and pass a substituted format string on to vfprint. There is
some nastiness with this approach, since you need to expand "%" in any
substitutions to "%%".
Comments?
--
Alan Modra
IBM OzLabs - Linux Technology Centre
More information about the Binutils
mailing list