[PATCH v3 11/18] BFD: Correct archive format determination for non-default link emulations
Maciej W. Rozycki
macro@redhat.com
Tue Jan 13 01:42:26 GMT 2026
On Wed, 10 Dec 2025, Alan Modra wrote:
> > > Looks plausible to me, but given the history could really do with Alan also
> > > taking a look. And of course ...
> >
> > FWIW I yet want to go back to the place of the segmentation fault and add
> > an assertion there, as it's a format mismatch case, i.e. an a.out handler
> > handed an ELF BFD, which is obviously not a user error. Somehow it didn't
> > struck me right away to do that. It can/will be a change on its own of
> > course.
>
> I think we should keep the target_defaulted test. The idea being that
> if a user supplies a target, then that should be only target allowed.
So far so good.
> The problem in this case is that ld does set the target (via
> ldlang.c:3714 s->input_statement.target = current_target), and that
> goes back to commit 2fa0b342a5cd in 1991. So a better solution might
> be to change the test to
>
> if ((abfd->target_defaulted || abfd->is_linker_input)
> && bfd_has_map (abfd))
I think the problem here is that LD also sets the input target in the
absence of any explicitly setting supplied by the user, in which case I
think no default target ought to be implied. Then such hacks wouldn't be
needed in BFD anymore. But that would require a code audit and a rewrite
large enough I'd rather not do on this occasion. So I agree that sticking
to the hacks is probably the most efficient approach to move forwards.
> That does happen to fix the segfault. Even if it didn't, a new
> test that exposes a segfault in the aout backend due to code using
> aout target data before testing that the bfd was actually aout, is
> fine.
Included in v4, as 05/15.
Maciej
More information about the Binutils
mailing list