OSDN Git Service

[elfabi] Add support for reading dynamic symbols from binaries
authorArmando Montanez <amontanez@google.com>
Thu, 24 Jan 2019 22:39:21 +0000 (22:39 +0000)
committerArmando Montanez <amontanez@google.com>
Thu, 24 Jan 2019 22:39:21 +0000 (22:39 +0000)
commit904cc193935cb5c2bf99e08d7555762f9bb763d6
treea082cb98ae4e7650bfe7f6f0a411af9db94686eb
parent24fa3683a5f44327a758bf80b92e6d41dc8463e5
[elfabi] Add support for reading dynamic symbols from binaries

This patch adds initial support for reading dynamic symbols from ELF binaries. Currently, STT_NOTYPE, STT_OBJECT, STT_FUNC, and STT_TLS are explicitly supported. Other symbol types are mapped to ELFSymbolType::Unknown to improve signal/noise ratio.

Symbols must meet two criteria to be read into in an ELFStub:

 - The symbol's binding must be STB_GLOBAL or STB_WEAK.
 - The symbol's visibility must be STV_DEFAULT or STV_PROTECTED.

This filters out symbols that aren't of interest during compile-time linking against a shared object.

This change uses DT_HASH and DT_GNU_HASH to determine the size of .dynsym. Using hash tables to determine the number of symbols in .dynsym allows llvm-elfabi to work on binaries without relying on section headers.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352121 91177308-0d34-0410-b5e6-96231b3b80d8
14 files changed:
test/tools/llvm-elfabi/Inputs/gnu_hash.so [new file with mode: 0755]
test/tools/llvm-elfabi/Inputs/sysv_hash.so [new file with mode: 0755]
test/tools/llvm-elfabi/binary-read-add-soname.test
test/tools/llvm-elfabi/binary-read-arch.test
test/tools/llvm-elfabi/binary-read-bad-soname.test
test/tools/llvm-elfabi/binary-read-bad-vaddr.test
test/tools/llvm-elfabi/binary-read-neededlibs-bad-offset.test
test/tools/llvm-elfabi/binary-read-neededlibs.test
test/tools/llvm-elfabi/binary-read-replace-soname.test
test/tools/llvm-elfabi/binary-read-soname-no-null.test
test/tools/llvm-elfabi/binary-read-soname.test
test/tools/llvm-elfabi/binary-read-syms-gnu-hash.test [new file with mode: 0644]
test/tools/llvm-elfabi/binary-read-syms-sysv-hash.test [new file with mode: 0644]
tools/llvm-elfabi/ELFObjHandler.cpp