aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCary Coutant <ccoutant@gmail.com>2016-03-08 12:24:39 -0800
committerCary Coutant <ccoutant@gmail.com>2016-03-08 15:06:59 -0800
commitc32482d65c43f40572a0722b48c20b3f571666a3 (patch)
treec496e6566aaf984af0f0150c9a3325d1032712cc /gold/output.cc
parentHandle local IFUNC symbols in shared object (diff)
downloadbinutils-gdb-c32482d65c43f40572a0722b48c20b3f571666a3.tar.gz
binutils-gdb-c32482d65c43f40572a0722b48c20b3f571666a3.tar.bz2
binutils-gdb-c32482d65c43f40572a0722b48c20b3f571666a3.zip
Refactor Output_data_reloc_base::do_write for MIPS-specific relocs.
This patch is a simple refactoring that will allow the MIPS backend to replace the Output_data_reloc_base::do_write() method without copying its entire implementation. I've moved the implementation of do_write() into a function template, which can be instantiated with a custom class to write the MIPS-specific relocation format. The custom class for MIPS needs access to the symbol index and address from Output_reloc, so I've included the part of Vlad's MIPS-64 patch that makes those accessor methods public. 2016-03-08 Cary Coutant <ccoutant@gmail.com> Vladimir Radosavljevic <vladimir.radosavljevic@imgtec.com> gold/ * output.cc (Output_reloc_writer): New type. (Output_data_reloc_base::do_write): Move implementation to template in output.h and replace with invocation of template. * output.h (Output_file): Move to top of file. (Output_reloc::get_symbol_index): Move to public interface. (Output_reloc::get_address): Likewise. (Output_data_reloc_base::do_write_generic): New function template.
Diffstat (limited to 'gold/output.cc')
-rw-r--r--gold/output.cc41
1 files changed, 15 insertions, 26 deletions
diff --git a/gold/output.cc b/gold/output.cc
index f9d4f23c119..077e2c4481e 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -1252,6 +1252,19 @@ Output_data_reloc_base<sh_type, dynamic, size, big_endian>
os->set_should_link_to_dynsym();
}
+// Standard relocation writer, which just calls Output_reloc::write().
+
+template<int sh_type, bool dynamic, int size, bool big_endian>
+struct Output_reloc_writer
+{
+ typedef Output_reloc<sh_type, dynamic, size, big_endian> Output_reloc_type;
+ typedef std::vector<Output_reloc_type> Relocs;
+
+ static void
+ write(typename Relocs::const_iterator p, unsigned char* pov)
+ { p->write(pov); }
+};
+
// Write out relocation data.
template<int sh_type, bool dynamic, int size, bool big_endian>
@@ -1259,32 +1272,8 @@ void
Output_data_reloc_base<sh_type, dynamic, size, big_endian>::do_write(
Output_file* of)
{
- const off_t off = this->offset();
- const off_t oview_size = this->data_size();
- unsigned char* const oview = of->get_output_view(off, oview_size);
-
- if (this->sort_relocs())
- {
- gold_assert(dynamic);
- std::sort(this->relocs_.begin(), this->relocs_.end(),
- Sort_relocs_comparison());
- }
-
- unsigned char* pov = oview;
- for (typename Relocs::const_iterator p = this->relocs_.begin();
- p != this->relocs_.end();
- ++p)
- {
- p->write(pov);
- pov += reloc_size;
- }
-
- gold_assert(pov - oview == oview_size);
-
- of->write_output_view(off, oview_size, oview);
-
- // We no longer need the relocation entries.
- this->relocs_.clear();
+ typedef Output_reloc_writer<sh_type, dynamic, size, big_endian> Writer;
+ this->do_write_generic<Writer>(of);
}
// Class Output_relocatable_relocs.