[PATCH] D29445: LTO: add a code-model flag
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 20 17:07:21 PST 2017
The large model should work if you create a non-PIC executable, rename
function to _start and provide a definition of the global. Then in your
test case link with small and large models and test for absence/presence of
movabs instruction.
Peter
On Feb 20, 2017 03:52, "Martell Malone via Phabricator" <
reviews at reviews.llvm.org> wrote:
martell added a comment.
In https://reviews.llvm.org/D29445#675329, @pcc wrote:
> It looks like you could adapt the test case `llvm/test/CodeGen/X86/
codemodel.ll`.
I created a test case based on `llvm/test/CodeGen/X86/codemodel.ll`
; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
; RUN: ld.lld -m elf_x86_64 %t.o -o %ts.so -mllvm -code-model=small
-shared
; RUN: ld.lld -m elf_x86_64 %t.o -o %tk.so -mllvm -code-model=kernel
-shared
; RUN: llvm-objdump -d %ts.so -o - | FileCheck %s --check-prefix=SMALL
; RUN: llvm-objdump -d %tk.so -o - | FileCheck %s --check-prefix=KERNEL
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-
i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-
v128:128:128-a0:0:64-s0:64:64-f80:128:128"
target triple = "x86_64-unknown-linux-gnu"
@data = external global [0 x i32] ; <[0 x i32]*> [#uses=5]
define i32 @foo() nounwind readonly {
entry:
; CHECK-SMALL-LABEL: foo:
; CHECK-SMALL: movl 4233(%rip), %eax
; CHECK-KERNEL-LABEL: foo:
; CHECK-KERNEL: movl 4233, %eax
%0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i64
0, i64 0), align 4 ; <i32> [#uses=1]
ret i32 %0
}
This is the result I am getting from the `llvm-objdump` stage
codemodels.so: file format ELF64-x86-64
Disassembly of section .text:
foo:
1000: 48 8b 05 89 10 00 00 movq 4233(%rip), %rax
1007: 8b 00 movl (%rax), %eax
1009: c3 retq
codemodelk.so: file format ELF64-x86-64
Disassembly of section .text:
foo:
1000: 48 8b 05 89 10 00 00 movq 4233(%rip), %rax
1007: 8b 00 movl (%rax), %eax
1009: c3 retq
The assumption I am making is that `llvm-as` only converts `llvm-ir` in a
text format to a binary format.
So as a result I should be able to use the code model passed after `-mllvm`
to decide what is generated.
I also tried changing the target to `i686` or `i386` with no joy.
Just for a test I did pass `-code-model=large` and I get errors
`ld.lld: error: ld-temp.o:(function foo): can't create dynamic relocation
R_X86_64_64 against symbol 'data' defined in codemodel.o`
this makes sense because of `@data = external global [0 x i32] ; <[0 x
i32]*> [#uses=5]`
Repository:
rL LLVM
https://reviews.llvm.org/D29445
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170220/23d7526a/attachment.html>
More information about the llvm-commits
mailing list