[JITLink][x86-64] Implement ELF::R_X86_64_16.
authorLang Hames <lhames@gmail.com>
Sun, 16 Apr 2023 01:59:00 +0000 (01:59 +0000)
committerLang Hames <lhames@gmail.com>
Sun, 16 Apr 2023 02:00:16 +0000 (02:00 +0000)
We already had an x86_64::Pointer16 edge kind courtesy of Sunho's COFF/x86-64
work, it just needed to be wired up.

llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_16.s [new file with mode: 0644]

index fe9675b..692b161 100644 (file)
@@ -159,6 +159,9 @@ private:
     case ELF::R_X86_64_32:
       Kind = x86_64::Pointer32;
       break;
+    case ELF::R_X86_64_16:
+      Kind = x86_64::Pointer16;
+      break;
     case ELF::R_X86_64_32S:
       Kind = x86_64::Pointer32Signed;
       break;
diff --git a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_16.s b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_16.s
new file mode 100644 (file)
index 0000000..eff9ebb
--- /dev/null
@@ -0,0 +1,33 @@
+# RUN: llvm-mc -triple=x86_64-unknown-linux -position-independent \
+# RUN:     -filetype=obj -o %t.o %s
+# RUN: llvm-jitlink -noexec -abs X=0x1234 -check=%s %t.o
+# RUN: not llvm-jitlink -noexec -abs X=0x12345 %t.o 2>&1 | \
+# RUN:   FileCheck -check-prefix=CHECK-ERROR %s
+#
+# Check success and failure cases of R_X86_64_16 handling.
+
+# jitlink-check: *{8}P = X
+
+# CHECK-ERROR: relocation target "X" {{.*}} is out of range of Pointer16 fixup
+
+       .text
+       .section        .text.main,"ax",@progbits
+       .globl  main
+       .p2align        4, 0x90
+       .type   main,@function
+main:
+       xorl    %eax, %eax
+       retq
+.Lfunc_end0:
+       .size   main, .Lfunc_end0-main
+
+       .type   P,@object
+       .data
+       .globl  P
+       .p2align        1, 0x0
+P:
+       .short  X    # Using short here generates R_X86_64_16.
+       .short  0
+       .short  0
+       .short  0
+       .size   P, 8