[PATCH] D50203: Find PLT entries for x86, x86_64, and AArch64

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 14 14:25:02 PDT 2018


pcc added inline comments.


================
Comment at: lib/Object/ELFObjectFile.cpp:357-368
+  const SectionRef *Plt = &*find_if(sections(), [&](const SectionRef &Sec) {
+    StringRef Name;
+    return !Sec.getName(Name) && Name == ".plt";
+  });
+  const SectionRef *RelaPlt = &*find_if(sections(), [&](const SectionRef &Sec) {
+    StringRef Name;
+    return !Sec.getName(Name) && (Name == ".rela.plt" || Name == ".rel.plt");
----------------
I don't think these `find_if` calls will do what you expect if the section is not found. In that case `find_if` will return the end iterator, and dereferencing it is UB.

I'd rewrite this as a single loop over `sections()`.


================
Comment at: lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp:171
+        continue;
+      Imm = (((PltSectionVA + Byte) >> 12) << 12) +
+            (((Insn >> 29) & 3) << 12) + (((Insn >> 5) & 0x3ffff) << 14);
----------------
Move the declaration of `Imm` onto this line.


================
Comment at: lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp:450
+    // Recognize a jmp followed by a push.
+    if (PltContents[Byte] == 0xff && PltContents[Byte + 1] == 0xa3 &&
+        PltContents[Byte + 6] == 0x68) {
----------------
jgalenson wrote:
> pcc wrote:
> > I think you also need to be able to decode the `0xff 0x25` form here, it's used in non-PIC executables.
> I extended the condition to handle that case.  But does anything else change with that form, or just these bits of the opcode?
`0xff 0x25` is similar to the equivalent 64-bit instruction, except that in 32-bit mode the immediate is not PC-relative. So I think you will need a separate block of code to handle it.


https://reviews.llvm.org/D50203





More information about the llvm-commits mailing list