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

Sriraman Tallam via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 20 16:17:26 PDT 2018


tmsriram added inline comments.


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



Repository:
  rL LLVM

https://reviews.llvm.org/D52322





More information about the llvm-commits mailing list