Re: [PATCH v2 4/6] Makerules: Make the .dt to .d conversion safe against concurrent sub-makes

Sam James <[email protected]> Thu, 06 Aug 2026 19:05:18 +0100
Newsgroups gmane.comp.lib.glibc.alpha
Organization Gentoo
Message-ID <[email protected]>
Adhemerval Zanella <[email protected]> writes:

> The %.d: %.dt rule seds its input into a fixed temporary name, renames
> it into place and removes the input.  Two makes converting the same
> file trip over each other:
>
>   mv: cannot stat '.../test-double-libmvec-sincos-avx512f.o.T': No such file or directory
>   sed: can't read .../test-float-libmvec-acosf-avx512f.o.dt: No such file or directory
>
> That happens because the elf rtld-Rules recursion runs a sub-make over
> every $(rtld-subdirs) directory, which converts that directory's .dt
> files, and the parallel subdirectory recursion (commit 7cac99621e96)
> runs it concurrently with those subdirectories' own sub-makes.
>
> Add the PID of the shell to the temporary name and claim the input with
> a rename: only the run that wins converts and installs the target.

Reviewed-by: Sam James <[email protected]>

> ---
>  Makerules | 18 ++++++++++++++----
>  1 file changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/Makerules b/Makerules
> index 5f65f3ab9ee..be51154bae4 100644
> --- a/Makerules
> +++ b/Makerules
> @@ -758,10 +758,20 @@ all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
>  	     $(wildcard $(all-dt-files:.dt=.d))
>  
>  # This is a funny rule in that it removes its input file.
> +#
> +# More than one make can convert the .dt files of a single object
> +# directory: the elf rtld-Rules recursion runs a sub-make over every
> +# $(rtld-subdirs) directory, concurrently with that directory's own
> +# sub-make under the parallel subdir recursion.  Add the PID of the
> +# shell to the temporary name and claim the input with a rename: only
> +# the run that wins converts and installs the target.
>  %.d: %.dt
> -	@sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
> -	 mv -f $(@:.d=.T) $@ && \
> -	 rm -f $<
> +	@dt=$(@:.d=.T)$$$$; \
> +	 if mv -f $< $$dt 2>/dev/null; then \
> +	   sed $(sed-remove-objpfx) $$dt > $$dt.new && \
> +	   mv -f $$dt.new $@ && \
> +	   rm -f $$dt; \
> +	 fi
>  
>  # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
>  # They will be generated when they're needed, and trying too early won't work.
> @@ -1433,7 +1443,7 @@ endef
>  # Also remove the dependencies and generated source files.
>  common-clean: common-mostlyclean
>  	-rm -f $(addprefix $(objpfx),$(generated))
> -	-rm -f $(objpfx)*.d $(objpfx)*.dt
> +	-rm -f $(objpfx)*.d $(objpfx)*.dt $(objpfx)*.T[0-9]*
>  	-rm -fr $(addprefix $(objpfx),$(generated-dirs))
>  	-rm -f $(addprefix $(common-objpfx),$(common-generated))
>  	-rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
signature.asc (application/pgp-signature, 418 B)
-----BEGIN PGP SIGNATURE-----

iQEBBAEWCgCpFiEEJaa7iN2bdkxrVUHCc4QJ9SDfkZAFAmp0zN4bFIAAAAAABAAO
bWFudTIsMi41KzEuMTIsMiwyXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25z
Lm9wZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQyNUE2QkI4OEREOUI3NjRDNkI1NTQx
QzI3Mzg0MDlGNTIwREY5MTkwDxxzYW1AZ2VudG9vLm9yZwAKCRBzhAn1IN+RkGW1
AP9JCZYQmH3q17F07AWlkCiiy8ko19Ke4hA+SLNHacOv9AD+NrbzY8fU3Rr+2qVa
icxFdTrArcRfGetuyBVRYgP5WAA=
=NgHK
-----END PGP SIGNATURE-----