Have you tried replacing basename() with libiberty's new lbasename()? lbasename() always returns a pointer to the string you give it, which shouldn't be clobbered unless someone renames a bfd. If that works, it would be a preferrable solution.