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

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 21 08:24:00 PDT 2018


tejohnson added inline comments.


================
Comment at: lib/IR/Module.cpp:522
+void Module::setCodeModel(CodeModel::Model CL) {
+  addModuleFlag(ModFlagBehavior::Error, "Code Model", CL);
+}
----------------
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. 


================
Comment at: test/LTO/X86/codemodel-3.ll:2
+; RUN: llvm-as %s -o %t0.o
+; RUN: llvm-as < %p/Inputs/codemodel-3.ll > %t1.o
+; RUN: not llvm-lto2 run -r %t0.o,_start,px -r %t1.o,bar,px %t0.o %t1.o -o %t2.s 2>&1 | FileCheck %s 
----------------
The Inputs/codemodel-3.ll file is missing from patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D52322





More information about the llvm-commits mailing list