Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvm suggests invalid command #25819

Open
vks opened this Issue May 27, 2015 · 2 comments

Comments

Projects
None yet
6 participants
@vks
Copy link
Contributor

vks commented May 27, 2015

$ rustc dummy.rs -C llvm-args=xyz
rustc: Unknown command line argument 'xyz'.  Try: 'rustc -help'

It should be rustc --help or rustc -h.

@jooert

This comment has been minimized.

Copy link
Contributor

jooert commented May 27, 2015

The problem here is that rustc: Unknown command line argument 'xyz'. Try: 'rustc -help' is actually printed by LLVM (see src/llvm/lib/Support/CommandLine.cpp) which rustc calls with a faked program name (see src/librustc_trans/back/write.rs).

We could change CommandLine.cpp to print Try: 'rustc --help' but that won't help with the real issue as rustc --help doesn't print anything about valid arguments to LLVM. To get information about those you would have to call rustc dummy.rs -C llvm-args=-help (note that you cannot call rustc -C llvm-args=-help without an input file, which is pretty awkward, too).

@brson brson added the P-low label Apr 11, 2017

@Mark-Simulacrum Mark-Simulacrum changed the title rustc suggests invalid command llvm suggests invalid command Jun 20, 2017

@Mark-Simulacrum Mark-Simulacrum added C-bug and removed I-wrong labels Jul 22, 2017

@mark-i-m

This comment has been minimized.

Copy link
Contributor

mark-i-m commented Jan 2, 2019

I played around with this a little, but didn't get very far because of my lack of expertise in how codegen is called. Here's an update for the next person that comes along:

  • The offending message is produced from LLVM's argument parser
    • src/llvm/lib/Support/CommandLine.cpp in ParseCommandLineOptions.
  • Everything else is unchanged from #25819 (comment)
  • It would be great if the fix didn't have to involve landing a patch in LLVM.
  • One fix is to add a rustc flag --llvm-help that calls LLVM with the -help flag. Unfortunately, this is hard because the codegen backend is not initialized until after we have parsed flags and handled stuff like --help.
    • Help/usage messages are printed in handle_options in src/librustc_driver/lib.rs which is called from run_compiler (same file).
    • run_compiler calls run_compiler_with_pool after handle_options is done.
    • run_compiler_with_pool builds a whole compiler Session first before building and initializing the codegen backend with get_codegen_backend.
    • get_codegen_backend calls backend.init(&sess) which eventually calls configure_llvm in src/librustc_codegen_llvm/llvm_util.rs`
    • configure_llvm makes the FFI call llvm::LLVMRustSetLLVMOptions which calls the parser in LLVM (in C++)...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.