1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-26 13:10:46 +03:00
This commit is contained in:
Rui Ueyama 2024-07-07 21:50:24 +09:00
parent 16ee9f48a4
commit 5b4377842b

View File

@ -1621,10 +1621,14 @@ ElfSym<E> to_output_esym(Context<E> &ctx, Symbol<E> &sym, u32 st_name,
};
i64 shndx = -1;
InputSection<E> *isec = sym.get_input_section();
if (sym.has_copyrel) {
// Symbol in .copyrel
shndx = sym.is_copyrel_readonly ? ctx.copyrel_relro->shndx : ctx.copyrel->shndx;
esym.st_value = sym.get_addr(ctx);
} else if (sym.file->is_dso || sym.esym().is_undef()) {
// Undefined symbol in a DSO
esym.st_shndx = SHN_UNDEF;
esym.st_size = 0;
if (sym.is_canonical)
@ -1637,7 +1641,7 @@ ElfSym<E> to_output_esym(Context<E> &ctx, Symbol<E> &sym, u32 st_name,
// Section fragment
shndx = frag->output_section.shndx;
esym.st_value = sym.get_addr(ctx);
} else if (!sym.get_input_section()) {
} else if (!isec) {
// Absolute symbol
esym.st_shndx = SHN_ABS;
esym.st_value = sym.get_addr(ctx);
@ -1651,7 +1655,25 @@ ElfSym<E> to_output_esym(Context<E> &ctx, Symbol<E> &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) {
// 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<E> *file = (ObjectFile<E> *)sym.file;
MergeableSection<E> *m =
file->mergeable_sections[file->get_shndx(sym.esym())].get();
SectionFragment<E> *frag;
i64 frag_addend;
std::tie(frag, frag_addend) = m->get_fragment(sym.esym().st_value);
shndx = m->parent.shndx;
esym.st_visibility = sym.visibility;
esym.st_value = frag->get_addr(ctx) + frag_addend;
} else {
// Symbol in a regular section
shndx = get_st_shndx(sym);
esym.st_visibility = sym.visibility;
esym.st_value = sym.get_addr(ctx, NO_PLT);