this->got_plt_);
// The first three entries are reserved.
- this->got_plt_->set_space_size(3 * 4);
+ this->got_plt_->set_current_data_size(3 * 4);
// Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
symtab->define_in_output_data(this, "_GLOBAL_OFFSET_TABLE_", NULL,
// Set the final size.
void
- do_set_address(uint64_t, off_t)
+ set_final_data_size()
{ this->set_data_size((this->count_ + 1) * plt_entry_size); }
// Write out the PLT data.
++this->count_;
- off_t got_offset = this->got_plt_->data_size();
+ off_t got_offset = this->got_plt_->current_data_size();
// Every PLT entry needs a GOT entry which points back to the PLT
// entry (this will be changed by the dynamic linker, normally
// lazily when the function is called).
- this->got_plt_->set_space_size(got_offset + 4);
+ this->got_plt_->set_current_data_size(got_offset + 4);
// Every PLT entry needs a reloc.
gsym->set_needs_dynsym_entry();
if (align > dynbss->addralign())
dynbss->set_space_alignment(align);
- off_t dynbss_size = dynbss->data_size();
+ off_t dynbss_size = dynbss->current_data_size();
dynbss_size = align_address(dynbss_size, align);
off_t offset = dynbss_size;
- dynbss->set_space_size(dynbss_size + symsize);
+ dynbss->set_current_data_size(dynbss_size + symsize);
symtab->define_with_copy_reloc(this, ssym, dynbss, offset);
Output_section* output_section,
const elfcpp::Rel<32, false>& reloc,
unsigned int r_type,
- const elfcpp::Sym<32, false>&)
+ const elfcpp::Sym<32, false>& lsym)
{
switch (r_type)
{
if (parameters->output_is_position_independent())
{
Reloc_section* rel_dyn = target->rel_dyn_section(layout);
- rel_dyn->add_local(object, 0, elfcpp::R_386_RELATIVE, output_section,
- data_shndx, reloc.get_r_offset());
+ unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
+ rel_dyn->add_local_relative(object, r_sym, elfcpp::R_386_RELATIVE,
+ output_section, data_shndx,
+ reloc.get_r_offset());
}
break;
if (got->add_local(object, r_sym))
{
// If we are generating a shared object, we need to add a
- // dynamic RELATIVE relocation for this symbol.
+ // dynamic RELATIVE relocation for this symbol's GOT entry.
if (parameters->output_is_position_independent())
{
Reloc_section* rel_dyn = target->rel_dyn_section(layout);
- rel_dyn->add_local(object, 0, elfcpp::R_386_RELATIVE,
- output_section, data_shndx,
- reloc.get_r_offset());
+ unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
+ rel_dyn->add_local_relative(object, r_sym,
+ elfcpp::R_386_RELATIVE,
+ got,
+ object->local_got_offset(r_sym));
}
}
}
Output_data_got<32, false>* got
= target->got_section(symtab, layout);
unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
- if (got->add_local_tls(object, r_sym, true))
- {
- Reloc_section* rel_dyn = target->rel_dyn_section(layout);
- unsigned int got_off
- = object->local_tls_got_offset(r_sym, true);
- rel_dyn->add_local(object, r_sym,
- elfcpp::R_386_TLS_DTPMOD32,
- got, got_off);
- rel_dyn->add_local(object, r_sym,
- elfcpp::R_386_TLS_DTPOFF32,
- got, got_off + 4);
- }
+ got->add_local_tls_with_rel(object, r_sym,
+ lsym.get_st_shndx(), true,
+ target->rel_dyn_section(layout),
+ elfcpp::R_386_TLS_DTPMOD32);
}
else if (optimized_type != tls::TLSOPT_TO_LE)
unsupported_reloc_local(object, r_type);
case elfcpp::R_386_TLS_GOTDESC: // Global-dynamic (from ~oliva)
case elfcpp::R_386_TLS_DESC_CALL:
- unsupported_reloc_local(object, r_type);
+ // FIXME: If not relaxing to LE, we need to generate
+ // a GOT entry with an R_386_TLS_DESC reloc.
+ if (optimized_type != tls::TLSOPT_TO_LE)
+ unsupported_reloc_local(object, r_type);
break;
case elfcpp::R_386_TLS_LDM: // Local-dynamic
Output_data_got<32, false>* got
= target->got_section(symtab, layout);
unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
- if (got->add_local_tls(object, r_sym, false))
- {
- Reloc_section* rel_dyn = target->rel_dyn_section(layout);
- unsigned int got_off
- = object->local_tls_got_offset(r_sym, false);
- rel_dyn->add_local(object, r_sym,
- elfcpp::R_386_TLS_DTPMOD32, got,
- got_off);
- }
+ got->add_local_tls_with_rel(object, r_sym,
+ lsym.get_st_shndx(), false,
+ target->rel_dyn_section(layout),
+ elfcpp::R_386_TLS_DTPMOD32);
}
else if (optimized_type != tls::TLSOPT_TO_LE)
unsupported_reloc_local(object, r_type);
case elfcpp::R_386_TLS_GOTIE:
if (optimized_type == tls::TLSOPT_NONE)
{
+ // For the R_386_TLS_IE relocation, we need to create a
+ // dynamic relocation when building a shared library.
+ if (r_type == elfcpp::R_386_TLS_IE
+ && parameters->output_is_shared())
+ {
+ Reloc_section* rel_dyn = target->rel_dyn_section(layout);
+ unsigned int r_sym
+ = elfcpp::elf_r_sym<32>(reloc.get_r_info());
+ rel_dyn->add_local_relative(object, r_sym,
+ elfcpp::R_386_RELATIVE,
+ output_section, data_shndx,
+ reloc.get_r_offset());
+ }
// Create a GOT entry for the tp-relative offset.
Output_data_got<32, false>* got
= target->got_section(symtab, layout);
unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
- if (got->add_local(object, r_sym))
- {
- unsigned int dyn_r_type
- = (r_type == elfcpp::R_386_TLS_IE_32
- ? elfcpp::R_386_TLS_TPOFF32
- : elfcpp::R_386_TLS_TPOFF);
- Reloc_section* rel_dyn = target->rel_dyn_section(layout);
- unsigned int got_off = object->local_got_offset(r_sym);
- rel_dyn->add_local(object, r_sym, dyn_r_type, got,
- got_off);
- }
+ unsigned int dyn_r_type = (r_type == elfcpp::R_386_TLS_IE_32
+ ? elfcpp::R_386_TLS_TPOFF32
+ : elfcpp::R_386_TLS_TPOFF);
+ got->add_local_with_rel(object, r_sym,
+ target->rel_dyn_section(layout),
+ dyn_r_type);
}
else if (optimized_type != tls::TLSOPT_TO_LE)
unsupported_reloc_local(object, r_type);
case elfcpp::R_386_TLS_LE: // Local-exec
case elfcpp::R_386_TLS_LE_32:
if (output_is_shared)
- unsupported_reloc_local(object, r_type);
+ {
+ // We need to create a dynamic relocation.
+ unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
+ unsigned int dyn_r_type = (r_type == elfcpp::R_386_TLS_LE_32
+ ? elfcpp::R_386_TLS_TPOFF32
+ : elfcpp::R_386_TLS_TPOFF);
+ Reloc_section* rel_dyn = target->rel_dyn_section(layout);
+ rel_dyn->add_local(object, r_sym, dyn_r_type, output_section,
+ data_shndx, reloc.get_r_offset());
+ }
break;
default:
&& gsym->can_use_relative_reloc(false))
{
Reloc_section* rel_dyn = target->rel_dyn_section(layout);
- rel_dyn->add_local(object, 0, elfcpp::R_386_RELATIVE,
- output_section, data_shndx,
- reloc.get_r_offset());
+ rel_dyn->add_global_relative(gsym, elfcpp::R_386_RELATIVE,
+ output_section, object,
+ data_shndx, reloc.get_r_offset());
}
else
{
{
// Make a PLT entry if necessary.
if (gsym->needs_plt_entry())
- target->make_plt_entry(symtab, layout, gsym);
+ {
+ // These relocations are used for function calls only in
+ // non-PIC code. For a 32-bit relocation in a shared library,
+ // we'll need a text relocation anyway, so we can skip the
+ // PLT entry and let the dynamic linker bind the call directly
+ // to the target. For smaller relocations, we should use a
+ // PLT entry to ensure that the call can reach.
+ if (!parameters->output_is_shared()
+ || r_type != elfcpp::R_386_PC32)
+ target->make_plt_entry(symtab, layout, gsym);
+ }
// Make a dynamic relocation if necessary.
bool is_function_call = (gsym->type() == elfcpp::STT_FUNC);
if (gsym->needs_dynamic_reloc(false, is_function_call))
{
// The symbol requires a GOT entry.
Output_data_got<32, false>* got = target->got_section(symtab, layout);
- if (got->add_global(gsym))
- {
+ if (gsym->final_value_is_known())
+ got->add_global(gsym);
+ else
+ {
// If this symbol is not fully resolved, we need to add a
- // dynamic relocation for it.
- if (!gsym->final_value_is_known())
+ // GOT entry with a dynamic relocation.
+ Reloc_section* rel_dyn = target->rel_dyn_section(layout);
+ if (gsym->is_from_dynobj() || gsym->is_preemptible())
+ got->add_global_with_rel(gsym, rel_dyn, elfcpp::R_386_GLOB_DAT);
+ else
{
- Reloc_section* rel_dyn = target->rel_dyn_section(layout);
- if (gsym->is_from_dynobj()
- || gsym->is_preemptible())
- rel_dyn->add_global(gsym, elfcpp::R_386_GLOB_DAT, got,
- gsym->got_offset());
- else
- {
- rel_dyn->add_local(object, 0, elfcpp::R_386_RELATIVE,
- got, gsym->got_offset());
- // Make sure we write the link-time value to the GOT.
- gsym->set_needs_value_in_got();
- }
+ if (got->add_global(gsym))
+ rel_dyn->add_global_relative(gsym, elfcpp::R_386_RELATIVE,
+ got, gsym->got_offset());
}
}
}
// dtv-relative offset.
Output_data_got<32, false>* got
= target->got_section(symtab, layout);
- if (got->add_global_tls(gsym, true))
- {
- Reloc_section* rel_dyn = target->rel_dyn_section(layout);
- unsigned int got_off = gsym->tls_got_offset(true);
- rel_dyn->add_global(gsym, elfcpp::R_386_TLS_DTPMOD32,
- got, got_off);
- rel_dyn->add_global(gsym, elfcpp::R_386_TLS_DTPOFF32,
- got, got_off + 4);
- }
+ got->add_global_tls_with_rel(gsym,
+ target->rel_dyn_section(layout),
+ elfcpp::R_386_TLS_DTPMOD32,
+ elfcpp::R_386_TLS_DTPOFF32);
}
else if (optimized_type == tls::TLSOPT_TO_IE)
{
// Create a GOT entry for the tp-relative offset.
Output_data_got<32, false>* got
= target->got_section(symtab, layout);
- if (got->add_global(gsym))
- {
- Reloc_section* rel_dyn = target->rel_dyn_section(layout);
- unsigned int got_off = gsym->got_offset();
- rel_dyn->add_global(gsym, elfcpp::R_386_TLS_TPOFF32,
- got, got_off);
- }
+ got->add_global_with_rel(gsym, target->rel_dyn_section(layout),
+ elfcpp::R_386_TLS_TPOFF32);
}
else if (optimized_type != tls::TLSOPT_TO_LE)
unsupported_reloc_global(object, r_type, gsym);
case elfcpp::R_386_TLS_GOTDESC: // Global-dynamic (~oliva url)
case elfcpp::R_386_TLS_DESC_CALL:
+ // FIXME: If not relaxing to LE, we need to generate
+ // a GOT entry with an R_386_TLS_DESC reloc.
+ if (optimized_type != tls::TLSOPT_TO_LE)
+ unsupported_reloc_global(object, r_type, gsym);
unsupported_reloc_global(object, r_type, gsym);
break;
// Create a GOT entry for the module index.
Output_data_got<32, false>* got
= target->got_section(symtab, layout);
- if (got->add_global_tls(gsym, false))
- {
- Reloc_section* rel_dyn = target->rel_dyn_section(layout);
- unsigned int got_off = gsym->tls_got_offset(false);
- rel_dyn->add_global(gsym, elfcpp::R_386_TLS_DTPMOD32,
- got, got_off);
- }
+ got->add_global_tls_with_rel(gsym,
+ target->rel_dyn_section(layout),
+ elfcpp::R_386_TLS_DTPMOD32);
}
else if (optimized_type != tls::TLSOPT_TO_LE)
unsupported_reloc_global(object, r_type, gsym);
case elfcpp::R_386_TLS_GOTIE:
if (optimized_type == tls::TLSOPT_NONE)
{
- // Create a GOT entry for the tp-relative offset.
- Output_data_got<32, false>* got
- = target->got_section(symtab, layout);
- if (got->add_global(gsym))
+ // For the R_386_TLS_IE relocation, we need to create a
+ // dynamic relocation when building a shared library.
+ if (r_type == elfcpp::R_386_TLS_IE
+ && parameters->output_is_shared())
{
- unsigned int dyn_r_type
- = (r_type == elfcpp::R_386_TLS_IE_32
- ? elfcpp::R_386_TLS_TPOFF32
- : elfcpp::R_386_TLS_TPOFF);
Reloc_section* rel_dyn = target->rel_dyn_section(layout);
- unsigned int got_off = gsym->got_offset();
- rel_dyn->add_global(gsym, dyn_r_type, got, got_off);
+ rel_dyn->add_global_relative(gsym, elfcpp::R_386_RELATIVE,
+ output_section, object,
+ data_shndx,
+ reloc.get_r_offset());
}
+ // Create a GOT entry for the tp-relative offset.
+ Output_data_got<32, false>* got
+ = target->got_section(symtab, layout);
+ unsigned int dyn_r_type = (r_type == elfcpp::R_386_TLS_IE_32
+ ? elfcpp::R_386_TLS_TPOFF32
+ : elfcpp::R_386_TLS_TPOFF);
+ got->add_global_with_rel(gsym,
+ target->rel_dyn_section(layout),
+ dyn_r_type);
}
else if (optimized_type != tls::TLSOPT_TO_LE)
unsupported_reloc_global(object, r_type, gsym);
case elfcpp::R_386_TLS_LE: // Local-exec
case elfcpp::R_386_TLS_LE_32:
if (parameters->output_is_shared())
- unsupported_reloc_global(object, r_type, gsym);
+ {
+ // We need to create a dynamic relocation.
+ unsigned int dyn_r_type = (r_type == elfcpp::R_386_TLS_LE_32
+ ? elfcpp::R_386_TLS_TPOFF32
+ : elfcpp::R_386_TLS_TPOFF);
+ Reloc_section* rel_dyn = target->rel_dyn_section(layout);
+ rel_dyn->add_global(gsym, dyn_r_type, output_section, object,
+ data_shndx, reloc.get_r_offset());
+ }
break;
default:
if (optimized_type == tls::TLSOPT_TO_IE)
{
gold_assert(tls_segment != NULL);
- this->tls_gd_to_ie(relinfo, relnum, tls_segment,
- rel, r_type, got_offset, view,
- view_size);
+ this->tls_gd_to_ie(relinfo, relnum, tls_segment, rel, r_type,
+ got_offset, view, view_size);
break;
}
else if (optimized_type == tls::TLSOPT_NONE)
// won't see the TLS_LDM reloc. The local_dynamic_type field
// tells us this.
gold_assert(tls_segment != NULL);
- if (optimized_type != tls::TLSOPT_TO_LE
- || this->local_dynamic_type_ == LOCAL_DYNAMIC_NONE)
- value = value - tls_segment->vaddr();
- else if (this->local_dynamic_type_ == LOCAL_DYNAMIC_GNU)
- value = value - (tls_segment->vaddr() + tls_segment->memsz());
- else
- value = tls_segment->vaddr() + tls_segment->memsz() - value;
+ if (this->local_dynamic_type_ == LOCAL_DYNAMIC_GNU)
+ value -= tls_segment->memsz();
+ else if (optimized_type == tls::TLSOPT_TO_LE
+ && this->local_dynamic_type_ != LOCAL_DYNAMIC_NONE)
+ value = tls_segment->memsz() - value;
Relocate_functions<32, false>::rel32(view, value);
break;
break;
case elfcpp::R_386_TLS_LE: // Local-exec
- gold_assert(tls_segment != NULL);
- value = value - (tls_segment->vaddr() + tls_segment->memsz());
- Relocate_functions<32, false>::rel32(view, value);
+ // If we're creating a shared library, a dynamic relocation will
+ // have been created for this location, so do not apply it now.
+ if (!parameters->output_is_shared())
+ {
+ gold_assert(tls_segment != NULL);
+ value -= tls_segment->memsz();
+ Relocate_functions<32, false>::rel32(view, value);
+ }
break;
case elfcpp::R_386_TLS_LE_32:
- gold_assert(tls_segment != NULL);
- value = tls_segment->vaddr() + tls_segment->memsz() - value;
- Relocate_functions<32, false>::rel32(view, value);
+ // If we're creating a shared library, a dynamic relocation will
+ // have been created for this location, so do not apply it now.
+ if (!parameters->output_is_shared())
+ {
+ gold_assert(tls_segment != NULL);
+ value = tls_segment->memsz() - value;
+ Relocate_functions<32, false>::rel32(view, value);
+ }
break;
}
}
}
}
- value = tls_segment->vaddr() + tls_segment->memsz() - value;
+ value = tls_segment->memsz() - value;
Relocate_functions<32, false>::rel32(view + roff, value);
// The next reloc should be a PLT32 reloc against __tls_get_addr.
this->skip_call_tls_get_addr_ = true;
}
-// Do a relocation in which we convert a TLS General-Dynamic to a
+// Do a relocation in which we convert a TLS General-Dynamic to an
// Initial-Exec.
inline void
}
}
- value = tls_segment->vaddr() + tls_segment->memsz() - value;
+ value = tls_segment->memsz() - value;
Relocate_functions<32, false>::rel32(view + roff, value);
// The next reloc should be a PLT32 reloc against __tls_get_addr.
tls::check_tls(relinfo, relnum, rel.get_r_offset(), 0);
}
- value = tls_segment->vaddr() + tls_segment->memsz() - value;
+ value = tls_segment->memsz() - value;
if (r_type == elfcpp::R_386_TLS_IE || r_type == elfcpp::R_386_TLS_GOTIE)
value = - value;