2007-09-26 13:44:38 +08:00
|
|
|
// ehframe.h -- handle exception frame sections for gold -*- C++ -*-
|
|
|
|
|
2023-01-01 14:08:42 +08:00
|
|
|
// Copyright (C) 2006-2023 Free Software Foundation, Inc.
|
2007-09-26 13:44:38 +08:00
|
|
|
// Written by Ian Lance Taylor <iant@google.com>.
|
|
|
|
|
|
|
|
// This file is part of gold.
|
|
|
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
// MA 02110-1301, USA.
|
|
|
|
|
|
|
|
#ifndef GOLD_EHFRAME_H
|
|
|
|
#define GOLD_EHFRAME_H
|
|
|
|
|
2008-02-02 14:50:45 +08:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
|
|
|
|
2007-09-26 13:44:38 +08:00
|
|
|
#include "output.h"
|
2007-11-09 15:00:15 +08:00
|
|
|
#include "merge.h"
|
2007-09-26 13:44:38 +08:00
|
|
|
|
|
|
|
namespace gold
|
|
|
|
{
|
|
|
|
|
2007-11-09 15:00:15 +08:00
|
|
|
template<int size, bool big_endian>
|
|
|
|
class Track_relocs;
|
|
|
|
|
|
|
|
class Eh_frame;
|
|
|
|
|
2007-09-26 13:44:38 +08:00
|
|
|
// This class manages the .eh_frame_hdr section, which holds the data
|
|
|
|
// for the PT_GNU_EH_FRAME segment. gcc's unwind support code uses
|
|
|
|
// the PT_GNU_EH_FRAME segment to find the list of FDEs. This saves
|
|
|
|
// the time required to register the exception handlers at startup
|
|
|
|
// time and when a shared object is loaded, and the time required to
|
|
|
|
// deregister the exception handlers when a shared object is unloaded.
|
|
|
|
|
|
|
|
class Eh_frame_hdr : public Output_section_data
|
|
|
|
{
|
|
|
|
public:
|
2007-11-09 15:00:15 +08:00
|
|
|
Eh_frame_hdr(Output_section* eh_frame_section, const Eh_frame*);
|
|
|
|
|
|
|
|
// Record that we found an unrecognized .eh_frame section.
|
|
|
|
void
|
|
|
|
found_unrecognized_eh_frame_section()
|
|
|
|
{ this->any_unrecognized_eh_frame_sections_ = true; }
|
|
|
|
|
|
|
|
// Record an FDE.
|
|
|
|
void
|
2007-12-18 08:48:04 +08:00
|
|
|
record_fde(section_offset_type fde_offset, unsigned char fde_encoding)
|
2007-11-09 15:00:15 +08:00
|
|
|
{
|
|
|
|
if (!this->any_unrecognized_eh_frame_sections_)
|
2013-11-15 05:15:06 +08:00
|
|
|
this->fde_offsets_.push_back(std::make_pair(fde_offset, fde_encoding));
|
2007-11-09 15:00:15 +08:00
|
|
|
}
|
2007-09-26 13:44:38 +08:00
|
|
|
|
2008-05-22 05:37:44 +08:00
|
|
|
protected:
|
2007-09-26 13:44:38 +08:00
|
|
|
// Set the final data size.
|
|
|
|
void
|
2007-11-30 04:10:17 +08:00
|
|
|
set_final_data_size();
|
2007-09-26 13:44:38 +08:00
|
|
|
|
|
|
|
// Write the data to the file.
|
|
|
|
void
|
|
|
|
do_write(Output_file*);
|
|
|
|
|
2008-05-22 05:37:44 +08:00
|
|
|
// Write to a map file.
|
|
|
|
void
|
|
|
|
do_print_to_mapfile(Mapfile* mapfile) const
|
|
|
|
{ mapfile->print_output_data(this, _("** eh_frame_hdr")); }
|
|
|
|
|
2007-09-26 13:44:38 +08:00
|
|
|
private:
|
2007-11-09 15:00:15 +08:00
|
|
|
// Write the data to the file with the right endianness.
|
|
|
|
template<int size, bool big_endian>
|
|
|
|
void
|
|
|
|
do_sized_write(Output_file*);
|
|
|
|
|
|
|
|
// The data we record for one FDE: the offset of the FDE within the
|
|
|
|
// .eh_frame section, and the FDE encoding.
|
2007-12-18 08:48:04 +08:00
|
|
|
typedef std::pair<section_offset_type, unsigned char> Fde_offset;
|
2007-11-09 15:00:15 +08:00
|
|
|
|
|
|
|
// The list of information we record for an FDE.
|
|
|
|
typedef std::vector<Fde_offset> Fde_offsets;
|
|
|
|
|
|
|
|
// When writing out the header, we convert the FDE offsets into FDE
|
|
|
|
// addresses. This is a list of pairs of the offset from the header
|
|
|
|
// to the FDE PC and to the FDE itself.
|
|
|
|
template<int size>
|
|
|
|
class Fde_addresses
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
|
|
|
|
typedef typename std::pair<Address, Address> Fde_address;
|
|
|
|
typedef typename std::vector<Fde_address> Fde_address_list;
|
|
|
|
typedef typename Fde_address_list::iterator iterator;
|
|
|
|
|
|
|
|
Fde_addresses(unsigned int reserve)
|
|
|
|
: fde_addresses_()
|
|
|
|
{ this->fde_addresses_.reserve(reserve); }
|
|
|
|
|
|
|
|
void
|
|
|
|
push_back(Address pc_address, Address fde_address)
|
|
|
|
{
|
|
|
|
this->fde_addresses_.push_back(std::make_pair(pc_address, fde_address));
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator
|
|
|
|
begin()
|
|
|
|
{ return this->fde_addresses_.begin(); }
|
|
|
|
|
|
|
|
iterator
|
|
|
|
end()
|
|
|
|
{ return this->fde_addresses_.end(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Fde_address_list fde_addresses_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Compare Fde_address objects.
|
|
|
|
template<int size>
|
|
|
|
struct Fde_address_compare
|
|
|
|
{
|
|
|
|
bool
|
|
|
|
operator()(const typename Fde_addresses<size>::Fde_address& f1,
|
|
|
|
const typename Fde_addresses<size>::Fde_address& f2) const
|
|
|
|
{ return f1.first < f2.first; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Return the PC to which an FDE refers.
|
|
|
|
template<int size, bool big_endian>
|
|
|
|
typename elfcpp::Elf_types<size>::Elf_Addr
|
2007-12-07 14:44:01 +08:00
|
|
|
get_fde_pc(typename elfcpp::Elf_types<size>::Elf_Addr eh_frame_address,
|
|
|
|
const unsigned char* eh_frame_contents,
|
2007-12-18 08:48:04 +08:00
|
|
|
section_offset_type fde_offset, unsigned char fde_encoding);
|
2007-11-09 15:00:15 +08:00
|
|
|
|
|
|
|
// Convert Fde_offsets to Fde_addresses.
|
|
|
|
template<int size, bool big_endian>
|
|
|
|
void
|
|
|
|
get_fde_addresses(Output_file* of,
|
|
|
|
const Fde_offsets* fde_offsets,
|
|
|
|
Fde_addresses<size>* fde_addresses);
|
|
|
|
|
2007-09-26 13:44:38 +08:00
|
|
|
// The .eh_frame section.
|
|
|
|
Output_section* eh_frame_section_;
|
2007-11-09 15:00:15 +08:00
|
|
|
// The .eh_frame section data.
|
|
|
|
const Eh_frame* eh_frame_data_;
|
|
|
|
// Data from the FDEs in the .eh_frame sections.
|
|
|
|
Fde_offsets fde_offsets_;
|
|
|
|
// Whether we found any .eh_frame sections which we could not
|
|
|
|
// process.
|
|
|
|
bool any_unrecognized_eh_frame_sections_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class holds an FDE.
|
|
|
|
|
|
|
|
class Fde
|
|
|
|
{
|
|
|
|
public:
|
2007-12-18 08:48:04 +08:00
|
|
|
Fde(Relobj* object, unsigned int shndx, section_offset_type input_offset,
|
2009-12-15 03:53:05 +08:00
|
|
|
const unsigned char* contents, size_t length)
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
: object_(object),
|
2009-12-15 03:53:05 +08:00
|
|
|
contents_(reinterpret_cast<const char*>(contents), length)
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
{
|
|
|
|
this->u_.from_object.shndx = shndx;
|
|
|
|
this->u_.from_object.input_offset = input_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an FDE associated with a PLT.
|
* target.h (Target::plt_fde_location, do_plt_fde_location): Declare.
* target.cc (Target::do_plt_fde_location): New function.
* ehframe.h (class FDE): Add post_map field to u_.from_linker,
accessor function, and constructor param.
(struct Post_fde, Post_fdes): Declare.
(Cie::write): Add post_fdes param.
* ehframe.cc (Fde::write): Use plt_fde_location.
(struct Post_fde): Define.
(Cie::write): Stash FDEs added post merge mapping.
(Eh_frame::add_ehframe_for_plt): Assert no new CIEs after mapping.
Adjust Fde constructor call. Bump final_data_size_ for post map FDEs.
(Eh_frame::do_sized_write): Arrange to write post map FDES after
other FDEs.
* powerpc.cc (Target_powerpc::do_plt_fde_location): New function.
(Target_powerpc::has_glink): New function.
(Target_powerpc::do_relax): Add eh_frame info for stubs.
(struct Eh_cie, eh_frame_cie, glink_eh_frame_fde_64,
glink_eh_frame_fde_32, default_fde): New data.
(Stub_table::eh_frame_added_): New var.
(Stub_table::find_long_branch_entry, stub_address, stub_offset):
Make const.
(Stub_table::add_eh_frame): New function.
(Output_data_glink::add_eh_frame): New function.
(Target_powerpc::make_glink_section): Call add_eh_frame.
2013-02-28 07:11:56 +08:00
|
|
|
Fde(Output_data* plt, const unsigned char* contents, size_t length,
|
|
|
|
bool post_map)
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
: object_(NULL),
|
|
|
|
contents_(reinterpret_cast<const char*>(contents), length)
|
* target.h (Target::plt_fde_location, do_plt_fde_location): Declare.
* target.cc (Target::do_plt_fde_location): New function.
* ehframe.h (class FDE): Add post_map field to u_.from_linker,
accessor function, and constructor param.
(struct Post_fde, Post_fdes): Declare.
(Cie::write): Add post_fdes param.
* ehframe.cc (Fde::write): Use plt_fde_location.
(struct Post_fde): Define.
(Cie::write): Stash FDEs added post merge mapping.
(Eh_frame::add_ehframe_for_plt): Assert no new CIEs after mapping.
Adjust Fde constructor call. Bump final_data_size_ for post map FDEs.
(Eh_frame::do_sized_write): Arrange to write post map FDES after
other FDEs.
* powerpc.cc (Target_powerpc::do_plt_fde_location): New function.
(Target_powerpc::has_glink): New function.
(Target_powerpc::do_relax): Add eh_frame info for stubs.
(struct Eh_cie, eh_frame_cie, glink_eh_frame_fde_64,
glink_eh_frame_fde_32, default_fde): New data.
(Stub_table::eh_frame_added_): New var.
(Stub_table::find_long_branch_entry, stub_address, stub_offset):
Make const.
(Stub_table::add_eh_frame): New function.
(Output_data_glink::add_eh_frame): New function.
(Target_powerpc::make_glink_section): Call add_eh_frame.
2013-02-28 07:11:56 +08:00
|
|
|
{
|
|
|
|
this->u_.from_linker.plt = plt;
|
|
|
|
this->u_.from_linker.post_map = post_map;
|
|
|
|
}
|
2007-11-09 15:00:15 +08:00
|
|
|
|
|
|
|
// Return the length of this FDE. Add 4 for the length and 4 for
|
|
|
|
// the offset to the CIE.
|
|
|
|
size_t
|
|
|
|
length() const
|
|
|
|
{ return this->contents_.length() + 8; }
|
|
|
|
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
// Add a mapping for this FDE to MERGE_MAP, so that relocations
|
|
|
|
// against the FDE are applied to right part of the output file.
|
2007-11-09 15:00:15 +08:00
|
|
|
void
|
2015-03-05 07:10:18 +08:00
|
|
|
add_mapping(section_offset_type output_offset,
|
|
|
|
Output_section_data* output_data) const
|
2007-11-09 15:00:15 +08:00
|
|
|
{
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
if (this->object_ != NULL)
|
2015-03-05 07:10:18 +08:00
|
|
|
this->object_->add_merge_mapping(output_data, this->u_.from_object.shndx,
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
this->u_.from_object.input_offset, this->length(),
|
|
|
|
output_offset);
|
2007-11-09 15:00:15 +08:00
|
|
|
}
|
|
|
|
|
* target.h (Target::plt_fde_location, do_plt_fde_location): Declare.
* target.cc (Target::do_plt_fde_location): New function.
* ehframe.h (class FDE): Add post_map field to u_.from_linker,
accessor function, and constructor param.
(struct Post_fde, Post_fdes): Declare.
(Cie::write): Add post_fdes param.
* ehframe.cc (Fde::write): Use plt_fde_location.
(struct Post_fde): Define.
(Cie::write): Stash FDEs added post merge mapping.
(Eh_frame::add_ehframe_for_plt): Assert no new CIEs after mapping.
Adjust Fde constructor call. Bump final_data_size_ for post map FDEs.
(Eh_frame::do_sized_write): Arrange to write post map FDES after
other FDEs.
* powerpc.cc (Target_powerpc::do_plt_fde_location): New function.
(Target_powerpc::has_glink): New function.
(Target_powerpc::do_relax): Add eh_frame info for stubs.
(struct Eh_cie, eh_frame_cie, glink_eh_frame_fde_64,
glink_eh_frame_fde_32, default_fde): New data.
(Stub_table::eh_frame_added_): New var.
(Stub_table::find_long_branch_entry, stub_address, stub_offset):
Make const.
(Stub_table::add_eh_frame): New function.
(Output_data_glink::add_eh_frame): New function.
(Target_powerpc::make_glink_section): Call add_eh_frame.
2013-02-28 07:11:56 +08:00
|
|
|
// Return whether this FDE was added after merge mapping.
|
|
|
|
bool
|
[GOLD] PowerPC notoc eh_frame
When generating notoc call and branch stubs without the benefit of
pc-relative insns, the stubs need to use LR to access the run time PC.
All LR changes must be described in .eh_frame if we're to support
unwinding through asynchronous exceptions. That's what this patch
does.
The patch has gone through way too many iterations. At first I
attempted to add multiple FDEs, one for each stub. That ran into
difficulties with do_plt_fde_location which is only capable of setting
the address of a single FDE per Output_data section, and with removing
any FDEs added on a previous do_relax pass. Removing FDEs (git commit
be897fb774) went overboard in matching the FDE contents. That means
either stashing the contents created for add_eh_frame_for_plt to use
when calling remove_eh_frame_for_plt, or recreating contents on the
fly (*) just to remove FDEs. In fact, FDE content matching is quite
unnecesary. FDEs added by a previous do_relax pass are those with
u_.from_linker.post_map set. So they can easily be recognised just by
looking at that flag. This patch keeps that part of the multiple FDE
changes.
In the end I went for just one FDE per stub group to describe the call
stubs. That's reasonably efficient for the common case of only
needing to describe the __tls_get_addr_opt call stub. We don't expect
to be making many calls using notoc stubs without pc-relative insns.
*) Which has it's own set of problems. The contents must be recreated
using the old stub layout, but .eh_frame size can affect stub
requirements so you need to temporarily keep the old .eh_frame size
when creating new stubs, then reset .eh_frame size before adding new
FDEs.
* ehframe.cc (Fde::operator==): Delete.
(Cie::remove_fde): Delete.
(Eh_frame::remove_ehframe_for_plt): Delete fde_data and fde_length
parameters. Remove all post-map plt FDEs.
* ehframe.h (Fde:post_map): Make const, add variant to compare plt.
(Fde::operator==): Delete.
(Cie::remove_fde): Implement here.
(Cie::last_fde): New accessor.
(Eh_frame::remove_ehframe_for_plt): Update prototype.
* layout.cc (Layout::remove_eh_frame_for_plt): Delete fde_data and
fde_length parameters.
* layout.h (Layout::remove_eh_frame_for_plt): Update prototype.
* powerpc.cc (Stub_table::tls_get_addr_opt_bctrl_): Delete.
(Stub_table::plt_fde_len_, plt_fde_, init_plt_fde): Delete.
(Stub_table::add_plt_call_entry): Don't set tls_get_addr_opt_bctrl_.
(eh_advance): New function.
(stub_sort): New function.
(Stub_table::add_eh_frame): Emit eh_frame for notoc plt calls and
branches as well as __tls_get_addr_opt plt call stub.
(Stub_table::remove_eh_frame): Update to suit.
2019-07-01 13:07:49 +08:00
|
|
|
post_map() const
|
* target.h (Target::plt_fde_location, do_plt_fde_location): Declare.
* target.cc (Target::do_plt_fde_location): New function.
* ehframe.h (class FDE): Add post_map field to u_.from_linker,
accessor function, and constructor param.
(struct Post_fde, Post_fdes): Declare.
(Cie::write): Add post_fdes param.
* ehframe.cc (Fde::write): Use plt_fde_location.
(struct Post_fde): Define.
(Cie::write): Stash FDEs added post merge mapping.
(Eh_frame::add_ehframe_for_plt): Assert no new CIEs after mapping.
Adjust Fde constructor call. Bump final_data_size_ for post map FDEs.
(Eh_frame::do_sized_write): Arrange to write post map FDES after
other FDEs.
* powerpc.cc (Target_powerpc::do_plt_fde_location): New function.
(Target_powerpc::has_glink): New function.
(Target_powerpc::do_relax): Add eh_frame info for stubs.
(struct Eh_cie, eh_frame_cie, glink_eh_frame_fde_64,
glink_eh_frame_fde_32, default_fde): New data.
(Stub_table::eh_frame_added_): New var.
(Stub_table::find_long_branch_entry, stub_address, stub_offset):
Make const.
(Stub_table::add_eh_frame): New function.
(Output_data_glink::add_eh_frame): New function.
(Target_powerpc::make_glink_section): Call add_eh_frame.
2013-02-28 07:11:56 +08:00
|
|
|
{ return this->object_ == NULL && this->u_.from_linker.post_map; }
|
|
|
|
|
[GOLD] PowerPC notoc eh_frame
When generating notoc call and branch stubs without the benefit of
pc-relative insns, the stubs need to use LR to access the run time PC.
All LR changes must be described in .eh_frame if we're to support
unwinding through asynchronous exceptions. That's what this patch
does.
The patch has gone through way too many iterations. At first I
attempted to add multiple FDEs, one for each stub. That ran into
difficulties with do_plt_fde_location which is only capable of setting
the address of a single FDE per Output_data section, and with removing
any FDEs added on a previous do_relax pass. Removing FDEs (git commit
be897fb774) went overboard in matching the FDE contents. That means
either stashing the contents created for add_eh_frame_for_plt to use
when calling remove_eh_frame_for_plt, or recreating contents on the
fly (*) just to remove FDEs. In fact, FDE content matching is quite
unnecesary. FDEs added by a previous do_relax pass are those with
u_.from_linker.post_map set. So they can easily be recognised just by
looking at that flag. This patch keeps that part of the multiple FDE
changes.
In the end I went for just one FDE per stub group to describe the call
stubs. That's reasonably efficient for the common case of only
needing to describe the __tls_get_addr_opt call stub. We don't expect
to be making many calls using notoc stubs without pc-relative insns.
*) Which has it's own set of problems. The contents must be recreated
using the old stub layout, but .eh_frame size can affect stub
requirements so you need to temporarily keep the old .eh_frame size
when creating new stubs, then reset .eh_frame size before adding new
FDEs.
* ehframe.cc (Fde::operator==): Delete.
(Cie::remove_fde): Delete.
(Eh_frame::remove_ehframe_for_plt): Delete fde_data and fde_length
parameters. Remove all post-map plt FDEs.
* ehframe.h (Fde:post_map): Make const, add variant to compare plt.
(Fde::operator==): Delete.
(Cie::remove_fde): Implement here.
(Cie::last_fde): New accessor.
(Eh_frame::remove_ehframe_for_plt): Update prototype.
* layout.cc (Layout::remove_eh_frame_for_plt): Delete fde_data and
fde_length parameters.
* layout.h (Layout::remove_eh_frame_for_plt): Update prototype.
* powerpc.cc (Stub_table::tls_get_addr_opt_bctrl_): Delete.
(Stub_table::plt_fde_len_, plt_fde_, init_plt_fde): Delete.
(Stub_table::add_plt_call_entry): Don't set tls_get_addr_opt_bctrl_.
(eh_advance): New function.
(stub_sort): New function.
(Stub_table::add_eh_frame): Emit eh_frame for notoc plt calls and
branches as well as __tls_get_addr_opt plt call stub.
(Stub_table::remove_eh_frame): Update to suit.
2019-07-01 13:07:49 +08:00
|
|
|
// Return whether this FDE was added for the PLT after merge mapping.
|
|
|
|
bool
|
|
|
|
post_map(const Output_data* plt) const
|
|
|
|
{ return this->post_map() && this->u_.from_linker.plt == plt; }
|
|
|
|
|
2007-11-09 15:00:15 +08:00
|
|
|
// Write the FDE to OVIEW starting at OFFSET. FDE_ENCODING is the
|
2008-02-14 10:40:15 +08:00
|
|
|
// encoding, from the CIE. Round up the bytes to ADDRALIGN if
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
// necessary. ADDRESS is the virtual address of OVIEW. Record the
|
|
|
|
// FDE in EH_FRAME_HDR. Return the new offset.
|
2007-11-09 15:00:15 +08:00
|
|
|
template<int size, bool big_endian>
|
2007-12-18 08:48:04 +08:00
|
|
|
section_offset_type
|
2014-07-03 00:39:41 +08:00
|
|
|
write(unsigned char* oview, section_offset_type output_section_offset,
|
|
|
|
section_offset_type offset, uint64_t address, unsigned int addralign,
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
section_offset_type cie_offset, unsigned char fde_encoding,
|
|
|
|
Eh_frame_hdr* eh_frame_hdr);
|
2007-11-09 15:00:15 +08:00
|
|
|
|
|
|
|
private:
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
// The object in which this FDE was seen. This will be NULL for a
|
|
|
|
// linker generated FDE.
|
2007-11-09 15:00:15 +08:00
|
|
|
Relobj* object_;
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
union
|
|
|
|
{
|
|
|
|
// These fields are used if the FDE is from an input object (the
|
|
|
|
// object_ field is not NULL).
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
// Input section index for this FDE.
|
|
|
|
unsigned int shndx;
|
|
|
|
// Offset within the input section for this FDE.
|
|
|
|
section_offset_type input_offset;
|
|
|
|
} from_object;
|
|
|
|
// This field is used if the FDE is generated by the linker (the
|
|
|
|
// object_ field is NULL).
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
// The only linker generated FDEs are for PLT sections, and this
|
|
|
|
// points to the PLT section.
|
|
|
|
Output_data* plt;
|
* target.h (Target::plt_fde_location, do_plt_fde_location): Declare.
* target.cc (Target::do_plt_fde_location): New function.
* ehframe.h (class FDE): Add post_map field to u_.from_linker,
accessor function, and constructor param.
(struct Post_fde, Post_fdes): Declare.
(Cie::write): Add post_fdes param.
* ehframe.cc (Fde::write): Use plt_fde_location.
(struct Post_fde): Define.
(Cie::write): Stash FDEs added post merge mapping.
(Eh_frame::add_ehframe_for_plt): Assert no new CIEs after mapping.
Adjust Fde constructor call. Bump final_data_size_ for post map FDEs.
(Eh_frame::do_sized_write): Arrange to write post map FDES after
other FDEs.
* powerpc.cc (Target_powerpc::do_plt_fde_location): New function.
(Target_powerpc::has_glink): New function.
(Target_powerpc::do_relax): Add eh_frame info for stubs.
(struct Eh_cie, eh_frame_cie, glink_eh_frame_fde_64,
glink_eh_frame_fde_32, default_fde): New data.
(Stub_table::eh_frame_added_): New var.
(Stub_table::find_long_branch_entry, stub_address, stub_offset):
Make const.
(Stub_table::add_eh_frame): New function.
(Output_data_glink::add_eh_frame): New function.
(Target_powerpc::make_glink_section): Call add_eh_frame.
2013-02-28 07:11:56 +08:00
|
|
|
// Set if the FDE was added after merge mapping.
|
|
|
|
bool post_map;
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
} from_linker;
|
|
|
|
} u_;
|
2007-11-09 15:00:15 +08:00
|
|
|
// FDE data.
|
|
|
|
std::string contents_;
|
|
|
|
};
|
|
|
|
|
2013-03-08 07:27:53 +08:00
|
|
|
// A FDE plus some info from a CIE to allow later writing of the FDE.
|
* target.h (Target::plt_fde_location, do_plt_fde_location): Declare.
* target.cc (Target::do_plt_fde_location): New function.
* ehframe.h (class FDE): Add post_map field to u_.from_linker,
accessor function, and constructor param.
(struct Post_fde, Post_fdes): Declare.
(Cie::write): Add post_fdes param.
* ehframe.cc (Fde::write): Use plt_fde_location.
(struct Post_fde): Define.
(Cie::write): Stash FDEs added post merge mapping.
(Eh_frame::add_ehframe_for_plt): Assert no new CIEs after mapping.
Adjust Fde constructor call. Bump final_data_size_ for post map FDEs.
(Eh_frame::do_sized_write): Arrange to write post map FDES after
other FDEs.
* powerpc.cc (Target_powerpc::do_plt_fde_location): New function.
(Target_powerpc::has_glink): New function.
(Target_powerpc::do_relax): Add eh_frame info for stubs.
(struct Eh_cie, eh_frame_cie, glink_eh_frame_fde_64,
glink_eh_frame_fde_32, default_fde): New data.
(Stub_table::eh_frame_added_): New var.
(Stub_table::find_long_branch_entry, stub_address, stub_offset):
Make const.
(Stub_table::add_eh_frame): New function.
(Output_data_glink::add_eh_frame): New function.
(Target_powerpc::make_glink_section): Call add_eh_frame.
2013-02-28 07:11:56 +08:00
|
|
|
|
2013-03-08 07:27:53 +08:00
|
|
|
struct Post_fde
|
|
|
|
{
|
|
|
|
Post_fde(Fde* f, section_offset_type cie_off, unsigned char encoding)
|
|
|
|
: fde(f), cie_offset(cie_off), fde_encoding(encoding)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
Fde* fde;
|
|
|
|
section_offset_type cie_offset;
|
|
|
|
unsigned char fde_encoding;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Post_fde> Post_fdes;
|
* target.h (Target::plt_fde_location, do_plt_fde_location): Declare.
* target.cc (Target::do_plt_fde_location): New function.
* ehframe.h (class FDE): Add post_map field to u_.from_linker,
accessor function, and constructor param.
(struct Post_fde, Post_fdes): Declare.
(Cie::write): Add post_fdes param.
* ehframe.cc (Fde::write): Use plt_fde_location.
(struct Post_fde): Define.
(Cie::write): Stash FDEs added post merge mapping.
(Eh_frame::add_ehframe_for_plt): Assert no new CIEs after mapping.
Adjust Fde constructor call. Bump final_data_size_ for post map FDEs.
(Eh_frame::do_sized_write): Arrange to write post map FDES after
other FDEs.
* powerpc.cc (Target_powerpc::do_plt_fde_location): New function.
(Target_powerpc::has_glink): New function.
(Target_powerpc::do_relax): Add eh_frame info for stubs.
(struct Eh_cie, eh_frame_cie, glink_eh_frame_fde_64,
glink_eh_frame_fde_32, default_fde): New data.
(Stub_table::eh_frame_added_): New var.
(Stub_table::find_long_branch_entry, stub_address, stub_offset):
Make const.
(Stub_table::add_eh_frame): New function.
(Output_data_glink::add_eh_frame): New function.
(Target_powerpc::make_glink_section): Call add_eh_frame.
2013-02-28 07:11:56 +08:00
|
|
|
|
2007-11-09 15:00:15 +08:00
|
|
|
// This class holds a CIE.
|
|
|
|
|
|
|
|
class Cie
|
|
|
|
{
|
|
|
|
public:
|
2007-12-18 08:48:04 +08:00
|
|
|
Cie(Relobj* object, unsigned int shndx, section_offset_type input_offset,
|
2007-11-09 15:00:15 +08:00
|
|
|
unsigned char fde_encoding, const char* personality_name,
|
|
|
|
const unsigned char* contents, size_t length)
|
|
|
|
: object_(object),
|
|
|
|
shndx_(shndx),
|
|
|
|
input_offset_(input_offset),
|
|
|
|
fde_encoding_(fde_encoding),
|
|
|
|
personality_name_(personality_name),
|
|
|
|
fdes_(),
|
|
|
|
contents_(reinterpret_cast<const char*>(contents), length)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~Cie();
|
|
|
|
|
|
|
|
// We permit copying a CIE when there are no FDEs. This is
|
|
|
|
// convenient in the code which creates them.
|
|
|
|
Cie(const Cie& cie)
|
|
|
|
: object_(cie.object_),
|
|
|
|
shndx_(cie.shndx_),
|
|
|
|
input_offset_(cie.input_offset_),
|
|
|
|
fde_encoding_(cie.fde_encoding_),
|
|
|
|
personality_name_(cie.personality_name_),
|
|
|
|
fdes_(),
|
|
|
|
contents_(cie.contents_)
|
|
|
|
{ gold_assert(cie.fdes_.empty()); }
|
|
|
|
|
|
|
|
// Add an FDE associated with this CIE.
|
|
|
|
void
|
|
|
|
add_fde(Fde* fde)
|
|
|
|
{ this->fdes_.push_back(fde); }
|
|
|
|
|
[GOLD] PowerPC notoc eh_frame
When generating notoc call and branch stubs without the benefit of
pc-relative insns, the stubs need to use LR to access the run time PC.
All LR changes must be described in .eh_frame if we're to support
unwinding through asynchronous exceptions. That's what this patch
does.
The patch has gone through way too many iterations. At first I
attempted to add multiple FDEs, one for each stub. That ran into
difficulties with do_plt_fde_location which is only capable of setting
the address of a single FDE per Output_data section, and with removing
any FDEs added on a previous do_relax pass. Removing FDEs (git commit
be897fb774) went overboard in matching the FDE contents. That means
either stashing the contents created for add_eh_frame_for_plt to use
when calling remove_eh_frame_for_plt, or recreating contents on the
fly (*) just to remove FDEs. In fact, FDE content matching is quite
unnecesary. FDEs added by a previous do_relax pass are those with
u_.from_linker.post_map set. So they can easily be recognised just by
looking at that flag. This patch keeps that part of the multiple FDE
changes.
In the end I went for just one FDE per stub group to describe the call
stubs. That's reasonably efficient for the common case of only
needing to describe the __tls_get_addr_opt call stub. We don't expect
to be making many calls using notoc stubs without pc-relative insns.
*) Which has it's own set of problems. The contents must be recreated
using the old stub layout, but .eh_frame size can affect stub
requirements so you need to temporarily keep the old .eh_frame size
when creating new stubs, then reset .eh_frame size before adding new
FDEs.
* ehframe.cc (Fde::operator==): Delete.
(Cie::remove_fde): Delete.
(Eh_frame::remove_ehframe_for_plt): Delete fde_data and fde_length
parameters. Remove all post-map plt FDEs.
* ehframe.h (Fde:post_map): Make const, add variant to compare plt.
(Fde::operator==): Delete.
(Cie::remove_fde): Implement here.
(Cie::last_fde): New accessor.
(Eh_frame::remove_ehframe_for_plt): Update prototype.
* layout.cc (Layout::remove_eh_frame_for_plt): Delete fde_data and
fde_length parameters.
* layout.h (Layout::remove_eh_frame_for_plt): Update prototype.
* powerpc.cc (Stub_table::tls_get_addr_opt_bctrl_): Delete.
(Stub_table::plt_fde_len_, plt_fde_, init_plt_fde): Delete.
(Stub_table::add_plt_call_entry): Don't set tls_get_addr_opt_bctrl_.
(eh_advance): New function.
(stub_sort): New function.
(Stub_table::add_eh_frame): Emit eh_frame for notoc plt calls and
branches as well as __tls_get_addr_opt plt call stub.
(Stub_table::remove_eh_frame): Update to suit.
2019-07-01 13:07:49 +08:00
|
|
|
// Remove the last FDE associated with this CIE.
|
[GOLD] PowerPC recreate eh_frame for stubs on each relax pass
There is a very small but non-zero probability that a stub group
contains stubs on one relax pass, but does not on the next. In that
case we would get an FDE covering a zero length address range.
(Actually, it's even worse. Alignment padding for stubs can mean the
address for the non-existent stubs is past the end of the original
section to which stubs are attached, and due to the way
do_plt_fde_location calculates the length we can get a negative
length.) Fixing this properly requires removing the FDE.
Also, I have been implementing the __tls_get_addr_opt support for
gold, and that stub needs something other than the default FDE. The
necessary FDE will depend on the offset to the __tls_get_addr_opt
stub, which of course can change during relaxation. That means at the
very least, rewriting the FDE on each pass, possibly changing the FDE
size. I think that is better done by completely recreating PLT
eh_frame FDEs.
* ehframe.cc (Fde::operator==): New.
(Cie::remove_fde, Eh_frame::remove_ehframe_for_plt): New.
* ehframe.h (Fde::operator==): Declare.
(Cie::remove_fde, Eh_frame::remove_ehframe_for_plt): Likewise.
* layout.cc (Layout::remove_eh_frame_for_plt): New.
* layout.h (Layout::remove_eh_frame_for_plt): Declare.
* powerpc.cc (Target_powerpc::do_relax): Remove old eh_frame FDEs.
(Stub_table::add_eh_frame): Delete eh_frame_added_ condition.
Don't add eh_frame for empty stub section.
(Stub_table::remove_eh_frame): New.
2017-08-01 12:38:53 +08:00
|
|
|
void
|
[GOLD] PowerPC notoc eh_frame
When generating notoc call and branch stubs without the benefit of
pc-relative insns, the stubs need to use LR to access the run time PC.
All LR changes must be described in .eh_frame if we're to support
unwinding through asynchronous exceptions. That's what this patch
does.
The patch has gone through way too many iterations. At first I
attempted to add multiple FDEs, one for each stub. That ran into
difficulties with do_plt_fde_location which is only capable of setting
the address of a single FDE per Output_data section, and with removing
any FDEs added on a previous do_relax pass. Removing FDEs (git commit
be897fb774) went overboard in matching the FDE contents. That means
either stashing the contents created for add_eh_frame_for_plt to use
when calling remove_eh_frame_for_plt, or recreating contents on the
fly (*) just to remove FDEs. In fact, FDE content matching is quite
unnecesary. FDEs added by a previous do_relax pass are those with
u_.from_linker.post_map set. So they can easily be recognised just by
looking at that flag. This patch keeps that part of the multiple FDE
changes.
In the end I went for just one FDE per stub group to describe the call
stubs. That's reasonably efficient for the common case of only
needing to describe the __tls_get_addr_opt call stub. We don't expect
to be making many calls using notoc stubs without pc-relative insns.
*) Which has it's own set of problems. The contents must be recreated
using the old stub layout, but .eh_frame size can affect stub
requirements so you need to temporarily keep the old .eh_frame size
when creating new stubs, then reset .eh_frame size before adding new
FDEs.
* ehframe.cc (Fde::operator==): Delete.
(Cie::remove_fde): Delete.
(Eh_frame::remove_ehframe_for_plt): Delete fde_data and fde_length
parameters. Remove all post-map plt FDEs.
* ehframe.h (Fde:post_map): Make const, add variant to compare plt.
(Fde::operator==): Delete.
(Cie::remove_fde): Implement here.
(Cie::last_fde): New accessor.
(Eh_frame::remove_ehframe_for_plt): Update prototype.
* layout.cc (Layout::remove_eh_frame_for_plt): Delete fde_data and
fde_length parameters.
* layout.h (Layout::remove_eh_frame_for_plt): Update prototype.
* powerpc.cc (Stub_table::tls_get_addr_opt_bctrl_): Delete.
(Stub_table::plt_fde_len_, plt_fde_, init_plt_fde): Delete.
(Stub_table::add_plt_call_entry): Don't set tls_get_addr_opt_bctrl_.
(eh_advance): New function.
(stub_sort): New function.
(Stub_table::add_eh_frame): Emit eh_frame for notoc plt calls and
branches as well as __tls_get_addr_opt plt call stub.
(Stub_table::remove_eh_frame): Update to suit.
2019-07-01 13:07:49 +08:00
|
|
|
remove_fde()
|
|
|
|
{ this->fdes_.pop_back(); }
|
|
|
|
|
|
|
|
// Access the last FDE associated with this CIE.
|
|
|
|
const Fde*
|
|
|
|
last_fde() const
|
|
|
|
{ return this->fdes_.back(); }
|
[GOLD] PowerPC recreate eh_frame for stubs on each relax pass
There is a very small but non-zero probability that a stub group
contains stubs on one relax pass, but does not on the next. In that
case we would get an FDE covering a zero length address range.
(Actually, it's even worse. Alignment padding for stubs can mean the
address for the non-existent stubs is past the end of the original
section to which stubs are attached, and due to the way
do_plt_fde_location calculates the length we can get a negative
length.) Fixing this properly requires removing the FDE.
Also, I have been implementing the __tls_get_addr_opt support for
gold, and that stub needs something other than the default FDE. The
necessary FDE will depend on the offset to the __tls_get_addr_opt
stub, which of course can change during relaxation. That means at the
very least, rewriting the FDE on each pass, possibly changing the FDE
size. I think that is better done by completely recreating PLT
eh_frame FDEs.
* ehframe.cc (Fde::operator==): New.
(Cie::remove_fde, Eh_frame::remove_ehframe_for_plt): New.
* ehframe.h (Fde::operator==): Declare.
(Cie::remove_fde, Eh_frame::remove_ehframe_for_plt): Likewise.
* layout.cc (Layout::remove_eh_frame_for_plt): New.
* layout.h (Layout::remove_eh_frame_for_plt): Declare.
* powerpc.cc (Target_powerpc::do_relax): Remove old eh_frame FDEs.
(Stub_table::add_eh_frame): Delete eh_frame_added_ condition.
Don't add eh_frame for empty stub section.
(Stub_table::remove_eh_frame): New.
2017-08-01 12:38:53 +08:00
|
|
|
|
2007-11-09 15:00:15 +08:00
|
|
|
// Return the number of FDEs.
|
|
|
|
unsigned int
|
|
|
|
fde_count() const
|
|
|
|
{ return this->fdes_.size(); }
|
|
|
|
|
|
|
|
// Set the output offset of this CIE to OUTPUT_OFFSET. It will be
|
|
|
|
// followed by all its FDEs. ADDRALIGN is the required address
|
|
|
|
// alignment, typically 4 or 8. This updates MERGE_MAP with the
|
|
|
|
// mapping. It returns the new output offset.
|
2007-12-18 08:48:04 +08:00
|
|
|
section_offset_type
|
|
|
|
set_output_offset(section_offset_type output_offset, unsigned int addralign,
|
2015-03-05 07:10:18 +08:00
|
|
|
Output_section_data*);
|
2007-11-09 15:00:15 +08:00
|
|
|
|
* target.h (Target::plt_fde_location, do_plt_fde_location): Declare.
* target.cc (Target::do_plt_fde_location): New function.
* ehframe.h (class FDE): Add post_map field to u_.from_linker,
accessor function, and constructor param.
(struct Post_fde, Post_fdes): Declare.
(Cie::write): Add post_fdes param.
* ehframe.cc (Fde::write): Use plt_fde_location.
(struct Post_fde): Define.
(Cie::write): Stash FDEs added post merge mapping.
(Eh_frame::add_ehframe_for_plt): Assert no new CIEs after mapping.
Adjust Fde constructor call. Bump final_data_size_ for post map FDEs.
(Eh_frame::do_sized_write): Arrange to write post map FDES after
other FDEs.
* powerpc.cc (Target_powerpc::do_plt_fde_location): New function.
(Target_powerpc::has_glink): New function.
(Target_powerpc::do_relax): Add eh_frame info for stubs.
(struct Eh_cie, eh_frame_cie, glink_eh_frame_fde_64,
glink_eh_frame_fde_32, default_fde): New data.
(Stub_table::eh_frame_added_): New var.
(Stub_table::find_long_branch_entry, stub_address, stub_offset):
Make const.
(Stub_table::add_eh_frame): New function.
(Output_data_glink::add_eh_frame): New function.
(Target_powerpc::make_glink_section): Call add_eh_frame.
2013-02-28 07:11:56 +08:00
|
|
|
// Write the CIE to OVIEW starting at OFFSET. Round up the bytes to
|
|
|
|
// ADDRALIGN. ADDRESS is the virtual address of OVIEW.
|
|
|
|
// EH_FRAME_HDR is the exception frame header for FDE recording.
|
|
|
|
// POST_FDES stashes FDEs created after mappings were done, for later
|
|
|
|
// writing. Return the new offset.
|
2007-11-09 15:00:15 +08:00
|
|
|
template<int size, bool big_endian>
|
2007-12-18 08:48:04 +08:00
|
|
|
section_offset_type
|
2014-07-03 00:39:41 +08:00
|
|
|
write(unsigned char* oview, section_offset_type output_section_offset,
|
|
|
|
section_offset_type offset, uint64_t address,
|
* target.h (Target::plt_fde_location, do_plt_fde_location): Declare.
* target.cc (Target::do_plt_fde_location): New function.
* ehframe.h (class FDE): Add post_map field to u_.from_linker,
accessor function, and constructor param.
(struct Post_fde, Post_fdes): Declare.
(Cie::write): Add post_fdes param.
* ehframe.cc (Fde::write): Use plt_fde_location.
(struct Post_fde): Define.
(Cie::write): Stash FDEs added post merge mapping.
(Eh_frame::add_ehframe_for_plt): Assert no new CIEs after mapping.
Adjust Fde constructor call. Bump final_data_size_ for post map FDEs.
(Eh_frame::do_sized_write): Arrange to write post map FDES after
other FDEs.
* powerpc.cc (Target_powerpc::do_plt_fde_location): New function.
(Target_powerpc::has_glink): New function.
(Target_powerpc::do_relax): Add eh_frame info for stubs.
(struct Eh_cie, eh_frame_cie, glink_eh_frame_fde_64,
glink_eh_frame_fde_32, default_fde): New data.
(Stub_table::eh_frame_added_): New var.
(Stub_table::find_long_branch_entry, stub_address, stub_offset):
Make const.
(Stub_table::add_eh_frame): New function.
(Output_data_glink::add_eh_frame): New function.
(Target_powerpc::make_glink_section): Call add_eh_frame.
2013-02-28 07:11:56 +08:00
|
|
|
unsigned int addralign, Eh_frame_hdr* eh_frame_hdr,
|
|
|
|
Post_fdes* post_fdes);
|
2007-11-09 15:00:15 +08:00
|
|
|
|
2016-02-26 23:50:15 +08:00
|
|
|
// Return the FDE encoding.
|
|
|
|
unsigned char
|
|
|
|
fde_encoding() const
|
|
|
|
{ return this->fde_encoding_; }
|
|
|
|
|
2007-11-09 15:00:15 +08:00
|
|
|
friend bool operator<(const Cie&, const Cie&);
|
|
|
|
friend bool operator==(const Cie&, const Cie&);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// The class is not assignable.
|
|
|
|
Cie& operator=(const Cie&);
|
|
|
|
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
// The object in which this CIE was first seen. This will be NULL
|
|
|
|
// for a linker generated CIE.
|
2007-11-09 15:00:15 +08:00
|
|
|
Relobj* object_;
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
// Input section index for this CIE. This will be 0 for a linker
|
|
|
|
// generated CIE.
|
2007-11-09 15:00:15 +08:00
|
|
|
unsigned int shndx_;
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
// Offset within the input section for this CIE. This will be 0 for
|
|
|
|
// a linker generated CIE.
|
2007-12-18 08:48:04 +08:00
|
|
|
section_offset_type input_offset_;
|
2007-11-09 15:00:15 +08:00
|
|
|
// The encoding of the FDE. This is a DW_EH_PE code.
|
|
|
|
unsigned char fde_encoding_;
|
|
|
|
// The name of the personality routine. This will be the name of a
|
|
|
|
// global symbol, or will be the empty string.
|
|
|
|
std::string personality_name_;
|
|
|
|
// List of FDEs.
|
|
|
|
std::vector<Fde*> fdes_;
|
|
|
|
// CIE data.
|
|
|
|
std::string contents_;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern bool operator<(const Cie&, const Cie&);
|
|
|
|
extern bool operator==(const Cie&, const Cie&);
|
|
|
|
|
|
|
|
// This class manages .eh_frame sections. It discards duplicate
|
|
|
|
// exception information.
|
|
|
|
|
|
|
|
class Eh_frame : public Output_section_data
|
|
|
|
{
|
|
|
|
public:
|
2015-03-10 01:10:29 +08:00
|
|
|
enum Eh_frame_section_disposition
|
|
|
|
{
|
|
|
|
EH_EMPTY_SECTION,
|
|
|
|
EH_UNRECOGNIZED_SECTION,
|
|
|
|
EH_OPTIMIZABLE_SECTION,
|
|
|
|
EH_END_MARKER_SECTION
|
|
|
|
};
|
|
|
|
|
2007-11-09 15:00:15 +08:00
|
|
|
Eh_frame();
|
|
|
|
|
|
|
|
// Record the associated Eh_frame_hdr, if any.
|
|
|
|
void
|
|
|
|
set_eh_frame_hdr(Eh_frame_hdr* hdr)
|
|
|
|
{ this->eh_frame_hdr_ = hdr; }
|
|
|
|
|
|
|
|
// Add the input section SHNDX in OBJECT. SYMBOLS is the contents
|
|
|
|
// of the symbol table section (size SYMBOLS_SIZE), SYMBOL_NAMES is
|
|
|
|
// the symbol names section (size SYMBOL_NAMES_SIZE). RELOC_SHNDX
|
|
|
|
// is the relocation section if any (0 for none, -1U for multiple).
|
|
|
|
// RELOC_TYPE is the type of the relocation section if any. This
|
|
|
|
// returns whether the section was incorporated into the .eh_frame
|
|
|
|
// data.
|
|
|
|
template<int size, bool big_endian>
|
2015-03-10 01:10:29 +08:00
|
|
|
Eh_frame_section_disposition
|
2011-05-25 05:41:10 +08:00
|
|
|
add_ehframe_input_section(Sized_relobj_file<size, big_endian>* object,
|
2007-11-09 15:00:15 +08:00
|
|
|
const unsigned char* symbols,
|
2007-12-18 08:48:04 +08:00
|
|
|
section_size_type symbols_size,
|
2007-11-09 15:00:15 +08:00
|
|
|
const unsigned char* symbol_names,
|
2007-12-18 08:48:04 +08:00
|
|
|
section_size_type symbol_names_size,
|
2007-11-09 15:00:15 +08:00
|
|
|
unsigned int shndx, unsigned int reloc_shndx,
|
|
|
|
unsigned int reloc_type);
|
|
|
|
|
PR gold/12571
* options.h (class General_options): Add
--ld-generated-unwind-info.
* ehframe.cc (Fde::write): Add address parameter. Change all
callers. If associated with PLT, fill in address and size.
(Cie::set_output_offset): Only add merge mapping if there is an
object.
(Cie::write): Add address parameter. Change all callers.
(Eh_frame::add_ehframe_for_plt): New function.
* ehframe.h (class Fde): Update declarations. Move shndx_ and
input_offset_ fields into union u_, with new plt field.
(Fde::Fde): Adjust for new union field.
(Fde::Fde) [Output_data version]: New constructor.
(Fde::add_mapping): Only add merge mapping if there is an object.
(class Cie): Update declarations.
(class Eh_frame): Declare add_ehframe_for_plt.
* layout.cc (Layout::layout_eh_frame): Break out code into
make_eh_frame_section, and call it.
(Layout::make_eh_frame_section): New function.
(Layout::add_eh_frame_for_plt): New function.
* layout.h (class Layout): Update declarations.
* merge.cc (Merge_map::add_mapping): Add assertion.
* i386.cc: Include "dwarf.h".
(class Output_data_plt_i386): Make first_plt_entry,
dyn_first_plt_entry, exec_plt_entry, and dyn_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_i386::Output_data_plt_i386): Align to 16-byte
boundary. Call add_eh_frame_for_plt if appropriate.
* x86_64.cc: Include "dwarf.h".
(class Output_data_plt_x86_64): Align to 16-byte boundary. Make
first_plt_entry, plt_entry and tlsdesc_plt_entry const. Add
plt_eh_frame_cie_size, plt_eh_frame_fde_size, plt_eh_frame_cie,
and plt_eh_frame_fde.
(Output_data_plt_x86_64::init): Call add_eh_frame_for_plt if
appropriate.
2011-07-02 06:05:01 +08:00
|
|
|
// Add a CIE and an FDE for a PLT section, to permit unwinding
|
|
|
|
// through a PLT. The FDE data should start with 8 bytes of zero,
|
|
|
|
// which will be replaced by a 4 byte PC relative reference to the
|
|
|
|
// address of PLT and a 4 byte size of PLT.
|
|
|
|
void
|
|
|
|
add_ehframe_for_plt(Output_data* plt, const unsigned char* cie_data,
|
|
|
|
size_t cie_length, const unsigned char* fde_data,
|
|
|
|
size_t fde_length);
|
|
|
|
|
[GOLD] PowerPC notoc eh_frame
When generating notoc call and branch stubs without the benefit of
pc-relative insns, the stubs need to use LR to access the run time PC.
All LR changes must be described in .eh_frame if we're to support
unwinding through asynchronous exceptions. That's what this patch
does.
The patch has gone through way too many iterations. At first I
attempted to add multiple FDEs, one for each stub. That ran into
difficulties with do_plt_fde_location which is only capable of setting
the address of a single FDE per Output_data section, and with removing
any FDEs added on a previous do_relax pass. Removing FDEs (git commit
be897fb774) went overboard in matching the FDE contents. That means
either stashing the contents created for add_eh_frame_for_plt to use
when calling remove_eh_frame_for_plt, or recreating contents on the
fly (*) just to remove FDEs. In fact, FDE content matching is quite
unnecesary. FDEs added by a previous do_relax pass are those with
u_.from_linker.post_map set. So they can easily be recognised just by
looking at that flag. This patch keeps that part of the multiple FDE
changes.
In the end I went for just one FDE per stub group to describe the call
stubs. That's reasonably efficient for the common case of only
needing to describe the __tls_get_addr_opt call stub. We don't expect
to be making many calls using notoc stubs without pc-relative insns.
*) Which has it's own set of problems. The contents must be recreated
using the old stub layout, but .eh_frame size can affect stub
requirements so you need to temporarily keep the old .eh_frame size
when creating new stubs, then reset .eh_frame size before adding new
FDEs.
* ehframe.cc (Fde::operator==): Delete.
(Cie::remove_fde): Delete.
(Eh_frame::remove_ehframe_for_plt): Delete fde_data and fde_length
parameters. Remove all post-map plt FDEs.
* ehframe.h (Fde:post_map): Make const, add variant to compare plt.
(Fde::operator==): Delete.
(Cie::remove_fde): Implement here.
(Cie::last_fde): New accessor.
(Eh_frame::remove_ehframe_for_plt): Update prototype.
* layout.cc (Layout::remove_eh_frame_for_plt): Delete fde_data and
fde_length parameters.
* layout.h (Layout::remove_eh_frame_for_plt): Update prototype.
* powerpc.cc (Stub_table::tls_get_addr_opt_bctrl_): Delete.
(Stub_table::plt_fde_len_, plt_fde_, init_plt_fde): Delete.
(Stub_table::add_plt_call_entry): Don't set tls_get_addr_opt_bctrl_.
(eh_advance): New function.
(stub_sort): New function.
(Stub_table::add_eh_frame): Emit eh_frame for notoc plt calls and
branches as well as __tls_get_addr_opt plt call stub.
(Stub_table::remove_eh_frame): Update to suit.
2019-07-01 13:07:49 +08:00
|
|
|
// Remove all post-map unwind information for a PLT.
|
[GOLD] PowerPC recreate eh_frame for stubs on each relax pass
There is a very small but non-zero probability that a stub group
contains stubs on one relax pass, but does not on the next. In that
case we would get an FDE covering a zero length address range.
(Actually, it's even worse. Alignment padding for stubs can mean the
address for the non-existent stubs is past the end of the original
section to which stubs are attached, and due to the way
do_plt_fde_location calculates the length we can get a negative
length.) Fixing this properly requires removing the FDE.
Also, I have been implementing the __tls_get_addr_opt support for
gold, and that stub needs something other than the default FDE. The
necessary FDE will depend on the offset to the __tls_get_addr_opt
stub, which of course can change during relaxation. That means at the
very least, rewriting the FDE on each pass, possibly changing the FDE
size. I think that is better done by completely recreating PLT
eh_frame FDEs.
* ehframe.cc (Fde::operator==): New.
(Cie::remove_fde, Eh_frame::remove_ehframe_for_plt): New.
* ehframe.h (Fde::operator==): Declare.
(Cie::remove_fde, Eh_frame::remove_ehframe_for_plt): Likewise.
* layout.cc (Layout::remove_eh_frame_for_plt): New.
* layout.h (Layout::remove_eh_frame_for_plt): Declare.
* powerpc.cc (Target_powerpc::do_relax): Remove old eh_frame FDEs.
(Stub_table::add_eh_frame): Delete eh_frame_added_ condition.
Don't add eh_frame for empty stub section.
(Stub_table::remove_eh_frame): New.
2017-08-01 12:38:53 +08:00
|
|
|
void
|
|
|
|
remove_ehframe_for_plt(Output_data* plt, const unsigned char* cie_data,
|
[GOLD] PowerPC notoc eh_frame
When generating notoc call and branch stubs without the benefit of
pc-relative insns, the stubs need to use LR to access the run time PC.
All LR changes must be described in .eh_frame if we're to support
unwinding through asynchronous exceptions. That's what this patch
does.
The patch has gone through way too many iterations. At first I
attempted to add multiple FDEs, one for each stub. That ran into
difficulties with do_plt_fde_location which is only capable of setting
the address of a single FDE per Output_data section, and with removing
any FDEs added on a previous do_relax pass. Removing FDEs (git commit
be897fb774) went overboard in matching the FDE contents. That means
either stashing the contents created for add_eh_frame_for_plt to use
when calling remove_eh_frame_for_plt, or recreating contents on the
fly (*) just to remove FDEs. In fact, FDE content matching is quite
unnecesary. FDEs added by a previous do_relax pass are those with
u_.from_linker.post_map set. So they can easily be recognised just by
looking at that flag. This patch keeps that part of the multiple FDE
changes.
In the end I went for just one FDE per stub group to describe the call
stubs. That's reasonably efficient for the common case of only
needing to describe the __tls_get_addr_opt call stub. We don't expect
to be making many calls using notoc stubs without pc-relative insns.
*) Which has it's own set of problems. The contents must be recreated
using the old stub layout, but .eh_frame size can affect stub
requirements so you need to temporarily keep the old .eh_frame size
when creating new stubs, then reset .eh_frame size before adding new
FDEs.
* ehframe.cc (Fde::operator==): Delete.
(Cie::remove_fde): Delete.
(Eh_frame::remove_ehframe_for_plt): Delete fde_data and fde_length
parameters. Remove all post-map plt FDEs.
* ehframe.h (Fde:post_map): Make const, add variant to compare plt.
(Fde::operator==): Delete.
(Cie::remove_fde): Implement here.
(Cie::last_fde): New accessor.
(Eh_frame::remove_ehframe_for_plt): Update prototype.
* layout.cc (Layout::remove_eh_frame_for_plt): Delete fde_data and
fde_length parameters.
* layout.h (Layout::remove_eh_frame_for_plt): Update prototype.
* powerpc.cc (Stub_table::tls_get_addr_opt_bctrl_): Delete.
(Stub_table::plt_fde_len_, plt_fde_, init_plt_fde): Delete.
(Stub_table::add_plt_call_entry): Don't set tls_get_addr_opt_bctrl_.
(eh_advance): New function.
(stub_sort): New function.
(Stub_table::add_eh_frame): Emit eh_frame for notoc plt calls and
branches as well as __tls_get_addr_opt plt call stub.
(Stub_table::remove_eh_frame): Update to suit.
2019-07-01 13:07:49 +08:00
|
|
|
size_t cie_length);
|
[GOLD] PowerPC recreate eh_frame for stubs on each relax pass
There is a very small but non-zero probability that a stub group
contains stubs on one relax pass, but does not on the next. In that
case we would get an FDE covering a zero length address range.
(Actually, it's even worse. Alignment padding for stubs can mean the
address for the non-existent stubs is past the end of the original
section to which stubs are attached, and due to the way
do_plt_fde_location calculates the length we can get a negative
length.) Fixing this properly requires removing the FDE.
Also, I have been implementing the __tls_get_addr_opt support for
gold, and that stub needs something other than the default FDE. The
necessary FDE will depend on the offset to the __tls_get_addr_opt
stub, which of course can change during relaxation. That means at the
very least, rewriting the FDE on each pass, possibly changing the FDE
size. I think that is better done by completely recreating PLT
eh_frame FDEs.
* ehframe.cc (Fde::operator==): New.
(Cie::remove_fde, Eh_frame::remove_ehframe_for_plt): New.
* ehframe.h (Fde::operator==): Declare.
(Cie::remove_fde, Eh_frame::remove_ehframe_for_plt): Likewise.
* layout.cc (Layout::remove_eh_frame_for_plt): New.
* layout.h (Layout::remove_eh_frame_for_plt): Declare.
* powerpc.cc (Target_powerpc::do_relax): Remove old eh_frame FDEs.
(Stub_table::add_eh_frame): Delete eh_frame_added_ condition.
Don't add eh_frame for empty stub section.
(Stub_table::remove_eh_frame): New.
2017-08-01 12:38:53 +08:00
|
|
|
|
2007-11-09 15:00:15 +08:00
|
|
|
// Return the number of FDEs.
|
|
|
|
unsigned int
|
|
|
|
fde_count() const;
|
|
|
|
|
2008-05-22 05:37:44 +08:00
|
|
|
protected:
|
2007-11-09 15:00:15 +08:00
|
|
|
// Set the final data size.
|
|
|
|
void
|
2007-11-30 04:10:17 +08:00
|
|
|
set_final_data_size();
|
2007-11-09 15:00:15 +08:00
|
|
|
|
|
|
|
// Return the output address for an input address.
|
|
|
|
bool
|
2007-12-18 08:48:04 +08:00
|
|
|
do_output_offset(const Relobj*, unsigned int shndx,
|
|
|
|
section_offset_type offset,
|
|
|
|
section_offset_type* poutput) const;
|
2007-11-09 15:00:15 +08:00
|
|
|
|
|
|
|
// Write the data to the file.
|
|
|
|
void
|
|
|
|
do_write(Output_file*);
|
|
|
|
|
2008-05-22 05:37:44 +08:00
|
|
|
// Write to a map file.
|
|
|
|
void
|
|
|
|
do_print_to_mapfile(Mapfile* mapfile) const
|
|
|
|
{ mapfile->print_output_data(this, _("** eh_frame")); }
|
|
|
|
|
2007-11-09 15:00:15 +08:00
|
|
|
private:
|
|
|
|
// The comparison routine for the CIE map.
|
|
|
|
struct Cie_less
|
|
|
|
{
|
|
|
|
bool
|
|
|
|
operator()(const Cie* cie1, const Cie* cie2) const
|
|
|
|
{ return *cie1 < *cie2; }
|
|
|
|
};
|
|
|
|
|
2008-02-02 14:50:45 +08:00
|
|
|
// A set of unique CIEs.
|
|
|
|
typedef std::set<Cie*, Cie_less> Cie_offsets;
|
2007-11-09 15:00:15 +08:00
|
|
|
|
2008-02-02 14:50:45 +08:00
|
|
|
// A list of unmergeable CIEs.
|
|
|
|
typedef std::vector<Cie*> Unmergeable_cie_offsets;
|
2007-11-09 15:00:15 +08:00
|
|
|
|
|
|
|
// A mapping from offsets to CIEs. This is used while reading an
|
|
|
|
// input section.
|
|
|
|
typedef std::map<uint64_t, Cie*> Offsets_to_cie;
|
|
|
|
|
|
|
|
// A list of CIEs, and a bool indicating whether the CIE is
|
|
|
|
// mergeable.
|
|
|
|
typedef std::vector<std::pair<Cie*, bool> > New_cies;
|
|
|
|
|
|
|
|
// Skip an LEB128.
|
|
|
|
static bool
|
|
|
|
skip_leb128(const unsigned char**, const unsigned char*);
|
|
|
|
|
|
|
|
// The implementation of add_ehframe_input_section.
|
|
|
|
template<int size, bool big_endian>
|
|
|
|
bool
|
2011-05-25 05:41:10 +08:00
|
|
|
do_add_ehframe_input_section(Sized_relobj_file<size, big_endian>* object,
|
2007-11-09 15:00:15 +08:00
|
|
|
const unsigned char* symbols,
|
2007-12-18 08:48:04 +08:00
|
|
|
section_size_type symbols_size,
|
2007-11-09 15:00:15 +08:00
|
|
|
const unsigned char* symbol_names,
|
2007-12-18 08:48:04 +08:00
|
|
|
section_size_type symbol_names_size,
|
2007-11-09 15:00:15 +08:00
|
|
|
unsigned int shndx,
|
|
|
|
unsigned int reloc_shndx,
|
|
|
|
unsigned int reloc_type,
|
|
|
|
const unsigned char* pcontents,
|
2007-12-18 08:48:04 +08:00
|
|
|
section_size_type contents_len,
|
2007-11-09 15:00:15 +08:00
|
|
|
New_cies*);
|
|
|
|
|
|
|
|
// Read a CIE.
|
|
|
|
template<int size, bool big_endian>
|
|
|
|
bool
|
2011-05-25 05:41:10 +08:00
|
|
|
read_cie(Sized_relobj_file<size, big_endian>* object,
|
2007-11-09 15:00:15 +08:00
|
|
|
unsigned int shndx,
|
|
|
|
const unsigned char* symbols,
|
2007-12-18 08:48:04 +08:00
|
|
|
section_size_type symbols_size,
|
2007-11-09 15:00:15 +08:00
|
|
|
const unsigned char* symbol_names,
|
2007-12-18 08:48:04 +08:00
|
|
|
section_size_type symbol_names_size,
|
2007-11-09 15:00:15 +08:00
|
|
|
const unsigned char* pcontents,
|
|
|
|
const unsigned char* pcie,
|
2010-08-25 16:36:54 +08:00
|
|
|
const unsigned char* pcieend,
|
2007-11-09 15:00:15 +08:00
|
|
|
Track_relocs<size, big_endian>* relocs,
|
|
|
|
Offsets_to_cie* cies,
|
|
|
|
New_cies* new_cies);
|
|
|
|
|
|
|
|
// Read an FDE.
|
|
|
|
template<int size, bool big_endian>
|
|
|
|
bool
|
2011-05-25 05:41:10 +08:00
|
|
|
read_fde(Sized_relobj_file<size, big_endian>* object,
|
2007-11-09 15:00:15 +08:00
|
|
|
unsigned int shndx,
|
|
|
|
const unsigned char* symbols,
|
2007-12-18 08:48:04 +08:00
|
|
|
section_size_type symbols_size,
|
2007-11-09 15:00:15 +08:00
|
|
|
const unsigned char* pcontents,
|
|
|
|
unsigned int offset,
|
|
|
|
const unsigned char* pfde,
|
2010-08-25 16:36:54 +08:00
|
|
|
const unsigned char* pfdeend,
|
2007-11-09 15:00:15 +08:00
|
|
|
Track_relocs<size, big_endian>* relocs,
|
|
|
|
Offsets_to_cie* cies);
|
|
|
|
|
|
|
|
// Template version of write function.
|
|
|
|
template<int size, bool big_endian>
|
|
|
|
void
|
|
|
|
do_sized_write(unsigned char* oview);
|
|
|
|
|
|
|
|
// The exception frame header, if any.
|
|
|
|
Eh_frame_hdr* eh_frame_hdr_;
|
|
|
|
// A mapping from all unique CIEs to their offset in the output
|
|
|
|
// file.
|
|
|
|
Cie_offsets cie_offsets_;
|
|
|
|
// A mapping from unmergeable CIEs to their offset in the output
|
|
|
|
// file.
|
|
|
|
Unmergeable_cie_offsets unmergeable_cie_offsets_;
|
2008-03-14 04:58:11 +08:00
|
|
|
// Whether we have created the mappings to the output section.
|
|
|
|
bool mappings_are_done_;
|
|
|
|
// The final data size. This is only set if mappings_are_done_ is
|
|
|
|
// true.
|
|
|
|
section_size_type final_data_size_;
|
2007-09-26 13:44:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End namespace gold.
|
|
|
|
|
|
|
|
#endif // !defined(GOLD_EHFRAME_H)
|