From: Cary Coutant Date: Wed, 25 Nov 2015 16:50:41 +0000 (-0800) Subject: Adjust local symbol value in relocatable link to be relative to section. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=74b03b91333ccbc8fa70647eca22062e902f797f;p=binutils-gdb.git Adjust local symbol value in relocatable link to be relative to section. gold/ PR gold/19291 * object.cc (Sized_relobj_file::write_local_symbols): If relocatable, subtract section address from symbol value. --- diff --git a/gold/ChangeLog b/gold/ChangeLog index a07226102b8..5eefa29eac9 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,9 @@ +2015-11-25 Cary Coutant + + PR gold/19291 + * object.cc (Sized_relobj_file::write_local_symbols): If relocatable, + subtract section address from symbol value. + 2015-11-25 Alan Modra * powerpc.cc (Output_data_got_powerpc::Output_data_got_powerpc): Align diff --git a/gold/object.cc b/gold/object.cc index 76d4630d16a..5381addde71 100644 --- a/gold/object.cc +++ b/gold/object.cc @@ -2674,6 +2674,7 @@ Sized_relobj_file::write_local_symbols( elfcpp::Sym isym(psyms); Symbol_value& lv(this->local_values_[i]); + typename elfcpp::Elf_types::Elf_Addr sym_value = lv.value(this, 0); bool is_ordinary; unsigned int st_shndx = this->adjust_sym_shndx(i, isym.get_st_shndx(), @@ -2683,6 +2684,9 @@ Sized_relobj_file::write_local_symbols( gold_assert(st_shndx < out_sections.size()); if (out_sections[st_shndx] == NULL) continue; + // In relocatable object files symbol values are section relative. + if (parameters->options().relocatable()) + sym_value -= out_sections[st_shndx]->address(); st_shndx = out_sections[st_shndx]->out_shndx(); if (st_shndx >= elfcpp::SHN_LORESERVE) { @@ -2702,7 +2706,7 @@ Sized_relobj_file::write_local_symbols( gold_assert(isym.get_st_name() < strtab_size); const char* name = pnames + isym.get_st_name(); osym.put_st_name(sympool->get_offset(name)); - osym.put_st_value(this->local_values_[i].value(this, 0)); + osym.put_st_value(sym_value); osym.put_st_size(isym.get_st_size()); osym.put_st_info(isym.get_st_info()); osym.put_st_other(isym.get_st_other()); @@ -2720,7 +2724,7 @@ Sized_relobj_file::write_local_symbols( gold_assert(isym.get_st_name() < strtab_size); const char* name = pnames + isym.get_st_name(); osym.put_st_name(dynpool->get_offset(name)); - osym.put_st_value(this->local_values_[i].value(this, 0)); + osym.put_st_value(sym_value); osym.put_st_size(isym.get_st_size()); osym.put_st_info(isym.get_st_info()); osym.put_st_other(isym.get_st_other());