I ran across this when cross building LLVM for riscv64. I have qemu-riscv64 installed, and can thus run riscv64 binaries on my stock X86 linux system. However, I need the QEMU_LD_PREFIX set so that dynamic loading works properly. llvm-lit currently isolates tests from the environment which exists at launch, and thus tests run through LIT were always failing. This change pulls all of the QEMU configuration variables from the environment and passes them through to the test so that qemu-user can successfully run the binaries.
I do want to note that test-suite has a wrapper script mechanism (TEST_SUITE_RUN_UNDER) I could implement in LLVM to solve this instead. I prefer this approach, but the other is also possible.
Even with this, ninja check-llvm doesn't yet work. There's another layer of environmental isolation somewhere that I haven't tracked down.
If we decide this is the right direction, we will need similar changes to other config files (e.g. test suite). I'll hold off posting them until we've confirmed this is the right direction.