[PATCH] D131309: [ELF] Add ability to get a symbol by name from the hash table section

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 18 12:12:37 PDT 2022


MaskRay added a comment.

Many Linux distributions (clang/lib/Driver/ToolChains/Linux.cpp:240) use the linker option `--hash-style=gnu`, so most of their executabls/shared objects do not have SHT_HASH/DT_HASH. You may need to add SHT_GNU_HASH/DT_GNU_HASH support.



================
Comment at: llvm/include/llvm/Object/ELF.h:75
+/// This function returns the hash value for a symbol in the .dynsym section
+/// Name of the API remains consistent as specified in the libelf
+/// REF : http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#hash
----------------
s/libelf/generic ABI/


================
Comment at: llvm/include/llvm/Object/ELF.h:546
+                         "] is greater than the number of symbols: " +
+                         Twine((*SymTabOrErr)->sh_size / sizeof(Elf_Sym)));
+    if (SymTab[I].st_name >= StrTab.size())
----------------
You can save `sh_size / sizeof(Elf_Sym)` as a local variable, then you can replace `I * sizeof(Elf_Sym) >= (*SymTabOrErr)->sh_size` with a simpler check.


================
Comment at: llvm/include/llvm/Object/ELF.h:551
+
+    if (StrTab.drop_front(SymTab[I].st_name).data() == Name)
+      return &SymTab[I];
----------------
Prefer `substr` which is also available in std::string_view and is the unaliased function in StringRef.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131309



More information about the llvm-commits mailing list