1 // ehframe.cc -- handle exception frame sections for gold
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
32 // This file handles generation of the exception frame header that
33 // gcc's runtime support libraries use to find unwind information at
36 // The exception frame header starts with four bytes:
38 // 0: The version number, currently 1.
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).
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).
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
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).
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).
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.
71 // FIXME: We currently always generate an empty exception frame
74 const int eh_frame_hdr_size
= 4;
76 // Construct the exception frame header.
78 Eh_frame_hdr::Eh_frame_hdr(Output_section
* eh_frame_section
)
79 : Output_section_data(4),
80 eh_frame_section_(eh_frame_section
)
84 // Set the final address and size of the exception frame header.
87 Eh_frame_hdr::do_set_address(uint64_t, off_t
)
89 this->set_data_size(eh_frame_hdr_size
+ 4);
92 // Write the data to the flie.
95 Eh_frame_hdr::do_write(Output_file
* of
)
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
);
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));
111 if (parameters
->is_big_endian())
112 elfcpp::Swap
<32, true>::writeval(oview
+ 4, eh_frame_offset
);
114 elfcpp::Swap
<32, false>::writeval(oview
+ 4, eh_frame_offset
);
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
;
120 gold_assert(oview_size
== 8);
122 of
->write_output_view(off
, oview_size
, oview
);
125 } // End namespace gold.