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

Jan Beulich jbeulich@suse.com
Thu Aug 14 15:26:47 GMT 2025


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 ...

> @@ -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?

Jan


More information about the Binutils mailing list