diff --git a/input_sections.cc b/input_sections.cc index 5e307643..303aaa52 100644 --- a/input_sections.cc +++ b/input_sections.cc @@ -30,12 +30,10 @@ void InputSection::scan_relocations() { return; for (const ELF64LE::Rela &rel : rels) { - int idx = rel.getSymbol(false); - if (idx < file->first_global) + Symbol *sym = file->get_symbol(rel.getSymbol(false)); + if (!sym) continue; - Symbol *sym = file->symbols[idx - file->first_global]; - switch (rel.getType(false)) { case R_X86_64_GOTPCREL: case R_X86_64_TLSGD: diff --git a/main.cc b/main.cc index 8414344b..62852b40 100644 --- a/main.cc +++ b/main.cc @@ -394,6 +394,7 @@ int main(int argc, char **argv) { { MyTimer t("sym_addr"); for_each(files, [](ObjectFile *file) { + }); } diff --git a/mold.h b/mold.h index f80cdf8a..1b3350fa 100644 --- a/mold.h +++ b/mold.h @@ -400,8 +400,11 @@ public: StringRef get_filename(); bool is_in_archive(); - std::vector symbols; - int first_global = 0; + Symbol *get_symbol(uint32_t idx) { + if (idx < first_global) + return nullptr; + return symbols[first_global - idx]; + } std::vector sections; StringRef archive_name; @@ -420,6 +423,9 @@ private: std::vector merged_strings_alloc; std::vector merged_strings_noalloc; + std::vector symbols; + int first_global = 0; + ArrayRef elf_sections; ArrayRef elf_syms; StringRef string_table;