[PATCH] D132323: [LoongArch] Port over minimal applyFixup from RISCV

WÁNG Xuěruì via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 20 18:48:47 PDT 2022


xen0n created this revision.
xen0n added reviewers: SixWeining, wangleiat, gonglingqin, MaskRay, xry111.
Herald added subscribers: sunshaoce, VincentWu, luke957, StephenFan, vkmr, evandro, luismarques, sameer.abuasal, s.egerton, Jim, benna, psnobl, rogfer01, shiva0217, kito-cheng, simoncook, hiraditya, arichardson.
Herald added a project: All.
xen0n requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD.
Herald added a project: LLVM.

Many DebugInfo tests now pass with native builds.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132323

Files:
  llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp


Index: llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
===================================================================
--- llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -73,8 +73,26 @@
                                      MutableArrayRef<char> Data, uint64_t Value,
                                      bool IsResolved,
                                      const MCSubtargetInfo *STI) const {
-  // TODO: Apply the Value for given Fixup into the provided data fragment.
-  return;
+  MCFixupKind Kind = Fixup.getKind();
+  if (Kind >= FirstLiteralRelocationKind)
+    return;
+  MCFixupKindInfo Info = getFixupKindInfo(Kind);
+  if (!Value)
+    return; // Doesn't change encoding.
+  // TODO: Apply any target-specific value adjustments.
+
+  // Shift the value into position.
+  Value <<= Info.TargetOffset;
+
+  unsigned Offset = Fixup.getOffset();
+  unsigned NumBytes = alignTo(Info.TargetSize + Info.TargetOffset, 8) / 8;
+
+  assert(Offset + NumBytes <= Data.size() && "Invalid fixup offset!");
+  // For each byte of the fragment that the fixup touches, mask in the
+  // bits from the fixup value.
+  for (unsigned I = 0; I != NumBytes; ++I) {
+    Data[Offset + I] |= uint8_t((Value >> (I * 8)) & 0xff);
+  }
 }
 
 bool LoongArchAsmBackend::shouldForceRelocation(const MCAssembler &Asm,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132323.454267.patch
Type: text/x-patch
Size: 1406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220821/c3d66115/attachment.bin>


More information about the llvm-commits mailing list