[lld] [llvm] [llvm-objdump][ARM] Find ELF file PLT entries for arm, thumb (PR #130764)

Vladislav Dzhidzhoev via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 13 05:23:50 PDT 2025


================
@@ -431,6 +431,112 @@ class ARMMCInstrAnalysis : public MCInstrAnalysis {
   std::optional<uint64_t>
   evaluateMemoryOperandAddress(const MCInst &Inst, const MCSubtargetInfo *STI,
                                uint64_t Addr, uint64_t Size) const override;
+
+  std::vector<std::pair<uint64_t, uint64_t>> findPltEntries(
+      uint64_t PltSectionVA, ArrayRef<uint8_t> PltContents,
+      const Triple &TargetTriple,
+      std::optional<llvm::endianness> InstrEndiannessHint) const override {
+    llvm::endianness DataEndianness =
+        TargetTriple.isLittleEndian() ? endianness::little : endianness::big;
+    llvm::endianness InstrEndianness =
+        InstrEndiannessHint.value_or(DataEndianness);
+
+    std::vector<std::pair<uint64_t, uint64_t>> Result;
+    // Do a lightweight parsing of PLT entries.
+    for (uint64_t Byte = 0, End = PltContents.size(); Byte + 12 < End;
+         Byte += 4) {
+      uint32_t InsnPart1 =
+          support::endian::read16(PltContents.data() + Byte, InstrEndianness);
+
+      // Is Thumb? Check for movw.
+      if ((InsnPart1 & 0xffb0) == 0xf200) {
+        uint32_t InsnPart2 = support::endian::read16(
+            PltContents.data() + Byte + 2, InstrEndianness);
+        if ((InsnPart2 & 0x8f00) != 0xc00)
+          continue;
+        uint64_t OffsetLower =
+            (InsnPart2 & 0xff) + ((InsnPart2 & 0x7000) >> 4) +
+            ((InsnPart1 & 0x400) << 1) + ((InsnPart1 & 0xf) << 12);
+        // Check for movt
+        uint32_t Insn2Part1 = support::endian::read16(
+            PltContents.data() + Byte + 4, InstrEndianness);
+        if ((Insn2Part1 & 0xfbf0) != 0xf2c0)
+          continue;
+        uint32_t Insn2Part2 = support::endian::read16(
+            PltContents.data() + Byte + 6, InstrEndianness);
+        if ((Insn2Part2 & 0x8f00) != 0xc00)
+          continue;
+        uint64_t OffsetHigher =
+            ((Insn2Part2 & 0xff) << 16) + ((Insn2Part2 & 0x7000) << 12) +
+            ((Insn2Part1 & 0x400) << 17) + ((Insn2Part1 & 0xf) << 28);
+
+        // Check for add
----------------
dzhidzhoev wrote:

Fixed. I did the same to check long entries.

https://github.com/llvm/llvm-project/pull/130764


More information about the llvm-commits mailing list