// reloc.cc -- relocate input files for gold.
-// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
#include "target-reloc.h"
#include "reloc.h"
#include "icf.h"
+#include "compressed_output.h"
namespace gold
{
workqueue->queue_next(new Gc_process_relocs(this->symtab_,
this->layout_,
this->object_, rd,
- this->symtab_lock_,
- this->blocker_));
+ this->this_blocker_,
+ this->next_blocker_));
}
else
{
workqueue->queue_next(new Scan_relocs(this->symtab_, this->layout_,
this->object_, rd,
- this->symtab_lock_,
- this->blocker_));
+ this->this_blocker_,
+ this->next_blocker_));
}
}
// Gc_process_relocs methods.
-// These tasks process the relocations read by Read_relocs and
+Gc_process_relocs::~Gc_process_relocs()
+{
+ if (this->this_blocker_ != NULL)
+ delete this->this_blocker_;
+}
+
+// These tasks process the relocations read by Read_relocs and
// determine which sections are referenced and which are garbage.
-// This task is done only when --gc-sections is used.
+// This task is done only when --gc-sections is used. This is blocked
+// by THIS_BLOCKER_. It unblocks NEXT_BLOCKER_.
Task_token*
Gc_process_relocs::is_runnable()
{
+ if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
+ return this->this_blocker_;
if (this->object_->is_locked())
return this->object_->token();
return NULL;
Gc_process_relocs::locks(Task_locker* tl)
{
tl->add(this, this->object_->token());
- tl->add(this, this->blocker_);
+ tl->add(this, this->next_blocker_);
}
void
// Scan_relocs methods.
+Scan_relocs::~Scan_relocs()
+{
+ if (this->this_blocker_ != NULL)
+ delete this->this_blocker_;
+}
+
// These tasks scan the relocations read by Read_relocs and mark up
// the symbol table to indicate which relocations are required. We
// use a lock on the symbol table to keep them from interfering with
Task_token*
Scan_relocs::is_runnable()
{
- if (!this->symtab_lock_->is_writable())
- return this->symtab_lock_;
+ if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
+ return this->this_blocker_;
if (this->object_->is_locked())
return this->object_->token();
return NULL;
Scan_relocs::locks(Task_locker* tl)
{
tl->add(this, this->object_->token());
- tl->add(this, this->symtab_lock_);
- tl->add(this, this->blocker_);
+ tl->add(this, this->next_blocker_);
}
// Scan the relocs.
Scan_relocs::run(Workqueue*)
{
this->object_->scan_relocs(this->symtab_, this->layout_, this->rd_);
- this->object_->release();
delete this->rd_;
this->rd_ = NULL;
+ this->object_->release();
}
// Return a debugging name for the task.
{
rd->relocs.clear();
- unsigned int sec_shnum = this->shnum();
- if (sec_shnum == 0)
+ unsigned int shnum = this->shnum();
+ if (shnum == 0)
return;
- rd->relocs.reserve(sec_shnum / 2);
+ rd->relocs.reserve(shnum / 2);
const Output_sections& out_sections(this->output_sections());
const std::vector<Address>& out_offsets(this->section_offsets_);
const unsigned char *pshdrs = this->get_view(this->elf_file_.shoff(),
- sec_shnum * This::shdr_size,
+ shnum * This::shdr_size,
true, true);
// Skip the first, dummy, section.
const unsigned char *ps = pshdrs + This::shdr_size;
- for (unsigned int i = 1; i < sec_shnum; ++i, ps += This::shdr_size)
+ for (unsigned int i = 1; i < shnum; ++i, ps += This::shdr_size)
{
typename This::Shdr shdr(ps);
continue;
unsigned int shndx = this->adjust_shndx(shdr.get_sh_info());
- if (shndx >= sec_shnum)
+ if (shndx >= shnum)
{
this->error(_("relocation section %u has bad info %u"),
i, shndx);
typename This::Shdr symtabshdr(pshdrs
+ this->symtab_shndx_ * This::shdr_size);
gold_assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB);
- const int symsize = This::sym_size;
+ const int sym_size = This::sym_size;
const unsigned int loccount = this->local_symbol_count_;
gold_assert(loccount == symtabshdr.get_sh_info());
- off_t locsize = loccount * symsize;
+ off_t locsize = loccount * sym_size;
rd->local_symbols = this->get_lasting_view(symtabshdr.get_sh_offset(),
locsize, true, true);
}
template<int size, bool big_endian>
void
Sized_relobj<size, big_endian>::do_gc_process_relocs(Symbol_table* symtab,
- Layout* alayout,
+ Layout* layout,
Read_relocs_data* rd)
{
Sized_target<size, big_endian>* target =
// only scan allocated sections. We may see a non-allocated
// section here if we are emitting relocs.
if (p->is_data_section_allocated)
- target->gc_process_relocs(symtab, alayout, this,
+ target->gc_process_relocs(symtab, layout, this,
p->data_shndx, p->sh_type,
p->contents->data(), p->reloc_count,
p->output_section,
template<int size, bool big_endian>
void
Sized_relobj<size, big_endian>::do_scan_relocs(Symbol_table* symtab,
- Layout* alayout,
+ Layout* layout,
Read_relocs_data* rd)
{
Sized_target<size, big_endian>* target =
// only scan allocated sections. We may see a non-allocated
// section here if we are emitting relocs.
if (p->is_data_section_allocated)
- target->scan_relocs(symtab, alayout, this, p->data_shndx,
+ target->scan_relocs(symtab, layout, this, p->data_shndx,
p->sh_type, p->contents->data(),
p->reloc_count, p->output_section,
p->needs_special_offset_handling,
this->local_symbol_count_,
local_symbols);
if (parameters->options().emit_relocs())
- this->emit_relocs_scan(symtab, alayout, local_symbols, p);
+ this->emit_relocs_scan(symtab, layout, local_symbols, p);
}
else
{
Relocatable_relocs* rr = this->relocatable_relocs(p->reloc_shndx);
gold_assert(rr != NULL);
rr->set_reloc_count(p->reloc_count);
- target->scan_relocatable_relocs(symtab, alayout, this,
+ target->scan_relocatable_relocs(symtab, layout, this,
p->data_shndx, p->sh_type,
p->contents->data(),
p->reloc_count,
void
Sized_relobj<size, big_endian>::emit_relocs_scan(
Symbol_table* symtab,
- Layout* alayout,
+ Layout* layout,
const unsigned char* plocal_syms,
const Read_relocs_data::Relocs_list::iterator& p)
{
rr->set_reloc_count(p->reloc_count);
if (p->sh_type == elfcpp::SHT_REL)
- this->emit_relocs_scan_reltype<elfcpp::SHT_REL>(symtab, alayout,
+ this->emit_relocs_scan_reltype<elfcpp::SHT_REL>(symtab, layout,
plocal_syms, p, rr);
else
{
gold_assert(p->sh_type == elfcpp::SHT_RELA);
- this->emit_relocs_scan_reltype<elfcpp::SHT_RELA>(symtab, alayout,
+ this->emit_relocs_scan_reltype<elfcpp::SHT_RELA>(symtab, layout,
plocal_syms, p, rr);
}
}
void
Sized_relobj<size, big_endian>::emit_relocs_scan_reltype(
Symbol_table* symtab,
- Layout* alayout,
+ Layout* layout,
const unsigned char* plocal_syms,
const Read_relocs_data::Relocs_list::iterator& p,
Relocatable_relocs* rr)
scan_relocatable_relocs<size, big_endian, sh_type,
Emit_relocs_strategy<sh_type> >(
symtab,
- alayout,
+ layout,
this,
p->data_shndx,
p->contents->data(),
template<int size, bool big_endian>
void
Sized_relobj<size, big_endian>::do_relocate(const Symbol_table* symtab,
- const Layout* alayout,
+ const Layout* layout,
Output_file* of)
{
- unsigned int sec_shnum = this->shnum();
+ unsigned int shnum = this->shnum();
// Read the section headers.
const unsigned char* pshdrs = this->get_view(this->elf_file_.shoff(),
- sec_shnum * This::shdr_size,
+ shnum * This::shdr_size,
true, true);
Views views;
- views.resize(sec_shnum);
+ views.resize(shnum);
// Make two passes over the sections. The first one copies the
// section data to the output file. The second one applies
// Apply relocations.
- this->relocate_sections(symtab, alayout, pshdrs, &views);
+ this->relocate_sections(symtab, layout, pshdrs, &views);
// After we've done the relocations, we release the hash tables,
// since we no longer need them.
this->free_input_to_output_maps();
// Write out the accumulated views.
- for (unsigned int i = 1; i < sec_shnum; ++i)
+ for (unsigned int i = 1; i < shnum; ++i)
{
if (views[i].view != NULL)
{
}
// Write out the local symbols.
- this->write_local_symbols(of, alayout->sympool(), alayout->dynpool(),
- alayout->symtab_xindex(), alayout->dynsym_xindex());
+ this->write_local_symbols(of, layout->sympool(), layout->dynpool(),
+ layout->symtab_xindex(), layout->dynsym_xindex());
// We should no longer need the local symbol values.
this->clear_local_symbols();
Output_file* of,
Views* pviews)
{
- unsigned int sec_shnum = this->shnum();
+ unsigned int shnum = this->shnum();
const Output_sections& out_sections(this->output_sections());
const std::vector<Address>& out_offsets(this->section_offsets_);
bool is_sorted = true;
const unsigned char* p = pshdrs + This::shdr_size;
- for (unsigned int i = 1; i < sec_shnum; ++i, p += This::shdr_size)
+ for (unsigned int i = 1; i < shnum; ++i, p += This::shdr_size)
{
View_size* pvs = &(*pviews)[i];
// buffer, and the output section is responsible for writing the
// final data to the output file.
- off_t out_section_offset;
+ off_t output_section_offset;
Address output_section_size;
if (!os->requires_postprocessing())
{
- out_section_offset = os->offset();
+ output_section_offset = os->offset();
output_section_size = convert_types<Address, off_t>(os->data_size());
}
else
{
- out_section_offset = 0;
+ output_section_offset = 0;
output_section_size =
convert_types<Address, off_t>(os->postprocessing_buffer_size());
}
off_t view_start;
section_size_type view_size;
+ bool must_decompress = false;
if (output_offset != invalid_address)
{
- view_start = out_section_offset + output_offset;
+ view_start = output_section_offset + output_offset;
view_size = convert_to_section_size_type(shdr.get_sh_size());
+ section_size_type uncompressed_size;
+ if (this->section_is_compressed(i, &uncompressed_size))
+ {
+ view_size = uncompressed_size;
+ must_decompress = true;
+ }
}
else
{
- view_start = out_section_offset;
+ view_start = output_section_offset;
view_size = convert_to_section_size_type(output_section_size);
}
gold_assert(output_offset == invalid_address
|| output_offset + view_size <= output_section_size);
- unsigned char* aview;
+ unsigned char* view;
if (os->requires_postprocessing())
{
unsigned char* buffer = os->postprocessing_buffer();
- aview = buffer + view_start;
- if (output_offset != invalid_address)
+ view = buffer + view_start;
+ if (output_offset != invalid_address && !must_decompress)
{
off_t sh_offset = shdr.get_sh_offset();
if (!rm.empty() && rm.back().file_offset > sh_offset)
is_sorted = false;
rm.push_back(File_read::Read_multiple_entry(sh_offset,
- view_size, aview));
+ view_size, view));
}
}
else
{
if (output_offset == invalid_address)
- aview = of->get_input_output_view(view_start, view_size);
+ view = of->get_input_output_view(view_start, view_size);
else
{
- aview = of->get_output_view(view_start, view_size);
- off_t sh_offset = shdr.get_sh_offset();
- if (!rm.empty() && rm.back().file_offset > sh_offset)
- is_sorted = false;
- rm.push_back(File_read::Read_multiple_entry(sh_offset,
- view_size, aview));
+ view = of->get_output_view(view_start, view_size);
+ if (!must_decompress)
+ {
+ off_t sh_offset = shdr.get_sh_offset();
+ if (!rm.empty() && rm.back().file_offset > sh_offset)
+ is_sorted = false;
+ rm.push_back(File_read::Read_multiple_entry(sh_offset,
+ view_size, view));
+ }
}
}
- pvs->view = aview;
+ if (must_decompress)
+ {
+ // Read and decompress the section.
+ section_size_type len;
+ const unsigned char* p = this->section_contents(i, &len, false);
+ if (!decompress_input_section(p, len, view, view_size))
+ this->error(_("could not decompress section %s"),
+ this->section_name(i).c_str());
+ }
+
+ pvs->view = view;
pvs->address = os->address();
if (output_offset != invalid_address)
pvs->address += output_offset;
void
Sized_relobj<size, big_endian>::do_relocate_sections(
const Symbol_table* symtab,
- const Layout* alayout,
+ const Layout* layout,
const unsigned char* pshdrs,
Views* pviews)
{
- unsigned int sec_shnum = this->shnum();
+ unsigned int shnum = this->shnum();
Sized_target<size, big_endian>* target =
parameters->sized_target<size, big_endian>();
Relocate_info<size, big_endian> relinfo;
relinfo.symtab = symtab;
- relinfo.layout = alayout;
+ relinfo.layout = layout;
relinfo.object = this;
const unsigned char* p = pshdrs + This::shdr_size;
- for (unsigned int i = 1; i < sec_shnum; ++i, p += This::shdr_size)
+ for (unsigned int i = 1; i < shnum; ++i, p += This::shdr_size)
{
typename This::Shdr shdr(p);
relinfo.reloc_shdr = p;
relinfo.data_shndx = index;
relinfo.data_shdr = pshdrs + index * This::shdr_size;
- unsigned char* aview = (*pviews)[index].view;
+ unsigned char* view = (*pviews)[index].view;
Address address = (*pviews)[index].address;
section_size_type view_size = (*pviews)[index].view_size;
typename This::Shdr data_shdr(pshdrs + index * This::shdr_size);
if ((data_shdr.get_sh_flags() & elfcpp::SHF_EXECINSTR) != 0)
this->split_stack_adjust(symtab, pshdrs, sh_type, index,
- prelocs, reloc_count, aview, view_size,
+ prelocs, reloc_count, view, view_size,
&reloc_map);
}
{
target->relocate_section(&relinfo, sh_type, prelocs, reloc_count, os,
output_offset == invalid_address,
- aview, address, view_size, reloc_map);
+ view, address, view_size, reloc_map);
if (parameters->options().emit_relocs())
this->emit_relocs(&relinfo, i, sh_type, prelocs, reloc_count,
- os, output_offset, aview, address, view_size,
+ os, output_offset, view, address, view_size,
(*pviews)[i].view, (*pviews)[i].view_size);
}
else
Relocatable_relocs* rr = this->relocatable_relocs(i);
target->relocate_for_relocatable(&relinfo, sh_type, prelocs,
reloc_count, os, output_offset, rr,
- aview, address, view_size,
+ view, address, view_size,
(*pviews)[i].view,
(*pviews)[i].view_size);
}
unsigned int sh_type,
const unsigned char* prelocs,
size_t reloc_count,
- Output_section* aoutput_section,
+ Output_section* output_section,
typename elfcpp::Elf_types<size>::Elf_Addr offset_in_output_section,
- unsigned char* aview,
+ unsigned char* view,
typename elfcpp::Elf_types<size>::Elf_Addr address,
section_size_type view_size,
unsigned char* reloc_view,
{
if (sh_type == elfcpp::SHT_REL)
this->emit_relocs_reltype<elfcpp::SHT_REL>(relinfo, i, prelocs,
- reloc_count, aoutput_section,
+ reloc_count, output_section,
offset_in_output_section,
- aview, address, view_size,
+ view, address, view_size,
reloc_view, reloc_view_size);
else
{
gold_assert(sh_type == elfcpp::SHT_RELA);
this->emit_relocs_reltype<elfcpp::SHT_RELA>(relinfo, i, prelocs,
- reloc_count, aoutput_section,
+ reloc_count, output_section,
offset_in_output_section,
- aview, address, view_size,
+ view, address, view_size,
reloc_view, reloc_view_size);
}
}
unsigned int i,
const unsigned char* prelocs,
size_t reloc_count,
- Output_section* aoutput_section,
+ Output_section* output_section,
typename elfcpp::Elf_types<size>::Elf_Addr offset_in_output_section,
- unsigned char* aview,
+ unsigned char* view,
typename elfcpp::Elf_types<size>::Elf_Addr address,
section_size_type view_size,
unsigned char* reloc_view,
relinfo,
prelocs,
reloc_count,
- aoutput_section,
+ output_section,
offset_in_output_section,
rr,
- aview,
+ view,
address,
view_size,
reloc_view,
unsigned int shndx,
const unsigned char* prelocs,
size_t reloc_count,
- unsigned char* aview,
+ unsigned char* view,
section_size_type view_size,
Reloc_symbol_changes** reloc_map)
{
if (sh_type == elfcpp::SHT_REL)
this->split_stack_adjust_reltype<elfcpp::SHT_REL>(symtab, pshdrs, shndx,
prelocs, reloc_count,
- aview, view_size,
+ view, view_size,
reloc_map);
else
{
gold_assert(sh_type == elfcpp::SHT_RELA);
this->split_stack_adjust_reltype<elfcpp::SHT_RELA>(symtab, pshdrs, shndx,
prelocs, reloc_count,
- aview, view_size,
+ view, view_size,
reloc_map);
}
}
unsigned int shndx,
const unsigned char* prelocs,
size_t reloc_count,
- unsigned char* aview,
+ unsigned char* view,
section_size_type view_size,
Reloc_symbol_changes** reloc_map)
{
// cases we will ask for a large stack unnecessarily, but this
// is not fatal. FIXME: Some targets have symbols which are
// functions but are not type STT_FUNC, e.g., STT_ARM_TFUNC.
- if (gsym->type() == elfcpp::STT_FUNC
- && !gsym->is_undefined()
+ if (!gsym->is_undefined()
&& gsym->source() == Symbol::FROM_OBJECT
&& !gsym->object()->uses_split_stack())
{
- section_offset_type off =
- convert_to_section_size_type(reloc.get_r_offset());
- non_split_refs.push_back(off);
+ unsigned int r_type = elfcpp::elf_r_type<size>(reloc.get_r_info());
+ if (parameters->target().is_call_to_non_split(gsym, r_type))
+ {
+ section_offset_type offset =
+ convert_to_section_size_type(reloc.get_r_offset());
+ non_split_refs.push_back(offset);
+ }
}
}
std::string from;
std::string to;
parameters->target().calls_non_split(this, shndx, p->first, p->second,
- aview, view_size, &from, &to);
+ view, view_size, &from, &to);
if (!from.empty())
{
gold_assert(!to.empty());
if (r_sym < local_count)
continue;
- section_offset_type off =
+ section_offset_type offset =
convert_to_section_size_type(reloc.get_r_offset());
- if (off < p->first
- || (off
+ if (offset < p->first
+ || (offset
>= (p->first
+ static_cast<section_offset_type>(p->second))))
continue;
// We need to read the symbols to find the functions. If we wanted
// to, we could cache reading the symbols across all sections in the
// object.
- const unsigned int sym_tab_shndx = this->symtab_shndx_;
- typename This::Shdr symtabshdr(pshdrs + sym_tab_shndx * This::shdr_size);
+ const unsigned int symtab_shndx = this->symtab_shndx_;
+ typename This::Shdr symtabshdr(pshdrs + symtab_shndx * This::shdr_size);
gold_assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB);
typename elfcpp::Elf_types<size>::Elf_WXword sh_size =
const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
sh_size, true, true);
- const int symsize = This::sym_size;
- const unsigned int symcount = sh_size / symsize;
- for (unsigned int i = 0; i < symcount; ++i, psyms += symsize)
+ const int sym_size = This::sym_size;
+ const unsigned int symcount = sh_size / sym_size;
+ for (unsigned int i = 0; i < symcount; ++i, psyms += sym_size)
{
typename elfcpp::Sym<size, big_endian> isym(psyms);
template
void
Sized_relobj<32, false>::do_gc_process_relocs(Symbol_table* symtab,
- Layout* alayout,
+ Layout* layout,
Read_relocs_data* rd);
#endif
template
void
Sized_relobj<32, true>::do_gc_process_relocs(Symbol_table* symtab,
- Layout* alayout,
+ Layout* layout,
Read_relocs_data* rd);
#endif
template
void
Sized_relobj<64, false>::do_gc_process_relocs(Symbol_table* symtab,
- Layout* alayout,
+ Layout* layout,
Read_relocs_data* rd);
#endif
template
void
Sized_relobj<64, true>::do_gc_process_relocs(Symbol_table* symtab,
- Layout* alayout,
+ Layout* layout,
Read_relocs_data* rd);
#endif
template
void
Sized_relobj<32, false>::do_scan_relocs(Symbol_table* symtab,
- Layout* alayout,
+ Layout* layout,
Read_relocs_data* rd);
#endif
template
void
Sized_relobj<32, true>::do_scan_relocs(Symbol_table* symtab,
- Layout* alayout,
+ Layout* layout,
Read_relocs_data* rd);
#endif
template
void
Sized_relobj<64, false>::do_scan_relocs(Symbol_table* symtab,
- Layout* alayout,
+ Layout* layout,
Read_relocs_data* rd);
#endif
template
void
Sized_relobj<64, true>::do_scan_relocs(Symbol_table* symtab,
- Layout* alayout,
+ Layout* layout,
Read_relocs_data* rd);
#endif
template
void
Sized_relobj<32, false>::do_relocate(const Symbol_table* symtab,
- const Layout* alayout,
+ const Layout* layout,
Output_file* of);
#endif
template
void
Sized_relobj<32, true>::do_relocate(const Symbol_table* symtab,
- const Layout* alayout,
+ const Layout* layout,
Output_file* of);
#endif
template
void
Sized_relobj<64, false>::do_relocate(const Symbol_table* symtab,
- const Layout* alayout,
+ const Layout* layout,
Output_file* of);
#endif
template
void
Sized_relobj<64, true>::do_relocate(const Symbol_table* symtab,
- const Layout* alayout,
+ const Layout* layout,
Output_file* of);
#endif
void
Sized_relobj<32, false>::do_relocate_sections(
const Symbol_table* symtab,
- const Layout* alayout,
+ const Layout* layout,
const unsigned char* pshdrs,
Views* pviews);
#endif
void
Sized_relobj<32, true>::do_relocate_sections(
const Symbol_table* symtab,
- const Layout* alayout,
+ const Layout* layout,
const unsigned char* pshdrs,
Views* pviews);
#endif
void
Sized_relobj<64, false>::do_relocate_sections(
const Symbol_table* symtab,
- const Layout* alayout,
+ const Layout* layout,
const unsigned char* pshdrs,
Views* pviews);
#endif