| 149 | } |
| 150 | |
| 151 | [[nodiscard]] |
| 152 | static bool findSymByName32(const ElfView::ElfInfo &info, const char *symbol, |
| 153 | const Elf32_Sym **ppsym, uint32_t *psymidx) { |
| 154 | if (info.gnu_hash != nullptr) { |
| 155 | if (findLocalSymByGnuHash32(info, symbol, ppsym, psymidx)) { |
| 156 | return true; |
| 157 | } |
| 158 | // search the symtab |
| 159 | const uint32_t *gnuhashtab = static_cast<const uint32_t *>(info.gnu_hash); |
| 160 | const uint32_t symoffset = gnuhashtab[1]; |
| 161 | const Elf32_Sym *symtab = static_cast<const Elf32_Sym *>(info.symtab); |
| 162 | for (uint32_t i = 0; i < symoffset; i++) { |
| 163 | const char *symname = info.symstr + symtab[i].st_name; |
| 164 | if (strcmp(symname, symbol) == 0) { |
| 165 | *psymidx = i; |
| 166 | *ppsym = &symtab[i]; |
| 167 | return true; |
| 168 | } |
| 169 | } |
| 170 | return false; |
| 171 | } else if (info.chain != nullptr) { |
| 172 | const Elf32_Sym *target = nullptr; |
| 173 | uint32_t hash = elf_sysv_hash(symbol); |
| 174 | uint32_t index = info.bucket[hash % info.nbucket]; |
| 175 | const auto *sym = static_cast<const Elf32_Sym *>(info.symtab); |
| 176 | if (!strcmp(info.symstr + sym[index].st_name, symbol)) { |
| 177 | target = sym + index; |
| 178 | } |
| 179 | if (!target) { |
| 180 | do { |
| 181 | index = info.chain[index]; |
| 182 | if (!strcmp(info.symstr + sym[index].st_name, symbol)) { |
| 183 | target = sym + index; |
| 184 | break; |
| 185 | } |
| 186 | } while (index != 0); |
| 187 | } |
| 188 | if (target) { |
| 189 | *ppsym = target; |
| 190 | *psymidx = int(index); |
| 191 | return true; |
| 192 | } |
| 193 | } |
| 194 | return false; |
| 195 | } |
| 196 | |
| 197 | [[nodiscard]] |
| 198 | static bool findSymByName64(const ElfView::ElfInfo &info, const char *symbol, |
no test coverage detected