[llvm] 23b2fbf - [LoongArch] Port over minimal applyFixup from RISCV

Weining Lu via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 26 02:59:14 PDT 2022


Author: WANG Xuerui
Date: 2022-08-26T17:36:29+08:00
New Revision: 23b2fbf9ecf6c7f5ed22cf65ff1cd34f5ac6e7a0

URL: https://github.com/llvm/llvm-project/commit/23b2fbf9ecf6c7f5ed22cf65ff1cd34f5ac6e7a0
DIFF: https://github.com/llvm/llvm-project/commit/23b2fbf9ecf6c7f5ed22cf65ff1cd34f5ac6e7a0.diff

LOG: [LoongArch] Port over minimal applyFixup from RISCV

Many DebugInfo tests now pass with native builds.

Differential Revision: https://reviews.llvm.org/D132323

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index dc98475267137..f9a024f57ae3e 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -73,8 +73,27 @@ void LoongArchAsmBackend::applyFixup(const MCAssembler &Asm,
                                      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;
+  if (!Value)
+    return; // Doesn't change encoding.
+
+  MCFixupKind Kind = Fixup.getKind();
+  if (Kind >= FirstLiteralRelocationKind)
+    return;
+  MCFixupKindInfo Info = getFixupKindInfo(Kind);
+  // 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,


        


More information about the llvm-commits mailing list