From eff458138e2978ee9a3aef4ebee40d53da11e764 Mon Sep 17 00:00:00 2001 From: Cary Coutant Date: Mon, 29 Sep 2008 21:10:26 +0000 Subject: [PATCH] * mapfile.cc (Mapfile::print_input_section): Change -1U to -1ULL. * object.cc (Sized_relobj::do_layout): Use constant invalid_address instead of -1U. (Sized_relobj::do_finalize_local_symbols): Likewise. (Sized_relobj::map_to_kept_section): Likewise. * object.h (Sized_relobj::invalid_address): New constant. (Sized_relobj::do_output_section_offset): Check for invalid_address and return -1ULL. * output.cc (Output_reloc::local_section_offset): Use constant invalid_address instead of -1U. (Output_reloc::get_address): Likewise. (Output_section::output_address): Change -1U to -1ULL. * output.h (Output_reloc::invalid_address): New constant. * reloc.cc (Sized_relobj::write_sections): Use constant invalid_address instead of -1U. (Sized_relobj::relocate_sections): Likewise. * symtab.cc (Symbol_table::sized_finalize_symbol): Handle symbol values for merge sections. * target-reloc.h (relocate_for_relocatable): Use constant invalid_address instead of -1U. --- gold/ChangeLog | 23 +++++++++++++++++++++++ gold/mapfile.cc | 2 +- gold/object.cc | 14 +++++++------- gold/object.h | 11 +++++++++-- gold/output.cc | 10 +++++----- gold/output.h | 4 +++- gold/reloc.cc | 20 ++++++++++---------- gold/symtab.cc | 19 ++++++++++++++----- gold/target-reloc.h | 5 +++-- 9 files changed, 75 insertions(+), 33 deletions(-) diff --git a/gold/ChangeLog b/gold/ChangeLog index 6b1a4f6762d..ff9dd446e84 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,26 @@ +2008-09-29 Cary Coutant + + * mapfile.cc (Mapfile::print_input_section): Change -1U to -1ULL. + * object.cc (Sized_relobj::do_layout): Use constant invalid_address + instead of -1U. + (Sized_relobj::do_finalize_local_symbols): Likewise. + (Sized_relobj::map_to_kept_section): Likewise. + * object.h (Sized_relobj::invalid_address): New constant. + (Sized_relobj::do_output_section_offset): Check for invalid_address + and return -1ULL. + * output.cc (Output_reloc::local_section_offset): Use constant + invalid_address instead of -1U. + (Output_reloc::get_address): Likewise. + (Output_section::output_address): Change -1U to -1ULL. + * output.h (Output_reloc::invalid_address): New constant. + * reloc.cc (Sized_relobj::write_sections): Use constant + invalid_address instead of -1U. + (Sized_relobj::relocate_sections): Likewise. + * symtab.cc (Symbol_table::sized_finalize_symbol): Handle symbol + values for merge sections. + * target-reloc.h (relocate_for_relocatable): Use constant + invalid_address instead of -1U. + 2008-09-19 Cary Coutant Add plugin functionality for link-time optimization (LTO). diff --git a/gold/mapfile.cc b/gold/mapfile.cc index 9cec36638bd..a3ba52ba611 100644 --- a/gold/mapfile.cc +++ b/gold/mapfile.cc @@ -253,7 +253,7 @@ Mapfile::print_input_section(Relobj* relobj, unsigned int shndx) { os = relobj->output_section(shndx); addr = relobj->output_section_offset(shndx); - if (addr != -1U) + if (addr != -1ULL) addr += os->address(); } diff --git a/gold/object.cc b/gold/object.cc index d8f5ec80274..f7dcda89ceb 100644 --- a/gold/object.cc +++ b/gold/object.cc @@ -926,7 +926,7 @@ Sized_relobj::do_layout(Symbol_table* symtab, { // Do not include this section in the link. out_sections[i] = NULL; - out_section_offsets[i] = -1U; + out_section_offsets[i] = invalid_address; continue; } @@ -967,7 +967,7 @@ Sized_relobj::do_layout(Symbol_table* symtab, out_sections[i] = os; if (offset == -1) - out_section_offsets[i] = -1U; + out_section_offsets[i] = invalid_address; else out_section_offsets[i] = convert_types(offset); @@ -1004,7 +1004,7 @@ Sized_relobj::do_layout(Symbol_table* symtab, if (data_section == NULL) { out_sections[i] = NULL; - out_section_offsets[i] = -1U; + out_section_offsets[i] = invalid_address; continue; } @@ -1014,7 +1014,7 @@ Sized_relobj::do_layout(Symbol_table* symtab, Output_section* os = layout->layout_reloc(this, i, shdr, data_section, rr); out_sections[i] = os; - out_section_offsets[i] = -1U; + out_section_offsets[i] = invalid_address; } // Handle the .eh_frame sections at the end. @@ -1042,7 +1042,7 @@ Sized_relobj::do_layout(Symbol_table* symtab, &offset); out_sections[i] = os; if (offset == -1) - out_section_offsets[i] = -1U; + out_section_offsets[i] = invalid_address; else out_section_offsets[i] = convert_types(offset); @@ -1266,7 +1266,7 @@ Sized_relobj::do_finalize_local_symbols(unsigned int index, // so we leave the input value unchanged here. continue; } - else if (out_offsets[shndx] == -1U) + else if (out_offsets[shndx] == invalid_address) { // This is a SHF_MERGE section or one which otherwise // requires special handling. We get the output address @@ -1573,7 +1573,7 @@ Sized_relobj::map_to_kept_section( *found = true; Output_section* os = kept->object_->output_section(kept->shndx_); Address offset = kept->object_->get_output_section_offset(kept->shndx_); - gold_assert(os != NULL && offset != -1U); + gold_assert(os != NULL && offset != invalid_address); return os->address() + offset; } *found = false; diff --git a/gold/object.h b/gold/object.h index 1c4fc6768ce..fcb5d317ea1 100644 --- a/gold/object.h +++ b/gold/object.h @@ -1202,6 +1202,8 @@ class Sized_relobj : public Relobj typedef std::vector Symbols; typedef std::vector > Local_values; + static const Address invalid_address = static_cast
(0) - 1; + Sized_relobj(const std::string& name, Input_file* input_file, off_t offset, const typename elfcpp::Ehdr&); @@ -1457,7 +1459,12 @@ class Sized_relobj : public Relobj // Get the offset of a section. uint64_t do_output_section_offset(unsigned int shndx) const - { return this->get_output_section_offset(shndx); } + { + Address off = this->get_output_section_offset(shndx); + if (off == invalid_address) + return -1ULL; + return off; + } // Set the offset of a section. void @@ -1699,7 +1706,7 @@ class Sized_relobj : public Relobj // for TLS symbols, indexed by symbol number. Local_got_offsets local_got_offsets_; // For each input section, the offset of the input section in its - // output section. This is -1U if the input section requires a + // output section. This is INVALID_ADDRESS if the input section requires a // special mapping. std::vector
section_offsets_; // Table mapping discarded comdat sections to corresponding kept sections. diff --git a/gold/output.cc b/gold/output.cc index 2a46195b2ac..f6a6f1da6e1 100644 --- a/gold/output.cc +++ b/gold/output.cc @@ -838,11 +838,11 @@ Output_reloc:: Output_section* os = this->u1_.relobj->output_section(lsi); gold_assert(os != NULL); Address offset = this->u1_.relobj->get_output_section_offset(lsi); - if (offset != -1U) + if (offset != invalid_address) return offset + addend; // This is a merge section. offset = os->output_address(this->u1_.relobj, lsi, addend); - gold_assert(offset != -1U); + gold_assert(offset != invalid_address); return offset; } @@ -858,13 +858,13 @@ Output_reloc::get_address() const Output_section* os = this->u2_.relobj->output_section(this->shndx_); gold_assert(os != NULL); Address off = this->u2_.relobj->get_output_section_offset(this->shndx_); - if (off != -1U) + if (off != invalid_address) address += os->address() + off; else { address = os->output_address(this->u2_.relobj, this->shndx_, address); - gold_assert(address != -1U); + gold_assert(address != invalid_address); } } else if (this->u2_.od != NULL) @@ -2043,7 +2043,7 @@ Output_section::output_address(const Relobj* object, unsigned int shndx, if (p->output_offset(object, shndx, offset, &output_offset)) { if (output_offset == -1) - return -1U; + return -1ULL; return addr + output_offset; } addr += p->data_size(); diff --git a/gold/output.h b/gold/output.h index 1c95881739f..9f075bec464 100644 --- a/gold/output.h +++ b/gold/output.h @@ -874,6 +874,8 @@ class Output_reloc typedef typename elfcpp::Elf_types::Elf_Addr Address; typedef typename elfcpp::Elf_types::Elf_Addr Addend; + static const Address invalid_address = static_cast
(0) - 1; + // An uninitialized entry. We need this because we want to put // instances of this class into an STL container. Output_reloc() @@ -1915,7 +1917,7 @@ class Output_section : public Output_data // Add a new input section SHNDX, named NAME, with header SHDR, from // object OBJECT. RELOC_SHNDX is the index of a relocation section - // which applies to this section, or 0 if none, or -1U if more than + // which applies to this section, or 0 if none, or -1 if more than // one. HAVE_SECTIONS_SCRIPT is true if we have a SECTIONS clause // in a linker script; in that case we need to keep track of input // sections associated with an output section. Return the offset diff --git a/gold/reloc.cc b/gold/reloc.cc index daa0ea88ae3..481617df0b5 100644 --- a/gold/reloc.cc +++ b/gold/reloc.cc @@ -586,8 +586,8 @@ Sized_relobj::write_sections(const unsigned char* pshdrs, // In the normal case, this input section is simply mapped to // the output section at offset OUTPUT_OFFSET. - // However, if OUTPUT_OFFSET == -1U, then input data is handled - // specially--e.g., a .eh_frame section. The relocation + // However, if OUTPUT_OFFSET == INVALID_ADDRESS, then input data is + // handled specially--e.g., a .eh_frame section. The relocation // routines need to check for each reloc where it should be // applied. For this case, we need an input/output view for the // entire contents of the section in the output file. We don't @@ -619,7 +619,7 @@ Sized_relobj::write_sections(const unsigned char* pshdrs, off_t view_start; section_size_type view_size; - if (output_offset != -1U) + if (output_offset != invalid_address) { view_start = output_section_offset + output_offset; view_size = convert_to_section_size_type(shdr.get_sh_size()); @@ -633,7 +633,7 @@ Sized_relobj::write_sections(const unsigned char* pshdrs, if (view_size == 0) continue; - gold_assert(output_offset == -1U + gold_assert(output_offset == invalid_address || output_offset + view_size <= output_section_size); unsigned char* view; @@ -641,7 +641,7 @@ Sized_relobj::write_sections(const unsigned char* pshdrs, { unsigned char* buffer = os->postprocessing_buffer(); view = buffer + view_start; - if (output_offset != -1U) + if (output_offset != invalid_address) { off_t sh_offset = shdr.get_sh_offset(); if (!rm.empty() && rm.back().file_offset > sh_offset) @@ -652,7 +652,7 @@ Sized_relobj::write_sections(const unsigned char* pshdrs, } else { - if (output_offset == -1U) + if (output_offset == invalid_address) view = of->get_input_output_view(view_start, view_size); else { @@ -667,11 +667,11 @@ Sized_relobj::write_sections(const unsigned char* pshdrs, pvs->view = view; pvs->address = os->address(); - if (output_offset != -1U) + if (output_offset != invalid_address) pvs->address += output_offset; pvs->offset = view_start; pvs->view_size = view_size; - pvs->is_input_output_view = output_offset == -1U; + pvs->is_input_output_view = output_offset == invalid_address; pvs->is_postprocessing_view = os->requires_postprocessing(); } @@ -772,7 +772,7 @@ Sized_relobj::relocate_sections( continue; } - gold_assert(output_offset != -1U + gold_assert(output_offset != invalid_address || this->relocs_must_follow_section_writes()); relinfo.reloc_shndx = i; @@ -784,7 +784,7 @@ Sized_relobj::relocate_sections( prelocs, reloc_count, os, - output_offset == -1U, + output_offset == invalid_address, (*pviews)[index].view, (*pviews)[index].address, (*pviews)[index].view_size); diff --git a/gold/symtab.cc b/gold/symtab.cc index 3bb88d8b2be..c2de3bcad90 100644 --- a/gold/symtab.cc +++ b/gold/symtab.cc @@ -2136,11 +2136,20 @@ Symbol_table::sized_finalize_symbol(Symbol* unsized_sym) } uint64_t secoff64 = relobj->output_section_offset(shndx); - Value_type secoff = convert_types(secoff64); - if (sym->type() == elfcpp::STT_TLS) - value = sym->value() + os->tls_offset() + secoff; - else - value = sym->value() + os->address() + secoff; + if (secoff64 == -1ULL) + { + // The section needs special handling (e.g., a merge section). + value = os->output_address(relobj, shndx, sym->value()); + } + else + { + Value_type secoff = + convert_types(secoff64); + if (sym->type() == elfcpp::STT_TLS) + value = sym->value() + os->tls_offset() + secoff; + else + value = sym->value() + os->address() + secoff; + } } } break; diff --git a/gold/target-reloc.h b/gold/target-reloc.h index 1cdc24458a6..935d76bc24e 100644 --- a/gold/target-reloc.h +++ b/gold/target-reloc.h @@ -450,6 +450,7 @@ relocate_for_relocatable( typedef typename Reloc_types::Reloc_write Reltype_write; const int reloc_size = Reloc_types::reloc_size; + const Address invalid_address = static_cast
(0) - 1; Sized_relobj* const object = relinfo->object; const unsigned int local_count = object->local_symbol_count(); @@ -524,7 +525,7 @@ relocate_for_relocatable( Address offset = reloc.get_r_offset(); Address new_offset; - if (offset_in_output_section != -1U) + if (offset_in_output_section != invalid_address) new_offset = offset + offset_in_output_section; else { @@ -543,7 +544,7 @@ relocate_for_relocatable( if (!parameters->options().relocatable()) { new_offset += view_address; - if (offset_in_output_section != -1U) + if (offset_in_output_section != invalid_address) new_offset -= offset_in_output_section; } -- 2.30.2