Pass configuration flags to `cargo`
As of #2822 "Start reusing rustc's format_args parser", we invoke cargo to produce object files to be linked into GCC. We currently don't specify any compilation flags and linker to use, so it's easy to run into mismatches between what GCC is configured for (for example, specific linker), and what cargo uses by default (for example, system cc for linking).
For example, the linker may be specified: https://doc.rust-lang.org/cargo/reference/config.html#targettriplelinker -- but do we need the Rust target triple for that (see #2898)? Trying to use a cfg() expressions à la --config "target.'cfg(all())'.linker=[...]" only produces:
warning: unused key `linker` in [target] config table `cfg(all())`
(Maybe I've misunderstood how that is to be used.)
Next problem: the GCC $(LINKER) defaults to $(CXX), and doesn't just point to an executable, but may have "wrapper" executables prepended (ccache, for example), and also contain flags.
For a simple --config target.x86_64-unknown-linux-gnu.linker=\"'$(LINKER)'\", and LINKER = $(CXX), and CXX = ccache g++ [flags], we then get:
error: linker `[...]/build-gcc/gcc/ccache g++ [flags] ` not found
oh, that's really sad... any chance there's another make variable you haven't thought about which is just the linker binary and not the full invocation? it seems this is the offending line in my generated Makefile, which seems wrong (why not add it to LINKER_FLAGS?) but maybe I'm not thinking of something.
# Link with -no-pie since we compile the compiler with -fno-PIE.
LINKER += $(NO_PIE_FLAG)
It looks like target.<triple>.rustflags and link-args could be used to pass arguments to the linker. We could split $(LINKER) into an executable and argument list if need be.