mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-04 05:48:20 +08:00
gold/
* output.cc (Output_segment::set_section_addresses): Take new Target* argument. If target->isolate_execinstr() and the segment is executable and starts at a target->abi_pagesize() boundary, pad its end out to a target->abi_pagesize() boundary with code fill. * output.h (Output_segment::set_section_addresses): Update decl. * layout.h (Layout::check_output_data_for_reset_values): Take new argument RELAX_OUTPUTS. (Layout): New member relax_output_list_. (Layout::add_relax_output): New method. * layout.cc (Layout::Layout): Update constructor. (Layout::reset_relax_output): New method. (Layout::clean_up_after_relaxation): Call it. (Layout::prepare_for_relaxation): Update caller. (Layout::set_segment_offsets): Update callers of set_section_addresses. Call reset_relax_output before re-processing segments for isolate_execinstr case. (Layout::write_data): Handle relax_output_list_. (Layout::Relaxation_debug_check::check_output_data_for_reset_values): Take new argument RELAX_OUTPUTS. Assert it's an empty collection.
This commit is contained in:
@ -1,3 +1,25 @@
|
||||
2013-08-27 Roland McGrath <mcgrathr@google.com>
|
||||
|
||||
* output.cc (Output_segment::set_section_addresses): Take new
|
||||
Target* argument. If target->isolate_execinstr() and the segment
|
||||
is executable and starts at a target->abi_pagesize() boundary,
|
||||
pad its end out to a target->abi_pagesize() boundary with code fill.
|
||||
* output.h (Output_segment::set_section_addresses): Update decl.
|
||||
* layout.h (Layout::check_output_data_for_reset_values): Take new
|
||||
argument RELAX_OUTPUTS.
|
||||
(Layout): New member relax_output_list_.
|
||||
(Layout::add_relax_output): New method.
|
||||
* layout.cc (Layout::Layout): Update constructor.
|
||||
(Layout::reset_relax_output): New method.
|
||||
(Layout::clean_up_after_relaxation): Call it.
|
||||
(Layout::prepare_for_relaxation): Update caller.
|
||||
(Layout::set_segment_offsets): Update callers of set_section_addresses.
|
||||
Call reset_relax_output before re-processing segments for
|
||||
isolate_execinstr case.
|
||||
(Layout::write_data): Handle relax_output_list_.
|
||||
(Layout::Relaxation_debug_check::check_output_data_for_reset_values):
|
||||
Take new argument RELAX_OUTPUTS. Assert it's an empty collection.
|
||||
|
||||
2013-08-23 Yuri Chornoivan <yurchor@ukr.net>
|
||||
|
||||
PR binutils/15834
|
||||
|
@ -293,7 +293,8 @@ Hash_task::is_runnable()
|
||||
void
|
||||
Layout::Relaxation_debug_check::check_output_data_for_reset_values(
|
||||
const Layout::Section_list& sections,
|
||||
const Layout::Data_list& special_outputs)
|
||||
const Layout::Data_list& special_outputs,
|
||||
const Layout::Data_list& relax_outputs)
|
||||
{
|
||||
for(Layout::Section_list::const_iterator p = sections.begin();
|
||||
p != sections.end();
|
||||
@ -304,6 +305,8 @@ Layout::Relaxation_debug_check::check_output_data_for_reset_values(
|
||||
p != special_outputs.end();
|
||||
++p)
|
||||
gold_assert((*p)->address_and_file_offset_have_reset_values());
|
||||
|
||||
gold_assert(relax_outputs.empty());
|
||||
}
|
||||
|
||||
// Save information of SECTIONS for checking later.
|
||||
@ -428,6 +431,7 @@ Layout::Layout(int number_of_input_files, Script_options* script_options)
|
||||
section_list_(),
|
||||
unattached_section_list_(),
|
||||
special_output_list_(),
|
||||
relax_output_list_(),
|
||||
section_headers_(NULL),
|
||||
tls_segment_(NULL),
|
||||
relro_segment_(NULL),
|
||||
@ -2341,6 +2345,20 @@ Layout::clean_up_after_relaxation()
|
||||
++p)
|
||||
delete *p;
|
||||
this->script_output_section_data_list_.clear();
|
||||
|
||||
// Special-case fill output objects are recreated each time through
|
||||
// the relaxation loop.
|
||||
this->reset_relax_output();
|
||||
}
|
||||
|
||||
void
|
||||
Layout::reset_relax_output()
|
||||
{
|
||||
for (Data_list::const_iterator p = this->relax_output_list_.begin();
|
||||
p != this->relax_output_list_.end();
|
||||
++p)
|
||||
delete *p;
|
||||
this->relax_output_list_.clear();
|
||||
}
|
||||
|
||||
// Prepare for relaxation.
|
||||
@ -2363,7 +2381,8 @@ Layout::prepare_for_relaxation()
|
||||
|
||||
if (is_debugging_enabled(DEBUG_RELAXATION))
|
||||
this->relaxation_debug_check_->check_output_data_for_reset_values(
|
||||
this->section_list_, this->special_output_list_);
|
||||
this->section_list_, this->special_output_list_,
|
||||
this->relax_output_list_);
|
||||
|
||||
// Also enable recording of output section data from scripts.
|
||||
this->record_output_section_data_from_script_ = true;
|
||||
@ -3540,7 +3559,8 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
|
||||
|
||||
unsigned int shndx_hold = *pshndx;
|
||||
bool has_relro = false;
|
||||
uint64_t new_addr = (*p)->set_section_addresses(this, false, addr,
|
||||
uint64_t new_addr = (*p)->set_section_addresses(target, this,
|
||||
false, addr,
|
||||
&increase_relro,
|
||||
&has_relro,
|
||||
&off, pshndx);
|
||||
@ -3581,7 +3601,8 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
|
||||
increase_relro = 0;
|
||||
has_relro = false;
|
||||
|
||||
new_addr = (*p)->set_section_addresses(this, true, addr,
|
||||
new_addr = (*p)->set_section_addresses(target, this,
|
||||
true, addr,
|
||||
&increase_relro,
|
||||
&has_relro,
|
||||
&off, pshndx);
|
||||
@ -3617,6 +3638,8 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
|
||||
// so they land after the segments starting at LOAD_SEG.
|
||||
off = align_file_offset(off, 0, target->abi_pagesize());
|
||||
|
||||
this->reset_relax_output();
|
||||
|
||||
for (Segment_list::iterator p = this->segment_list_.begin();
|
||||
*p != load_seg;
|
||||
++p)
|
||||
@ -3630,8 +3653,8 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
|
||||
bool has_relro = false;
|
||||
const uint64_t old_addr = (*p)->vaddr();
|
||||
const uint64_t old_end = old_addr + (*p)->memsz();
|
||||
uint64_t new_addr = (*p)->set_section_addresses(this, true,
|
||||
old_addr,
|
||||
uint64_t new_addr = (*p)->set_section_addresses(target, this,
|
||||
true, old_addr,
|
||||
&increase_relro,
|
||||
&has_relro,
|
||||
&off,
|
||||
@ -5268,6 +5291,13 @@ Layout::write_data(const Symbol_table* symtab, Output_file* of) const
|
||||
p != this->special_output_list_.end();
|
||||
++p)
|
||||
(*p)->write(of);
|
||||
|
||||
// Write out the Output_data which are not in an Output_section
|
||||
// and are regenerated in each iteration of relaxation.
|
||||
for (Data_list::const_iterator p = this->relax_output_list_.begin();
|
||||
p != this->relax_output_list_.end();
|
||||
++p)
|
||||
(*p)->write(of);
|
||||
}
|
||||
|
||||
// Write out the Output_sections which can only be written after the
|
||||
|
@ -1,6 +1,6 @@
|
||||
// layout.h -- lay out output file sections for gold -*- C++ -*-
|
||||
|
||||
// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012
|
||||
// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
|
||||
// Free Software Foundation, Inc.
|
||||
// Written by Ian Lance Taylor <iant@google.com>.
|
||||
|
||||
@ -977,6 +977,16 @@ class Layout
|
||||
bool
|
||||
keep_input_section(const Relobj*, const char*);
|
||||
|
||||
// Add a special output object that will be recreated afresh
|
||||
// if there is another relaxation iteration.
|
||||
void
|
||||
add_relax_output(Output_data* data)
|
||||
{ this->relax_output_list_.push_back(data); }
|
||||
|
||||
// Clear out (and free) everything added by add_relax_output.
|
||||
void
|
||||
reset_relax_output();
|
||||
|
||||
private:
|
||||
Layout(const Layout&);
|
||||
Layout& operator=(const Layout&);
|
||||
@ -1272,7 +1282,8 @@ class Layout
|
||||
// Check that sections and special data are in reset states.
|
||||
void
|
||||
check_output_data_for_reset_values(const Layout::Section_list&,
|
||||
const Layout::Data_list&);
|
||||
const Layout::Data_list& special_outputs,
|
||||
const Layout::Data_list& relax_outputs);
|
||||
|
||||
// Record information of a section list.
|
||||
void
|
||||
@ -1324,6 +1335,9 @@ class Layout
|
||||
// The list of unattached Output_data objects which require special
|
||||
// handling because they are not Output_sections.
|
||||
Data_list special_output_list_;
|
||||
// Like special_output_list_, but cleared and recreated on each
|
||||
// iteration of relaxation.
|
||||
Data_list relax_output_list_;
|
||||
// The section headers.
|
||||
Output_section_headers* section_headers_;
|
||||
// A pointer to the PT_TLS segment if there is one.
|
||||
|
@ -1,6 +1,6 @@
|
||||
// output.cc -- manage the output file for gold
|
||||
|
||||
// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012
|
||||
// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
|
||||
// Free Software Foundation, Inc.
|
||||
// Written by Ian Lance Taylor <iant@google.com>.
|
||||
|
||||
@ -4299,7 +4299,8 @@ Output_segment::has_dynamic_reloc_list(const Output_data_list* pdl) const
|
||||
// and *PSHNDX.
|
||||
|
||||
uint64_t
|
||||
Output_segment::set_section_addresses(Layout* layout, bool reset,
|
||||
Output_segment::set_section_addresses(const Target* target,
|
||||
Layout* layout, bool reset,
|
||||
uint64_t addr,
|
||||
unsigned int* increase_relro,
|
||||
bool* has_relro,
|
||||
@ -4439,6 +4440,41 @@ Output_segment::set_section_addresses(Layout* layout, bool reset,
|
||||
// objects.
|
||||
*poff = off;
|
||||
|
||||
// If code segments must contain only code, and this code segment is
|
||||
// page-aligned in the file, then fill it out to a whole page with
|
||||
// code fill (the tail of the segment will not be within any section).
|
||||
// Thus the entire code segment can be mapped from the file as whole
|
||||
// pages and that mapping will contain only valid instructions.
|
||||
if (target->isolate_execinstr() && (this->flags() & elfcpp::PF_X) != 0)
|
||||
{
|
||||
uint64_t abi_pagesize = target->abi_pagesize();
|
||||
if (orig_off % abi_pagesize == 0 && off % abi_pagesize != 0)
|
||||
{
|
||||
size_t fill_size = abi_pagesize - (off % abi_pagesize);
|
||||
|
||||
std::string fill_data;
|
||||
if (target->has_code_fill())
|
||||
fill_data = target->code_fill(fill_size);
|
||||
else
|
||||
fill_data.resize(fill_size); // Zero fill.
|
||||
|
||||
Output_data_const* fill = new Output_data_const(fill_data, 0);
|
||||
fill->set_address(this->vaddr_ + this->memsz_);
|
||||
fill->set_file_offset(off);
|
||||
layout->add_relax_output(fill);
|
||||
|
||||
off += fill_size;
|
||||
gold_assert(off % abi_pagesize == 0);
|
||||
ret += fill_size;
|
||||
gold_assert(ret % abi_pagesize == 0);
|
||||
|
||||
gold_assert((uint64_t) this->filesz_ == this->memsz_);
|
||||
this->memsz_ = this->filesz_ += fill_size;
|
||||
|
||||
*poff = off;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
// output.h -- manage the output file for gold -*- C++ -*-
|
||||
|
||||
// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2013
|
||||
// Free Software Foundation, Inc.
|
||||
// Written by Ian Lance Taylor <iant@google.com>.
|
||||
|
||||
// This file is part of gold.
|
||||
@ -4596,7 +4597,7 @@ class Output_segment
|
||||
// address of the immediately following segment. Update *POFF and
|
||||
// *PSHNDX. This should only be called for a PT_LOAD segment.
|
||||
uint64_t
|
||||
set_section_addresses(Layout*, bool reset, uint64_t addr,
|
||||
set_section_addresses(const Target*, Layout*, bool reset, uint64_t addr,
|
||||
unsigned int* increase_relro, bool* has_relro,
|
||||
off_t* poff, unsigned int* pshndx);
|
||||
|
||||
|
Reference in New Issue
Block a user