[PATCH] ld: Issue an error for recursively included linker script

H.J. Lu hjl.tools@gmail.com
Thu Aug 14 15:47:20 GMT 2025


On Thu, Aug 14, 2025 at 8:26 AM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 14.08.2025 17:05, H.J. Lu wrote:
> > When a linker script is included recursively by mistake, issue an error
> > instead of hang forever without outputting any error message.
> >
> >       PR ld/33265
> >       * ldfile.c (opened_scripts): New.
> >       (ldfile_try_open_bfd): After reading a linker script, clear the
> >       opened linker script list and free its memory.
> >       (ldfile_find_command_file): Issue a fatal error when the linker
> >       script is included recursively.  Add the linker script to the
> >       linked list of opened linker scripts.
> >       * testsuite/ld-scripts/libpr33265-1.a: New file.
> >       * testsuite/ld-scripts/libpr33265-2.a: Likewise.
> >       * testsuite/ld-scripts/pr33265-1.d: Likewise.
> >       * testsuite/ld-scripts/pr33265-2.d: Likewise.
> >       * testsuite/ld-scripts/script.exp: Run PR ld/33265 tests.
> >
> > Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
>
> Is this a v2, or merely a re-submission of v1 (for whatever reason)? In
> any event, my prior question ...

It is a rebase.  It should be v2.

> > @@ -475,6 +480,11 @@ ldfile_try_open_bfd (const char *attempt,
> >                 ldfile_assumed_script = false;
> >                 fclose (yyin);
> >                 yyin = NULL;
> > +
> > +               /* After reading a linker script, clear the opened
> > +                  linker script list and free its memory.  */
> > +               ldfile_script_free (&opened_scripts);
>
> ... here remains: We can't get here recursively, in which case - aiui -
> the freeing would happen too early?

True, we won't get there recursively since a recursion will cause a fatal
error before we get here.  The opened script list only applies to
the linker script file we are currently reading.  After closing the file,
the opened script list is no longer valid and should be freed.

> Jan



-- 
H.J.


More information about the Binutils mailing list