[llvm-dev] ThinLTO: passing TargetOptions to LLVMgold.so

Mehdi Amini via llvm-dev llvm-dev at lists.llvm.org
Wed Oct 5 08:44:42 PDT 2016


> On Oct 5, 2016, at 3:20 AM, Johan Engelen via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> Hi all,
>   I am trying to figure out the best way to deal with non-default TargetMachine options when using ThinLTO with the LLVMgold.so plugin. (I'm adding support for ThinLTO to the LDC D compiler)
> 
> Things like the target triple, target CPU and target CPU features, some floating point options like unsafe-fp-math, etc., those are (or can be made) explicit in the IR. Is that the way to go? We currently don't emit some of them in the IR, but I see that Clang does, so perhaps we should just mimic that.

Yes, definitely. 

> But some other options are not expressed in IR (e.g. FunctionSections, relocation model).
> I see that I can pass LLVM options to the plugin, so one way is to pass all non-default options as plugin-opt cmdline flags. I can't find code in Clang that does that though.

The usual model is that the linker interacts with the LTO codegen to pass these options.

Assuming you’d link a program on MacOS with ThinLTO for instance, the linker will derive the “pic model” the following way: https://github.com/Apple-FOSS-Mirror/ld64/blob/master/src/ld/parsers/lto_file.cpp#L594 (not the call to ::lto_codegen_set_pic_model).

— 
Mehdi



More information about the llvm-dev mailing list