This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
gold patch committed: Fix ld -r with linker script
- From: Ian Lance Taylor <iant at google dot com>
- To: binutils at sourceware dot org
- Date: Sat, 28 Feb 2009 09:55:03 -0800
- Subject: gold patch committed: Fix ld -r with linker script
When using a linker script with ld -r (an unusual case) the sections may
wind up at non-zero addresses. gold wasn't handling that in a couple of
cases--it was including the section address in the symbol value, which
is correct for a final link but incorrect when using -r. I never
noticed because when using -r the section address is normally
zero--unless you use a linker script. I committed this patch to fix the
problem.
Ian
2009-02-28 Ian Lance Taylor <iant@google.com>
PR 6992
* symtab.cc (Symbol_table::sized_write_section_symbol): In a
relocatable link set the value of the section symbol to zero.
* object.cc (Sized_relobj::do_finalize_local_symbols): In a
relocatable link don't include the section address in the local
symbol value.
Index: object.cc
===================================================================
RCS file: /cvs/src/src/gold/object.cc,v
retrieving revision 1.86
diff -u -p -r1.86 object.cc
--- object.cc 28 Feb 2009 04:39:57 -0000 1.86
+++ object.cc 28 Feb 2009 17:51:55 -0000
@@ -1509,6 +1509,7 @@ Sized_relobj<size, big_endian>::do_final
const unsigned int loccount = this->local_symbol_count_;
this->local_symbol_offset_ = off;
+ const bool relocatable = parameters->options().relocatable();
const Output_sections& out_sections(this->output_sections());
const std::vector<Address>& out_offsets(this->section_offsets_);
unsigned int shnum = this->shnum();
@@ -1589,7 +1590,7 @@ Sized_relobj<size, big_endian>::do_final
+ out_offsets[shndx]
+ lv.input_value());
else
- lv.set_output_value(os->address()
+ lv.set_output_value((relocatable ? 0 : os->address())
+ out_offsets[shndx]
+ lv.input_value());
}
Index: symtab.cc
===================================================================
RCS file: /cvs/src/src/gold/symtab.cc,v
retrieving revision 1.116
diff -u -p -r1.116 symtab.cc
--- symtab.cc 28 Feb 2009 04:39:57 -0000 1.116
+++ symtab.cc 28 Feb 2009 17:51:55 -0000
@@ -2693,7 +2693,10 @@ Symbol_table::sized_write_section_symbol
elfcpp::Sym_write<size, big_endian> osym(pov);
osym.put_st_name(0);
- osym.put_st_value(os->address());
+ if (parameters->options().relocatable())
+ osym.put_st_value(0);
+ else
+ osym.put_st_value(os->address());
osym.put_st_size(0);
osym.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL,
elfcpp::STT_SECTION));