https://bugs.gentoo.org/938009 https://github.com/rui314/mold/issues/1326 https://github.com/rui314/mold/commit/5a9919b43344b4fb92ea701f0b32a7e20857b9ca From 5a9919b43344b4fb92ea701f0b32a7e20857b9ca Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 9 Aug 2024 12:08:03 +0900 Subject: [PATCH] Fix a crash bug Fixes https://github.com/rui314/mold/issues/1326 --- a/elf/output-chunks.cc +++ b/elf/output-chunks.cc @@ -1730,21 +1730,18 @@ ElfSym to_output_esym(Context &ctx, Symbol &sym, u32 st_name, esym.st_type = STT_FUNC; esym.st_visibility = sym.visibility; esym.st_value = sym.get_plt_addr(ctx); - } else if (!isec->output_section) { + } else if ((isec->shdr().sh_flags & SHF_MERGE) && + !(isec->shdr().sh_flags & SHF_ALLOC)) { // Symbol in a mergeable non-SHF_ALLOC section, such as .debug_str - assert(!(isec->shdr().sh_flags & SHF_ALLOC)); - assert(isec->shdr().sh_flags & SHF_MERGE); - assert(!sym.file->is_dso); - ObjectFile *file = (ObjectFile *)sym.file; - MergeableSection *m = - file->mergeable_sections[file->get_shndx(sym.esym())].get(); + MergeableSection &m = + *file->mergeable_sections[file->get_shndx(sym.esym())]; SectionFragment *frag; i64 frag_addend; - std::tie(frag, frag_addend) = m->get_fragment(sym.esym().st_value); + std::tie(frag, frag_addend) = m.get_fragment(sym.esym().st_value); - shndx = m->parent.shndx; + shndx = m.parent.shndx; esym.st_visibility = sym.visibility; esym.st_value = frag->get_addr(ctx) + frag_addend; } else {