rustc_codegen_ssa: fix pre_link_args order #151165
Open
+8
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
We had an issue while compiling the linux kernel with a composite linker command in Yocto when activating the rust parts of the kernel.
Kernel Makefiles run rustc with
-Clinker=$(HOSTCC)(scripts/Makefile.host, rust/Makefile)But,
HOSTCCcan be something like<my-wrapper-tool> <my-cc-as-arg>(in our yocto caseccache gcc), which is incompatible with the way rustc handles-Clinker, it is handled as aPathBuf, used directly as aCommandname, but theCommandconstructor doesn't accept arguments.We could split
HOSTCCtoSTART_HOSTCCandEND_HOSTCCto do something like-Clinker=$(START_HOSTCC) -Zpre-link-args='$(END_HOSTCC)', but a rustc limitation occurs.Indeed, some linker arguments given by target files (ex:
-m64from a target file) and from the functionexport_symbols(ex:--no-undefined-versionhere) where added to the command before thepre-link-args.Therefore, we could end up with a generated call like
<my-wrapper-tool> -m64 <my-cc-as-arg> ...(in our caseccache -m64 gcc ...), which is broken.This PR mitigates this issue sorting pre-link-args calls before target files pre-link-args, and before the call to
export_symbols, which allow to use any wrapper tool around the actual linker.Please make me know if I should rewrite it in another way (a new argument parameter ? directly split the PathBuf into arguments ?).
I could write some tests if needed, but I'm not sure about the best way to test it in the repository.
Thanks for reading, regards,
Alban