This is the mail archive of the
binutils-cvs@sourceware.org
mailing list for the binutils project.
[binutils-gdb/binutils-2_26-branch] Adjust local symbol value in relocatable link to be relative to section.
- From: Alan Modra <amodra at sourceware dot org>
- To: bfd-cvs at sourceware dot org
- Date: 10 Dec 2015 13:50:23 -0000
- Subject: [binutils-gdb/binutils-2_26-branch] Adjust local symbol value in relocatable link to be relative to section.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=dd5474b0c1a0ae90bc68d07e18136000fde2e461
commit dd5474b0c1a0ae90bc68d07e18136000fde2e461
Author: Cary Coutant <ccoutant@gmail.com>
Date: Wed Nov 25 08:50:41 2015 -0800
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:
---
gold/ChangeLog | 5 +++++
gold/object.cc | 8 ++++++--
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/gold/ChangeLog b/gold/ChangeLog
index 628d6d0..80793bb 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,6 +1,11 @@
2015-12-10 Alan Modra <amodra@gmail.com>
Apply from master.
+ 2015-11-25 Cary Coutant <ccoutant@gmail.com>
+ PR gold/19291
+ * object.cc (Sized_relobj_file::write_local_symbols): If relocatable,
+ subtract section address from symbol value.
+
2015-11-25 Alan Modra <amodra@gmail.com>
* powerpc.cc (Output_data_got_powerpc::Output_data_got_powerpc): Align
to 256 byte boundary.
diff --git a/gold/object.cc b/gold/object.cc
index 76d4630..5381add 100644
--- a/gold/object.cc
+++ b/gold/object.cc
@@ -2674,6 +2674,7 @@ Sized_relobj_file<size, big_endian>::write_local_symbols(
elfcpp::Sym<size, big_endian> isym(psyms);
Symbol_value<size>& lv(this->local_values_[i]);
+ typename elfcpp::Elf_types<size>::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<size, big_endian>::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<size, big_endian>::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<size, big_endian>::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());