|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU Lesser General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU Lesser General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #include <iostream> |
|
20 #include "dwarfmanager.h" |
|
21 #include "inputfile.h" |
|
22 |
|
23 const string DwarfArangesManager::iArangesSectionName(".debug_aranges"); |
|
24 |
|
25 void DwarfArangesManager::ProcessSection(FileShdrPair & aPair, Dwarf_Byte_Ptr start, Dwarf_Byte_Ptr end){ |
|
26 while (start < end){ |
|
27 Dwarf_Byte_Ptr data = start; |
|
28 size_t offset_size, initial_length_size; |
|
29 |
|
30 Dwarf_Word length = READ_UNALIGNED4(data); |
|
31 data += 4; |
|
32 |
|
33 if (length >= 0xfffffff0u) { |
|
34 cerr << "Error: 64 bit DWARF not supported\n"; |
|
35 exit(EXIT_FAILURE); |
|
36 } else { |
|
37 offset_size = 4; |
|
38 initial_length_size = 4; |
|
39 } |
|
40 |
|
41 start += length + initial_length_size; |
|
42 |
|
43 Dwarf_Half version = READ_UNALIGNED2(data); |
|
44 data += 2; |
|
45 |
|
46 Dwarf_Word offset = GetValue(data, offset_size); |
|
47 Dwarf_Word newOffset = CheckNewOffset(iDwarfInfoManager.GetSectionOffset(aPair.iXIPFileDetails.iElfFile), offset); |
|
48 if (offset != newOffset) |
|
49 WriteValue(data, offset, offset_size); |
|
50 data += offset_size; |
|
51 |
|
52 |
|
53 size_t pointer_size = *data++; |
|
54 |
|
55 size_t segment_size = *data++; |
|
56 |
|
57 if (version != 2 && version != 3){ |
|
58 static bool warned = false; |
|
59 if (!warned){ |
|
60 cerr << "Only DWARF 2 and 3 aranges are currently supported\n"; |
|
61 warned = true; |
|
62 } |
|
63 continue; |
|
64 } |
|
65 |
|
66 size_t address_size = pointer_size + segment_size; |
|
67 |
|
68 if (address_size > 4){ |
|
69 static bool warned2 = false; |
|
70 if (!warned2){ |
|
71 cerr << "64 bit DWARF not currently supported\n"; |
|
72 warned2 = true; |
|
73 } |
|
74 continue; |
|
75 } |
|
76 |
|
77 Dwarf_Byte_Ptr ranges = data; |
|
78 |
|
79 /* Must pad to an alignment boundary that is twice the address size. */ |
|
80 size_t excess = (data - start) % (2 * address_size); |
|
81 if (excess) |
|
82 ranges += (2 * address_size) - excess; |
|
83 |
|
84 while (ranges + 2 * address_size <= start){ |
|
85 LinearAddr addr = GetValue(ranges, address_size); |
|
86 LinearAddr relocatedAddress = aPair.iXIPFileDetails.Relocate(addr); |
|
87 if (addr != relocatedAddress) |
|
88 WriteValue(ranges, relocatedAddress, address_size); |
|
89 ranges += address_size; |
|
90 // skip length field |
|
91 ranges += address_size; |
|
92 } |
|
93 } |
|
94 } |