[llvm] 03ed35b - Updates and adds tests for i386/ELF JITLink backend

Kshitij Jain via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 24 18:06:47 PST 2022


Author: Kshitij Jain
Date: 2022-12-25T02:06:09Z
New Revision: 03ed35b111a703b600fd5619552a93992afdf81b

URL: https://github.com/llvm/llvm-project/commit/03ed35b111a703b600fd5619552a93992afdf81b
DIFF: https://github.com/llvm/llvm-project/commit/03ed35b111a703b600fd5619552a93992afdf81b.diff

LOG: Updates and adds tests for i386/ELF JITLink backend

This CR modifies the existing 32 bit pcrel relocation test to
include the case when the relocation target might be present at
a smaller address than the address of the location that needs to be
patched.

Additionally, it adds a test for 16 bit absolute relocation.

Reviewed By: sunho

Differential Revision: https://reviews.llvm.org/D138372

Added: 
    llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_absolute_relocations_16.s

Modified: 
    llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_absolute_relocations_32.s
    llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_pc_relative_relocations_32.s

Removed: 
    


################################################################################
diff  --git a/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_absolute_relocations_16.s b/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_absolute_relocations_16.s
new file mode 100644
index 000000000000..47142c4be3c0
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_absolute_relocations_16.s
@@ -0,0 +1,25 @@
+# RUN: llvm-mc -triple=i386-unknown-linux-gnu -filetype=obj --show-encoding --show-inst -o %t.o %s
+# RUN: llvm-jitlink -noexec \
+# RUN:   -slab-allocate 1Kb -slab-address 0x1 -slab-page-size 4096 \
+# RUN:   -abs external_data=0x32 \
+# RUN:   -check %s %t.o
+#
+# Test ELF 16 bit absolute relocations
+
+        .text
+        .code16 
+
+        .globl  main     
+        .align        2, 0x90
+        .type   main, at function
+main:      
+        ret
+        .size   main, .-main
+
+# jitlink-check: decode_operand(bar, 0) = external_data
+        .globl  bar
+        .align        2, 0x90
+        .type   bar, at function
+bar:
+        retw    $external_data
+        .size   bar, .-bar
\ No newline at end of file

diff  --git a/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_absolute_relocations_32.s b/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_absolute_relocations_32.s
index 40cb8d4147fd..e4b02a794bbc 100644
--- a/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_absolute_relocations_32.s
+++ b/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_absolute_relocations_32.s
@@ -1,25 +1,23 @@
 # RUN: llvm-mc -triple=i386-unknown-linux-gnu -filetype=obj -o %t.o %s
-# RUN: llvm-jitlink -noexec %t.o
+# RUN: llvm-jitlink -noexec \
+# RUN:   -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
+# RUN:   -abs external_data=0x100 \
+# RUN:   -check %s %t.o
+
+# Test ELF 32 bit absolute relocations
 
         .text
-        .globl  main
-        .p2align        4
+        .globl  main     
+        .p2align        4, 0x90
         .type   main, at function
-main:
-    pushl   %ebp
-    movl    %esp, %ebp
-    pushl   %eax
-    movl    $0, -4(%ebp)
-    movl    a, %eax
-    addl    $4, %esp
-    popl    %ebp
-    retl
-
+main:                                   
+        retl
         .size   main, .-main
 
-        .data
-        .p2align        2
-        .type   a, at object
-a:
-        .long   42
-        .size   a, 4
\ No newline at end of file
+# jitlink-check: decode_operand(foo, 0) = external_data
+        .globl  foo     
+        .p2align        4, 0x90
+        .type   foo, at function
+foo:
+        movl    external_data, %eax
+        .size   foo, .-foo
\ No newline at end of file

diff  --git a/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_pc_relative_relocations_32.s b/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_pc_relative_relocations_32.s
index 38be68a8d46b..df74c7bb3932 100644
--- a/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_pc_relative_relocations_32.s
+++ b/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_pc_relative_relocations_32.s
@@ -1,31 +1,49 @@
 # RUN: llvm-mc -triple=i386-unknown-linux-gnu -filetype=obj -o %t.o %s
-# RUN: llvm-jitlink -noexec %t.o
+# RUN: llvm-jitlink -noexec \
+# RUN:     -check %s %t.o
+#
+# Test ELF 32 bit pc relative relocations
 
         .text
-        .section        .text.main
+
         .globl  main
         .p2align        4
         .type   main, at function
 main:
-    pushl   %ebp
-    movl    %esp, %ebp
-    subl    $8, %esp
-    movl    $0, -4(%ebp)
-    calll   foo
-    addl    $8, %esp
-    popl    %ebp
     retl
-
         .size   main, .-main
 
-        .section        .text.foo
+
+# Tests PC relative relocation for positive offset from PC
+# jitlink-check: decode_operand(bar, 0) = foo - next_pc(bar)
+
+        .globl  bar
+        .p2align        4
+        .type   bar, at function
+bar:
+    calll foo
+    .size       bar, .-bar
+
+        .globl  foo
         .p2align        4
         .type   foo, at function
 foo:
-    pushl   %ebp
-    movl    %esp, %ebp
-    movl    $42, %eax
-    popl    %ebp
     retl
+    .size       foo, .-foo
 
-    .size       foo, .-foo
\ No newline at end of file
+
+# Tests PC relative relocation for negative offset from PC
+# jitlink-check: decode_operand(baz, 0) = fooz - next_pc(baz)
+        .globl  fooz
+        .p2align        4
+        .type   fooz, at function
+fooz:
+    retl
+        .size   fooz, .-fooz
+
+        .globl  baz
+        .p2align        4
+        .type   baz, at function
+baz:
+    calll fooz
+        .size       baz, .-baz
\ No newline at end of file


        


More information about the llvm-commits mailing list