[PATCH] D52322: Pass code-model through Module IR to LTO which will use is

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 21 08:34:59 PDT 2018


dexonsmith added inline comments.


================
Comment at: lib/IR/Module.cpp:522
+void Module::setCodeModel(CodeModel::Model CL) {
+  addModuleFlag(ModFlagBehavior::Error, "Code Model", CL);
+}
----------------
tejohnson wrote:
> tmsriram wrote:
> > dexonsmith wrote:
> > > Is this the correct linking behaviour for code model?  I.e., is it illegal to link two object files together that have different code models?
> > I believe it is undefined behavior to link two object files with different code models as the compiler has to generate additional code if a larger code model would be used.  As an example:
> > 
> > extern int *a;
> > int main() {
> >   return a[10];
> > }
> > 
> > $ clang a.cc -S -mcmodel=large && cat a.s
> > ...
> > 	movabsq	$a, %rax
> > 	movq	(%rax), %rax
> > 	movl	40(%rax), %eax
> > 	popq	%rbp
> > ..
> > 
> > $ clang a.cc -S -mcmodel=small && cat a.s
> > ...
> > 	movq	a, %rax
> > 	movl	40(%rax), %eax
> > 	popq	%rbp
> > 
> > The data would not be accessible with a 32-bit relocation for x86_64 and the compiler must explicitly handle this.  
> > 
> Presumably the largest could be picked for code generation, but if it is illegal to link 2 native objects with different code models then the question is why we should support linking to LTO IR objects with different code models. Also, not sure how something like -code-model=kernel interact with the -code-model=small/medium/large.
> 
> Unless otherwise shown that we need to mix and match different code models, I think Error is the right behavior. Suggest adding a comment summarizing why it is being treated as an Error. 
Agreed; if it's not correct for normal object files we should error here as in the patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D52322





More information about the llvm-commits mailing list