[PATCH] D49383: [cfi-verify] Add an option to treat calls to a specified function as traps.

Evgenii Stepanov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 24 15:21:59 PDT 2018


eugenis added a comment.

It would be really nice for llvm object library to support PLT detection/parsing.

Just for cfi-verify tool, we can cheat and link with -Wl,-emit-relocs. We already rely on line tables to tell data from code, so the tool does not work on fully stripped production executables anyway.



================
Comment at: tools/llvm-cfi-verify/lib/FileAnalysis.cpp:563
+  // We begin by finding the base address of the PLT.
+  if (!TrapName.endswith("@plt"))
+    return make_error<StringError>("Could not find trap function",
----------------
TrapName should be just a function name.
"@plt" is assembly convention, the user of the tool should not care whether the call is local or external.


================
Comment at: tools/llvm-cfi-verify/lib/FileAnalysis.cpp:576
+  // This section has the same order as the PLT, so if we find it, we can
+  // compute its offset from the base address of the PLT.
+  const object::SectionRef *RelaPLT =
----------------
I'm not sure you can rely on the order of these sections being the same.

Generally speaking, you need to disassemble each PLT entry and find the indirect branch instruction that points to the address of the corresponding .rela.plt relocation.

This sounds complicated, but there are only a few _recommended_ PLT instruction sequences, usually found in SYSV architecture supplement documents.

Maybe relying on .rela.plt order is not such a bad idea after all, provided that all linkers behave the same way.


================
Comment at: tools/llvm-cfi-verify/lib/FileAnalysis.cpp:580
+        StringRef Str;
+        return !Section.getName(Str) && Str == ".rela.plt";
+      });
----------------
.rela.plt can be found by DT_JMPREL entry in dynamic section.

It's very uncommon, but the section table can be stripped from the binary.


Repository:
  rL LLVM

https://reviews.llvm.org/D49383





More information about the llvm-commits mailing list