-Cllvm-args
usability improvement by ldm0 · Pull Request #115638 · rust-lang/rust (original) (raw)
Two problems were found during playing with -Cllvm-args
- When
llvm.link-shared
is set tofalse
inconfig.toml
, output ofrustc -C llvm-args='--help-list-hidden'
doesn't contain--emit-dwarf-unwind
and--emulated-tls
. When it is set totrue
,rustc -C llvm-args='--help-list-hidden'
emits--emit-dwarf-unwind
, but--emulated-tls
is still missing. - Setting
-Cllvm-args=--emit-dwarf-unwind=always
doesn't take any effect, but-Cllvm-args=-machine-outliner-reruns=3
does work.
1
Adding RegisterCodeGenFlags
to register codegen flags fixed the first problem. rustc -C llvm-args='--help-list-hidden'
emits full codegen flags including --emit-dwarf-unwind
and --emulated-tls
.
2
Constructing TargetOptions
from InitTargetOptionsFromCodeGenFlags
in LLVMRustCreateTargetMachine
fixed the second problem. The LLVMRustSetLLVMOptions
calls ParseCommandLineOptions
which parses given llvm-args
. For options like machine-outliner-reruns
, it just works, since the codegen logic directly consumes the parsing result:
machine-outliner-reruns register
machine-outliner-reruns consumption
But for flags defined in TargetOptions
and MCTargetOptions
to take effect, constructing them with InitTargetOptionsFromCodeGenFlags
is essential, or the parsing result is just not consumed. Similar patterns can be observed in lli, llc, etc.