[PATCH] D141746: Fixes handling logic for i386/ELF GOTPC relocation

Kshitij Jain via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 13 19:21:36 PST 2023


jain98 created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
jain98 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The i386/ELF JITLink backend was not correctly handling the GOTPC relocation
by skipping the in-built addend, which was manifesting itself in the form of
a segmentation fault in the `LF_external_to_absolute_conversion.s` test. This
CR has fixed that issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141746

Files:
  llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp


Index: llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp
===================================================================
--- llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp
+++ llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp
@@ -11,14 +11,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/ExecutionEngine/JITLink/ELF_i386.h"
+#include "DefineExternalSectionStartAndEndSymbols.h"
 #include "ELFLinkGraphBuilder.h"
 #include "JITLinkGeneric.h"
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/ExecutionEngine/JITLink/i386.h"
 #include "llvm/Object/ELFObjectFile.h"
 
-#include "DefineExternalSectionStartAndEndSymbols.h"
-
 #define DEBUG_TYPE "jitlink"
 
 using namespace llvm;
@@ -180,9 +179,18 @@
     if (!Kind)
       return Kind.takeError();
 
+    auto FixupAddress = orc::ExecutorAddr(FixupSection.sh_addr) + Rel.r_offset;
     int64_t Addend = 0;
 
-    auto FixupAddress = orc::ExecutorAddr(FixupSection.sh_addr) + Rel.r_offset;
+    switch (*Kind) {
+    case i386::EdgeKind_i386::Delta32: {
+      const char *FixupContent = BlockToFix.getContent().data() +
+                                 (FixupAddress - BlockToFix.getAddress());
+      Addend = *(const support::ulittle32_t *)FixupContent;
+      break;
+    }
+    }
+
     Edge::OffsetT Offset = FixupAddress - BlockToFix.getAddress();
     Edge GE(*Kind, Offset, *GraphSymbol, Addend);
     LLVM_DEBUG({


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141746.489184.patch
Type: text/x-patch
Size: 1426 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230114/058c063d/attachment-0001.bin>


More information about the llvm-commits mailing list