The %b substitution is at
gcc\gcc.cc:6161
case 'b':
/* Don't use %b in the linker command. */
#ifndef __OS2__ /* this causes 'internal compiler error: in do_spec_1, at gcc.c:6063' with GCC 11.x - dunno why - FIXME */
gcc_assert (suffixed_basename_length);
#endif
if (!this_is_output_file && dumpdir_length)
obstack_grow (&obstack, dumpdir, dumpdir_length);
if (this_is_output_file || !outbase_length)
obstack_grow (&obstack, input_basename, basename_length);
else
obstack_grow (&obstack, outbase, outbase_length);
We don't have source debug in this part of the code, but I can see the incorrect insertion into the obstack. This is probably the dumpdir value. The specs docs imply that we need a %w to have this_is_output_file set.
I'm thinking that if outbase is set correctly, editing the built-in specs to add a %w before the %b might be the fix.
For 9.2.0, the code is quite different.
gcc\gcc.c:5333
case 'b':
if (save_temps_length)
obstack_grow (&obstack, save_temps_prefix, save_temps_length);
else
obstack_grow (&obstack, input_basename, basename_length);
if (compare_debug < 0)
obstack_grow (&obstack, ".gk", 3);
arg_going = 1;
break;
Hopefully, this will save you some time.