[PATCH] D55629: [elfabi] Add support for reading DT_SONAME from binaries

Jake Ehrlich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 3 17:05:34 PST 2019


jakehehrlich requested changes to this revision.
jakehehrlich added a comment.
This revision now requires changes to proceed.

As discussed offline I realized I missed something.



================
Comment at: llvm/test/tools/llvm-elfabi/binary-read-zero-dt-strtab.test:35-37
+  - Type: PT_LOAD
+    VAddr: 0x0000
+    PAddr: 0x0000
----------------
Also this has no size, it should cover the whole PT_DYNAMIC and the string table. There isn't a way to start the offset in zero in yaml2elf (my fault, sorry) so you'll have to start it somewhere else anyhow to make the vaddr and offset consistent anyway.


================
Comment at: llvm/tools/llvm-elfabi/ELFObjHandler.cpp:140
 
+  const char *DynStrPtr = reinterpret_cast<const char *>(ElfFile->base()) +
+                          DynEnt.StrTabOffset;
----------------
Ah wait, never-mind, I want this to work a bit differently. We discussed this offline but for others benifit I'll mention it here. This should work for cases when the vaddr which corresponds to ElfFile->base() is not zero (e.g. the common case for ET_EXEC and the almost never but sometimes case for ET_DYN). To do this you have to loop though the program headers, find the PT_LOAD such that the vaddr of the string table is in range of the vaddr to vaddr+filesz of the program header, and then use the offset of the program header and the difference between the vaddr of the program header and the string table to calculate the correct offset from base of the elf file. That's kind of a tricky subtle issue. You can test this by creating a binary using yaml2obj and making the vaddr of the program header that contains a dynamic string table non-zero.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55629/new/

https://reviews.llvm.org/D55629





More information about the llvm-commits mailing list