* gdbarch.sh (convert_register_p): Add gdbarch as parameter.
[deliverable/binutils-gdb.git] / gold / ehframe.cc
CommitLineData
3151305a
ILT
1// ehframe.cc -- handle exception frame sections for gold
2
3// Copyright 2006, 2007 Free Software Foundation, Inc.
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
8// This program is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21// MA 02110-1301, USA.
22
23#include "gold.h"
24
25#include "elfcpp.h"
26#include "dwarf.h"
27#include "ehframe.h"
28
29namespace gold
30{
31
32// This file handles generation of the exception frame header that
33// gcc's runtime support libraries use to find unwind information at
34// runtime.
35
36// The exception frame header starts with four bytes:
37
38// 0: The version number, currently 1.
39
40// 1: The encoding of the pointer to the exception frames. This can
41// be any DWARF unwind encoding (DW_EH_PE_*). It is normally a 4
42// byte PC relative offset (DW_EH_PE_pcrel | DW_EH_PE_sdata4).
43
44// 2: The encoding of the count of the number of FDE pointers in the
45// lookup table. This can be any DWARF unwind encoding, and in
46// particular can be DW_EH_PE_omit if the count is omitted. It is
47// normally a 4 byte unsigned count (DW_EH_PE_udata4).
48
49// 3: The encoding of the lookup table entries. Currently gcc's
50// libraries will only support DW_EH_PE_datarel | DW_EH_PE_sdata4,
51// which means that the values are 4 byte offsets from the start of
52// the table.
53
54// The exception frame header is followed by a pointer to the contents
55// of the exception frame section (.eh_frame). This pointer is
56// encoded as specified in the byte at offset 1 of the header (i.e.,
57// it is normally a 4 byte PC relative offset).
58
59// If there is a lookup table, this is followed by the count of the
60// number of FDE pointers, encoded as specified in the byte at offset
61// 2 of the header (i.e., normally a 4 byte unsigned integer).
62
63// This is followed by the table, which should start at an 4-byte
64// aligned address in memory. Each entry in the table is 8 bytes.
65// Each entry represents an FDE. The first four bytes of each entry
66// are an offset to the starting PC for the FDE. The last four bytes
67// of each entry are an offset to the FDE data. The offsets are from
68// the start of the exception frame header information. The entries
69// are in sorted order by starting PC.
70
71// FIXME: We currently always generate an empty exception frame
72// header.
73
74const int eh_frame_hdr_size = 4;
75
76// Construct the exception frame header.
77
9025d29d 78Eh_frame_hdr::Eh_frame_hdr(Output_section* eh_frame_section)
3151305a 79 : Output_section_data(4),
9025d29d 80 eh_frame_section_(eh_frame_section)
3151305a
ILT
81{
82}
83
84// Set the final address and size of the exception frame header.
85
86void
87Eh_frame_hdr::do_set_address(uint64_t, off_t)
88{
89 this->set_data_size(eh_frame_hdr_size + 4);
90}
91
92// Write the data to the flie.
93
94void
95Eh_frame_hdr::do_write(Output_file* of)
96{
97 const off_t off = this->offset();
98 const off_t oview_size = this->data_size();
99 unsigned char* const oview = of->get_output_view(off, oview_size);
100
101 // Version number.
102 oview[0] = 1;
103
104 // Write out a 4 byte PC relative offset to the address of the
105 // .eh_frame section.
106 oview[1] = elfcpp::DW_EH_PE_pcrel | elfcpp::DW_EH_PE_sdata4;
107 uint64_t eh_frame_address = this->eh_frame_section_->address();
108 uint64_t eh_frame_hdr_address = this->address();
109 uint64_t eh_frame_offset = (eh_frame_address -
110 (eh_frame_hdr_address + 4));
9025d29d 111 if (parameters->is_big_endian())
3151305a
ILT
112 elfcpp::Swap<32, true>::writeval(oview + 4, eh_frame_offset);
113 else
114 elfcpp::Swap<32, false>::writeval(oview + 4, eh_frame_offset);
115
116 // We don't currently write out the sorted table.
117 oview[2] = elfcpp::DW_EH_PE_omit;
118 oview[3] = elfcpp::DW_EH_PE_omit;
119
120 gold_assert(oview_size == 8);
121
122 of->write_output_view(off, oview_size, oview);
123}
124
125} // End namespace gold.
This page took 0.032298 seconds and 4 git commands to generate.