[llvm] 32f514c - [JITLink][i386] Support R_386_GOT32X using existing non-relaxable edge kind.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed May 7 17:07:51 PDT 2025


Author: Lang Hames
Date: 2025-05-08T10:07:44+10:00
New Revision: 32f514c68d78530f7d7adee883e1b4fc8dd1e9fd

URL: https://github.com/llvm/llvm-project/commit/32f514c68d78530f7d7adee883e1b4fc8dd1e9fd
DIFF: https://github.com/llvm/llvm-project/commit/32f514c68d78530f7d7adee883e1b4fc8dd1e9fd.diff

LOG: [JITLink][i386] Support R_386_GOT32X using existing non-relaxable edge kind.

R_386_GOT32 was already handled by lowering to
EdgeKind_i386::RequestGOTAndTransformToDelta32FromGOT. R_386_GOT32X is just an
optionally relaxable version of R_386_GOT32, so we can lower to the same edge
kind.

I've left a TODO to add a relaxable edge kind and update the i386 relaxation
optimization in the future, though I'll probably leave this as an exercise for
any i386 aficionados out there. ;)

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp
    llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_small_pic_relocations_got.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp
index 1273dc1481c35..6e9f6ed40ec8c 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp
@@ -129,6 +129,9 @@ class ELFLinkGraphBuilder_i386 : public ELFLinkGraphBuilder<object::ELF32LE> {
       return EdgeKind_i386::PCRel16;
     case ELF::R_386_GOT32:
       return EdgeKind_i386::RequestGOTAndTransformToDelta32FromGOT;
+    case ELF::R_386_GOT32X:
+      // TODO: Add a relaxable edge kind and update relaxation optimization.
+      return EdgeKind_i386::RequestGOTAndTransformToDelta32FromGOT;
     case ELF::R_386_GOTPC:
       return EdgeKind_i386::Delta32;
     case ELF::R_386_GOTOFF:

diff  --git a/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_small_pic_relocations_got.s b/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_small_pic_relocations_got.s
index 080341ac3bfed..d4cf7090b7dc0 100644
--- a/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_small_pic_relocations_got.s
+++ b/llvm/test/ExecutionEngine/JITLink/i386/ELF_i386_small_pic_relocations_got.s
@@ -33,7 +33,28 @@ test_got:
         leal    named_data2 at GOT+5, %eax
         .size   test_got, .-test_got
 
+# Test R_386_GOT32X handling.
+#
+# We want to check both the offset to the GOT entry and its contents.
+# jitlink-check: decode_operand(test_gotx_load, 4) = got_addr(elf_sm_pic_reloc_got.o, named_data1) - _GLOBAL_OFFSET_TABLE_
+# jitlink-check: *{4}(got_addr(elf_sm_pic_reloc_got.o, named_data1)) = named_data1
 
+        .globl test_gotx
+        .p2align      4, 0x90
+        .type   test_gotx, at function
+test_gotx:
+	calll	.L0$pb
+.L0$pb:
+	popl	%eax
+.Ltmp0:
+	addl	$_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %eax
+        .globl test_gotx_load
+test_gotx_load:
+	movl	named_data1 at GOT(%eax), %eax
+        .size   test_gotx_load, .-test_gotx_load
+	movl	(%eax), %eax
+	retl
+        .size   test_gotx, .-test_gotx
 
 # Test GOTOFF64 handling.
 # jitlink-check: decode_operand(test_gotoff, 1) = named_func - _GLOBAL_OFFSET_TABLE_ + 99


        


More information about the llvm-commits mailing list