Impossible to pass LLVM code generation flags in command line from driver invocation?

Hi folks,

I was trying to find a way to enable -addrsig for another compiler which uses LLVM as backend with no luck: the LLVM option parsing complain that it does not recognize -addrsig. Then I went back to try clang -mllvm -addrsig and surprisingly it gives back the same result:

clang (LLVM option parsing): Unknown command line argument '-addrsig'.  Try: 'clang (LLVM option parsing) --help'
clang (LLVM option parsing): Did you mean '--version'?

I have a few questions:

  1. Is it designed not to accept custom codegen options from command line? If not, is it possible to do so? Otherwise, support has to be done for other frontends (to make an -faddrsig-like driver option).

  2. Is it OK to enable -addrsig for other frontends by changing its default value for testing purpose, or special handling has to be done for different frontends?

Did you try -faddrsig which seems to be mapped to the backend option.

Yes, I know clang has such driver option, but I’m trying to enable the underlying codegen option for another frontend.

Searching clang/include/clang/Driver/Options.td for addrsig we see it is recorded in CodeGenOpts.Addrsig; this flag is propagated to the LLVM TargetOptions.EmitAddrsig in clang/lib/CodeGen/BackendUtil.cpp. So, if your frontend populates a TargetOptions to pass to LLVM, it can set that same field however you like.

The LLVM command-line tools (opt, llc, etc) will parse an -addrsig command line option, using codegen::InitTargetOptionsFromCodeGenFlags(). This is a utility function that is used by the various command-line tools (opt, llc) but not in LLVM proper. LLVM really wants you to set this via the TargetOption struct.