[PATCH] D152344: [RelocationResolver] Support new LoongArch relocs

WÁNG Xuěruì via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 7 00:00:50 PDT 2023


xen0n created this revision.
xen0n added reviewers: SixWeining, wangleiat, MaskRay, xry111.
Herald added subscribers: s.egerton, simoncook, asb, hiraditya.
Herald added a project: All.
xen0n requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead.
Herald added a project: LLVM.

Support for applicable LAELF v20230519 relocs are added, minus the
couple of ULEB128 relocs that cannot be supported with the current API:
a buffer or stream is required to be able to decode/encode LEB128
values, while currently only LocData is available which is just an
integer.

A previous oversight that led to always-zero LocData for LoongArch is
also fixed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152344

Files:
  llvm/lib/Object/RelocationResolver.cpp


Index: llvm/lib/Object/RelocationResolver.cpp
===================================================================
--- llvm/lib/Object/RelocationResolver.cpp
+++ llvm/lib/Object/RelocationResolver.cpp
@@ -539,6 +539,9 @@
   case ELF::R_LARCH_32:
   case ELF::R_LARCH_32_PCREL:
   case ELF::R_LARCH_64:
+  case ELF::R_LARCH_64_PCREL:
+  case ELF::R_LARCH_ADD6:
+  case ELF::R_LARCH_SUB6:
   case ELF::R_LARCH_ADD8:
   case ELF::R_LARCH_SUB8:
   case ELF::R_LARCH_ADD16:
@@ -548,6 +551,11 @@
   case ELF::R_LARCH_ADD64:
   case ELF::R_LARCH_SUB64:
     return true;
+  case ELF::R_LARCH_ADD_ULEB128:
+  case ELF::R_LARCH_SUB_ULEB128:
+    // TODO: Cannot be supported with the current API: LEB128 requires a
+    // stream for I/O.
+    return false;
   default:
     return false;
   }
@@ -564,6 +572,12 @@
     return (S + Addend - Offset) & 0xFFFFFFFF;
   case ELF::R_LARCH_64:
     return S + Addend;
+  case ELF::R_LARCH_64_PCREL:
+    return S + Addend - Offset;
+  case ELF::R_LARCH_ADD6:
+    return (LocData & 0xC0) | (((LocData & 0x3F) + (S + Addend)) & 0x3F);
+  case ELF::R_LARCH_SUB6:
+    return (LocData & 0xC0) | (((LocData & 0x3F) - (S + Addend)) & 0x3F);
   case ELF::R_LARCH_ADD8:
     return (LocData + (S + Addend)) & 0xFF;
   case ELF::R_LARCH_SUB8:
@@ -880,8 +894,10 @@
 
       if (GetRelSectionType() == ELF::SHT_RELA) {
         Addend = getELFAddend(R);
-        // RISCV relocations use both LocData and Addend.
-        if (Obj->getArch() != Triple::riscv32 &&
+        // LoongArch and RISCV relocations use both LocData and Addend.
+        if (Obj->getArch() != Triple::loongarch32 &&
+            Obj->getArch() != Triple::loongarch64 &&
+            Obj->getArch() != Triple::riscv32 &&
             Obj->getArch() != Triple::riscv64)
           LocData = 0;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152344.529191.patch
Type: text/x-patch
Size: 1799 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230607/3d6edaf0/attachment.bin>


More information about the llvm-commits mailing list