[PATCH] D29445: LTO: add a code-model flag

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 3 08:57:51 PST 2017


pcc added a comment.

In https://reviews.llvm.org/D29445#665750, @martell wrote:

> In https://reviews.llvm.org/D29445#664931, @pcc wrote:
>
> > I believe that in both linkers we can just write `Config->CodeModel = CMModel;` which would use the existing flag in CommandFlags.h.
>
>
> I believe this could be useful for setting the default.
>
> Example:
>
>   llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
>   ld.lld %t -o %t2
>
>
> This would result in the code model being what `CMModel` was set for `x86_64-unknown-linux`
>
> I would like to ask
>  What happens in the following scenario?
>
>   clang -target=x86_64-unknown-linux -mcmodel=large %s -o %t
>   ld.lld %t -o %t2
>
>
> Will `CMModel` be the default for that target like above or is the large model information in the object there for the linker to infer?


I don't think the code model information will be passed correctly from the compiler to the linker in that case. `CMModel` will be the value of the existing `-code-model` flag, which will be `CodeModel::Default` by default (same as the default in `lto::Config`, see http://llvm-cs.pcc.me.uk/include/llvm/CodeGen/CommandFlags.h#81). You can pass it to lld with (e.g.) `-mllvm -code-model=large` or to gold with `-plugin-opt -code-model=large`.

If we wanted to pass the code model from the compiler to the linker, I think we would need to introduce a function attribute that controls the code model. The compiler would apply the attribute to every function in the translation unit and it would make it to the linker via bitcode.


https://reviews.llvm.org/D29445





More information about the llvm-commits mailing list