[PATCH/BUG] ld/Makefile.am: missing dependency on ldscripts/stamp for e%.c target

Alan Modra amodra@gmail.com
Sun Aug 16 03:05:02 GMT 2026


On Sat, Aug 15, 2026 at 12:51:26PM +0200, A B C wrote:
> Hi everyone,
> 
> While working on adding a new target/architecture to GNU ld, I ran into a
> build issue where genscripts.sh fails with errors like:
> Plaintext
> 
> ../../ld/genscripts.sh: line 322: ldscripts/elf32simplecpu.xr: No such
> file or directory
> cat: ldscripts/dyntmp.73640: No such file or directory
> sed: can't read ldscripts/elf32simplecpu.x: No such file or directory

You neglected to add your new target to ALL_EMULATION_SOURCES, no
other changes needed.

> *Issue Description:* The failure happens because the ldscripts/ directory
> does not exist at the time genscripts.sh is executed. Because the output
> files cannot be created in ldscripts/, the resulting C variables in
> e${EMULATION_NAME}.c end up empty/corrupted (e.g. generating broken
> statements like return ; instead of returning the script string), which
> subsequently fails during C compilation.
> 
> *Root Cause:* In ld/Makefile.am, the rule responsible for generating
> emulation C sources:
> Makefile
> 
> e%.c:
> 	$(AM_V_GEN)${GENSCRIPTS} $* "$(tdir_$*)"
> 
> does not explicitly depend on ldscripts/stamp (or $(GEN_DEPENDS)).
> Consequently, under certain conditions (such as parallel builds with make -j
> or when adding a custom target before running a full re-configuration),
> Make attempts to run genscripts.sh before the rule creating ldscripts/ has
> been executed.
> 
> *Proposed Fix:* Adding $(GEN_DEPENDS) or ldscripts/stamp as a prerequisite
> for e%.c ensures the destination directory is always created beforehand:
> Makefile
> 
> e%.c: $(GEN_DEPENDS)
> 	$(AM_V_GEN)${GENSCRIPTS} $* "$(tdir_$*)"
> 
> Alternatively, ensuring genscripts.sh implicitly creates ldscripts/ before
> attempting file redirections could also prevent this failure.
> 
> Thanks for your time and for maintaining Binutils!
> 
> Best regards,
> 
> Daniel

-- 
Alan Modra


More information about the Binutils mailing list