diff options
| author | Martin Jansa <Martin.Jansa@gmail.com> | 2021-05-12 18:45:03 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-05-13 11:34:15 +0100 |
| commit | e7ce28c8b060fc4fc84fe328275bbca87d17a3f0 (patch) | |
| tree | 67e82dac46f1a20a27f2201aaa6dac1da0b9aae6 /meta/recipes-devtools/binutils | |
| parent | 0fc0804e4b6df74aa160cab75e9da944013b0db3 (diff) | |
| download | poky-e7ce28c8b060fc4fc84fe328275bbca87d17a3f0.tar.gz | |
binutils: backport DWARF-5 support for gold
* DWARF-5 is now used by default with gcc-11, causing
11.1.0/ld: internal error in format_file_lineno, at ../../gold/dwarf_reader.cc:2278
collect2: error: ld returned 1 exit status
in various projects (runc-opencontainers, libhybris, collada-dom)
* https://gcc.gnu.org/gcc-11/changes.html
For targets that produce DWARF debugging information GCC now defaults to DWARF version 5
(with the exception of VxWorks and Darwin/Mac OS X which default to version 2 and
AIX which defaults to version 4). This can produce up to 25% more compact debug
information compared to earlier versions.
To take full advantage of DWARF version 5 GCC needs to be build against binutils version 2.35.2 or higher.
When GCC is build against earlier versions of binutils GCC will still emit DWARF version 5 for
most debuginfo data, but will generate version 4 debug line tables (even when explicitly given -gdwarf-5).
The following debug information consumers can process DWARF version 5:
GDB 8.0, or higher
valgrind 3.17.0
elfutils 0.172, or higher (for use with systemtap, dwarves/pahole, perf and libabigail)
dwz 0.14
Programs embedding libbacktrace are urged to upgrade to the version shipping with GCC 11.
To make GCC 11 generate an older DWARF version use -g together with -gdwarf-2, -gdwarf-3 or -gdwarf-4.
(From OE-Core rev: d07d4d739ae17787017f771dd2068fda0e836722)
Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/binutils')
| -rw-r--r-- | meta/recipes-devtools/binutils/binutils-2.36.inc | 1 | ||||
| -rw-r--r-- | meta/recipes-devtools/binutils/binutils/0018-Add-DWARF-5-support-in-gold.patch | 1374 |
2 files changed, 1375 insertions, 0 deletions
diff --git a/meta/recipes-devtools/binutils/binutils-2.36.inc b/meta/recipes-devtools/binutils/binutils-2.36.inc index 66080dfcee..d54e2a3457 100644 --- a/meta/recipes-devtools/binutils/binutils-2.36.inc +++ b/meta/recipes-devtools/binutils/binutils-2.36.inc | |||
| @@ -36,6 +36,7 @@ SRC_URI = "\ | |||
| 36 | file://0015-sync-with-OE-libtool-changes.patch \ | 36 | file://0015-sync-with-OE-libtool-changes.patch \ |
| 37 | file://0016-Check-for-clang-before-checking-gcc-version.patch \ | 37 | file://0016-Check-for-clang-before-checking-gcc-version.patch \ |
| 38 | file://0017-Add-support-for-the-DW_FORM_strx-forms-to-the-BFD-li.patch \ | 38 | file://0017-Add-support-for-the-DW_FORM_strx-forms-to-the-BFD-li.patch \ |
| 39 | file://0018-Add-DWARF-5-support-in-gold.patch \ | ||
| 39 | file://CVE-2021-20197.patch \ | 40 | file://CVE-2021-20197.patch \ |
| 40 | " | 41 | " |
| 41 | S = "${WORKDIR}/git" | 42 | S = "${WORKDIR}/git" |
diff --git a/meta/recipes-devtools/binutils/binutils/0018-Add-DWARF-5-support-in-gold.patch b/meta/recipes-devtools/binutils/binutils/0018-Add-DWARF-5-support-in-gold.patch new file mode 100644 index 0000000000..353b680857 --- /dev/null +++ b/meta/recipes-devtools/binutils/binutils/0018-Add-DWARF-5-support-in-gold.patch | |||
| @@ -0,0 +1,1374 @@ | |||
| 1 | From 29dab7648672342418a9d32767e3b3182d9e6a30 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cary Coutant <ccoutant@gmail.com> | ||
| 3 | Date: Wed, 17 Mar 2021 21:31:15 -0700 | ||
| 4 | Subject: [PATCH] Add DWARF 5 support in gold. | ||
| 5 | |||
| 6 | elfcpp/ | ||
| 7 | PR gold/27246 | ||
| 8 | * dwarf.h (enum DW_LNCT): Add line number table content type codes. | ||
| 9 | (enum DW_LINE_OPS): Reformat. | ||
| 10 | (enum DW_LINE_EXTENDED_OPS): Reformat. | ||
| 11 | (enum DW_CHILDREN): Reformat. | ||
| 12 | (enum DW_RLE): Add range list entry types. | ||
| 13 | (enum DW_SECT): Update values for DWARF 5. | ||
| 14 | |||
| 15 | gold/ | ||
| 16 | PR gold/27246 | ||
| 17 | * dwarf_reader.cc (Dwarf_abbrev_table::do_get_abbrev): Handle | ||
| 18 | DW_FORM_implicit_const. | ||
| 19 | (Dwarf_ranges_table::read_ranges_table): Add version parameter; | ||
| 20 | Adjust all callers. Look for .debug_rnglists section if DWARF 5. | ||
| 21 | (Dwarf_ranges_table::read_range_list_v5): New method. | ||
| 22 | (Dwarf_die::read_attributes): Handle new DWARF 5 DW_FORM codes. | ||
| 23 | (Dwarf_die::skip_attributes): Likewise. | ||
| 24 | (Dwarf_info_reader::do_parse): Support DWARF 5 unit header format. | ||
| 25 | (Dwarf_info_reader::read_3bytes_from_pointer): New method. | ||
| 26 | (Sized_dwarf_line_info::Sized_dwarf_line_info): Initialize | ||
| 27 | str_buffer_, str_buffer_start, reloc_map_, line_number_map_. | ||
| 28 | Look for .debug_line_str section. | ||
| 29 | (Sized_dwarf_line_info::read_header_prolog): Support DWARF 5 prolog. | ||
| 30 | (Sized_dwarf_line_info::read_header_tables): Rename to... | ||
| 31 | (Sized_dwarf_line_info::read_header_tables_v2): ... this. | ||
| 32 | (Sized_dwarf_line_info::read_header_tables_v5): New method. | ||
| 33 | (Sized_dwarf_line_info::process_one_opcode): Insert missing "this->". | ||
| 34 | Change advance_line to signed int64_t. | ||
| 35 | (Sized_dwarf_line_info::read_lines): Add endptr parameter; adjust | ||
| 36 | callers. Insert missing "this->". | ||
| 37 | (Sized_dwarf_line_info::read_line_mappings): Support DWARF 5. | ||
| 38 | (Sized_dwarf_line_info::do_addr2line): Add debug code. | ||
| 39 | * dwarf_reader.h (Dwarf_abbrev_table::Attribute): Add implicit_const | ||
| 40 | field. Adjust constructor. | ||
| 41 | (Dwarf_abbrev_table::add_sttribute): Add implicit_const parameter. | ||
| 42 | (Dwarf_ranges_table::read_ranges_table): Add version parameter. | ||
| 43 | (Dwarf_ranges_table::read_range_list_v5): New method. | ||
| 44 | (Dwarf_die): Remove unused attr_off field. | ||
| 45 | (Dwarf_info_reader::Dwarf_info_reader): Initialize unit_type_ field. | ||
| 46 | (Dwarf_info_reader::is_type_unit): New method. | ||
| 47 | (Dwarf_info_reader::read_3bytes_from_pointer): New method. | ||
| 48 | (Dwarf_info_reader::read_range_list): Call read_range_list_v5 for | ||
| 49 | DWARF 5 range lists. | ||
| 50 | (Dwarf_info_reader::is_type_unit_): Remove. | ||
| 51 | (Dwarf_info_reader::unit_type_): New field. | ||
| 52 | (Sized_dwarf_line_info::~Sized_dwarf_line_info): Delete | ||
| 53 | str_buffer_start_. | ||
| 54 | (Sized_dwarf_line_info::read_header_tables): Rename to... | ||
| 55 | (Sized_dwarf_line_info::read_header_tables_v2): ... this. | ||
| 56 | (Sized_dwarf_line_info::read_header_tables_v5): New method. | ||
| 57 | (Sized_dwarf_line_info::read_lines): Add endptr parameter. | ||
| 58 | (Sized_dwarf_line_info::Dwarf_line_infoHeader): Add address_size field. | ||
| 59 | (Sized_dwarf_line_info::str_buffer_): New field. | ||
| 60 | (Sized_dwarf_line_info::str_buffer_end_): New field. | ||
| 61 | (Sized_dwarf_line_info::str_buffer_start_): New field. | ||
| 62 | (Sized_dwarf_line_info::end_of_header_length_): New field. | ||
| 63 | (Sized_dwarf_line_info::end_of_unit_): New field. | ||
| 64 | |||
| 65 | Upstream-Status: Backport [5cde809b7b9 Add DWARF 5 support in gold.] | ||
| 66 | |||
| 67 | Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> | ||
| 68 | --- | ||
| 69 | elfcpp/dwarf.h | 89 +++++-- | ||
| 70 | gold/dwarf_reader.cc | 591 +++++++++++++++++++++++++++++++++++++------ | ||
| 71 | gold/dwarf_reader.h | 103 ++++++-- | ||
| 72 | 3 files changed, 654 insertions(+), 129 deletions(-) | ||
| 73 | |||
| 74 | diff --git a/elfcpp/dwarf.h b/elfcpp/dwarf.h | ||
| 75 | index e24347f8481..c9a9e02369c 100644 | ||
| 76 | --- a/elfcpp/dwarf.h | ||
| 77 | +++ b/elfcpp/dwarf.h | ||
| 78 | @@ -152,35 +152,48 @@ enum DW_EH_PE | ||
| 79 | DW_EH_PE_indirect = 0x80 | ||
| 80 | }; | ||
| 81 | |||
| 82 | +// Line number table content type codes. | ||
| 83 | + | ||
| 84 | +enum DW_LNCT | ||
| 85 | +{ | ||
| 86 | + DW_LNCT_path = 0x1, | ||
| 87 | + DW_LNCT_directory_index = 0x2, | ||
| 88 | + DW_LNCT_timestamp = 0x3, | ||
| 89 | + DW_LNCT_size = 0x4, | ||
| 90 | + DW_LNCT_MD5 = 0x5, | ||
| 91 | + DW_LNCT_lo_user = 0x2000, | ||
| 92 | + DW_LNCT_hi_user = 0x3fff | ||
| 93 | +}; | ||
| 94 | + | ||
| 95 | // Line number opcodes. | ||
| 96 | |||
| 97 | enum DW_LINE_OPS | ||
| 98 | { | ||
| 99 | - DW_LNS_extended_op = 0, | ||
| 100 | - DW_LNS_copy = 1, | ||
| 101 | - DW_LNS_advance_pc = 2, | ||
| 102 | - DW_LNS_advance_line = 3, | ||
| 103 | - DW_LNS_set_file = 4, | ||
| 104 | - DW_LNS_set_column = 5, | ||
| 105 | - DW_LNS_negate_stmt = 6, | ||
| 106 | - DW_LNS_set_basic_block = 7, | ||
| 107 | - DW_LNS_const_add_pc = 8, | ||
| 108 | - DW_LNS_fixed_advance_pc = 9, | ||
| 109 | + DW_LNS_extended_op = 0x00, | ||
| 110 | + DW_LNS_copy = 0x01, | ||
| 111 | + DW_LNS_advance_pc = 0x02, | ||
| 112 | + DW_LNS_advance_line = 0x03, | ||
| 113 | + DW_LNS_set_file = 0x04, | ||
| 114 | + DW_LNS_set_column = 0x05, | ||
| 115 | + DW_LNS_negate_stmt = 0x06, | ||
| 116 | + DW_LNS_set_basic_block = 0x07, | ||
| 117 | + DW_LNS_const_add_pc = 0x08, | ||
| 118 | + DW_LNS_fixed_advance_pc = 0x09, | ||
| 119 | // DWARF 3. | ||
| 120 | - DW_LNS_set_prologue_end = 10, | ||
| 121 | - DW_LNS_set_epilogue_begin = 11, | ||
| 122 | - DW_LNS_set_isa = 12 | ||
| 123 | + DW_LNS_set_prologue_end = 0x0a, | ||
| 124 | + DW_LNS_set_epilogue_begin = 0x0b, | ||
| 125 | + DW_LNS_set_isa = 0x0c | ||
| 126 | }; | ||
| 127 | |||
| 128 | // Line number extended opcodes. | ||
| 129 | |||
| 130 | enum DW_LINE_EXTENDED_OPS | ||
| 131 | { | ||
| 132 | - DW_LNE_end_sequence = 1, | ||
| 133 | - DW_LNE_set_address = 2, | ||
| 134 | - DW_LNE_define_file = 3, | ||
| 135 | + DW_LNE_end_sequence = 0x01, | ||
| 136 | + DW_LNE_set_address = 0x02, | ||
| 137 | + DW_LNE_define_file = 0x03, | ||
| 138 | // DWARF4. | ||
| 139 | - DW_LNE_set_discriminator = 4, | ||
| 140 | + DW_LNE_set_discriminator = 0x04, | ||
| 141 | // HP extensions. | ||
| 142 | DW_LNE_HP_negate_is_UV_update = 0x11, | ||
| 143 | DW_LNE_HP_push_context = 0x12, | ||
| 144 | @@ -191,13 +204,15 @@ enum DW_LINE_EXTENDED_OPS | ||
| 145 | DW_LNE_HP_negate_post_semantics = 0x17, | ||
| 146 | DW_LNE_HP_negate_function_exit = 0x18, | ||
| 147 | DW_LNE_HP_negate_front_end_logical = 0x19, | ||
| 148 | - DW_LNE_HP_define_proc = 0x20 | ||
| 149 | + DW_LNE_HP_define_proc = 0x20, | ||
| 150 | + DW_LNE_lo_user = 0x80, | ||
| 151 | + DW_LNE_hi_user = 0xff | ||
| 152 | }; | ||
| 153 | |||
| 154 | enum DW_CHILDREN | ||
| 155 | { | ||
| 156 | - DW_CHILDREN_no =0x00, | ||
| 157 | - DW_CHILDREN_yes =0x01 | ||
| 158 | + DW_CHILDREN_no = 0, | ||
| 159 | + DW_CHILDREN_yes = 1 | ||
| 160 | }; | ||
| 161 | |||
| 162 | // Source language names and codes. | ||
| 163 | @@ -247,20 +262,38 @@ enum DW_LANG | ||
| 164 | DW_LANG_HP_Assembler = 0x8007 | ||
| 165 | }; | ||
| 166 | |||
| 167 | +// Range list entry kinds in .debug_rnglists* section. | ||
| 168 | + | ||
| 169 | +enum DW_RLE | ||
| 170 | +{ | ||
| 171 | + DW_RLE_end_of_list = 0x00, | ||
| 172 | + DW_RLE_base_addressx = 0x01, | ||
| 173 | + DW_RLE_startx_endx = 0x02, | ||
| 174 | + DW_RLE_startx_length = 0x03, | ||
| 175 | + DW_RLE_offset_pair = 0x04, | ||
| 176 | + DW_RLE_base_address = 0x05, | ||
| 177 | + DW_RLE_start_end = 0x06, | ||
| 178 | + DW_RLE_start_length = 0x07 | ||
| 179 | +}; | ||
| 180 | + | ||
| 181 | // DWARF section identifiers used in the package format. | ||
| 182 | // Extensions for Fission. See http://gcc.gnu.org/wiki/DebugFissionDWP. | ||
| 183 | +// Added (with changes) in DWARF 5. | ||
| 184 | |||
| 185 | enum DW_SECT | ||
| 186 | { | ||
| 187 | - DW_SECT_INFO = 1, | ||
| 188 | - DW_SECT_TYPES = 2, | ||
| 189 | - DW_SECT_ABBREV = 3, | ||
| 190 | - DW_SECT_LINE = 4, | ||
| 191 | - DW_SECT_LOC = 5, | ||
| 192 | + DW_SECT_INFO = 1, | ||
| 193 | + DW_SECT_ABBREV = 3, | ||
| 194 | + DW_SECT_LINE = 4, | ||
| 195 | + DW_SECT_LOCLISTS = 5, | ||
| 196 | DW_SECT_STR_OFFSETS = 6, | ||
| 197 | - DW_SECT_MACINFO = 7, | ||
| 198 | - DW_SECT_MACRO = 8, | ||
| 199 | - DW_SECT_MAX = DW_SECT_MACRO, | ||
| 200 | + DW_SECT_MACINFO = 7, | ||
| 201 | + DW_SECT_RNGLISTS = 8, | ||
| 202 | + DW_SECT_MAX = DW_SECT_RNGLISTS, | ||
| 203 | + // These were used only for the experimental Fission support in DWARF 4. | ||
| 204 | + DW_SECT_TYPES = 2, | ||
| 205 | + DW_SECT_LOC = 5, | ||
| 206 | + DW_SECT_MACRO = 8 | ||
| 207 | }; | ||
| 208 | |||
| 209 | } // End namespace elfcpp. | ||
| 210 | diff --git a/gold/dwarf_reader.cc b/gold/dwarf_reader.cc | ||
| 211 | index f0e6b89bde2..83a0114ed39 100644 | ||
| 212 | --- a/gold/dwarf_reader.cc | ||
| 213 | +++ b/gold/dwarf_reader.cc | ||
| 214 | @@ -26,6 +26,7 @@ | ||
| 215 | #include <utility> | ||
| 216 | #include <vector> | ||
| 217 | |||
| 218 | +#include "debug.h" | ||
| 219 | #include "elfcpp_swap.h" | ||
| 220 | #include "dwarf.h" | ||
| 221 | #include "object.h" | ||
| 222 | @@ -275,6 +276,14 @@ Dwarf_abbrev_table::do_get_abbrev(unsigned int code) | ||
| 223 | uint64_t form = read_unsigned_LEB_128(this->buffer_pos_, &len); | ||
| 224 | this->buffer_pos_ += len; | ||
| 225 | |||
| 226 | + // For DW_FORM_implicit_const, read the constant. | ||
| 227 | + int64_t implicit_const = 0; | ||
| 228 | + if (form == elfcpp::DW_FORM_implicit_const) | ||
| 229 | + { | ||
| 230 | + implicit_const = read_signed_LEB_128(this->buffer_pos_, &len); | ||
| 231 | + this->buffer_pos_ += len; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | // A (0,0) pair terminates the list. | ||
| 235 | if (attr == 0 && form == 0) | ||
| 236 | break; | ||
| 237 | @@ -282,7 +291,7 @@ Dwarf_abbrev_table::do_get_abbrev(unsigned int code) | ||
| 238 | if (attr == elfcpp::DW_AT_sibling) | ||
| 239 | entry->has_sibling_attribute = true; | ||
| 240 | |||
| 241 | - entry->add_attribute(attr, form); | ||
| 242 | + entry->add_attribute(attr, form, implicit_const); | ||
| 243 | } | ||
| 244 | |||
| 245 | this->store_abbrev(nextcode, entry); | ||
| 246 | @@ -302,8 +311,16 @@ Dwarf_ranges_table::read_ranges_table( | ||
| 247 | Relobj* object, | ||
| 248 | const unsigned char* symtab, | ||
| 249 | off_t symtab_size, | ||
| 250 | - unsigned int ranges_shndx) | ||
| 251 | + unsigned int ranges_shndx, | ||
| 252 | + unsigned int version) | ||
| 253 | { | ||
| 254 | + const std::string section_name(version < 5 | ||
| 255 | + ? ".debug_ranges" | ||
| 256 | + : ".debug_rnglists"); | ||
| 257 | + const std::string compressed_section_name(version < 5 | ||
| 258 | + ? ".zdebug_ranges" | ||
| 259 | + : ".zdebug_rnglists"); | ||
| 260 | + | ||
| 261 | // If we've already read this abbrev table, return immediately. | ||
| 262 | if (this->ranges_shndx_ > 0 | ||
| 263 | && this->ranges_shndx_ == ranges_shndx) | ||
| 264 | @@ -318,7 +335,7 @@ Dwarf_ranges_table::read_ranges_table( | ||
| 265 | for (unsigned int i = 1; i < object->shnum(); ++i) | ||
| 266 | { | ||
| 267 | std::string name = object->section_name(i); | ||
| 268 | - if (name == ".debug_ranges" || name == ".zdebug_ranges") | ||
| 269 | + if (name == section_name || name == compressed_section_name) | ||
| 270 | { | ||
| 271 | ranges_shndx = i; | ||
| 272 | this->output_section_offset_ = object->output_section_offset(i); | ||
| 273 | @@ -393,7 +410,7 @@ Dwarf_ranges_table::read_range_list( | ||
| 274 | { | ||
| 275 | Dwarf_range_list* ranges; | ||
| 276 | |||
| 277 | - if (!this->read_ranges_table(object, symtab, symtab_size, ranges_shndx)) | ||
| 278 | + if (!this->read_ranges_table(object, symtab, symtab_size, ranges_shndx, 4)) | ||
| 279 | return NULL; | ||
| 280 | |||
| 281 | // Correct the offset. For incremental update links, we have a | ||
| 282 | @@ -459,6 +476,125 @@ Dwarf_ranges_table::read_range_list( | ||
| 283 | return ranges; | ||
| 284 | } | ||
| 285 | |||
| 286 | +// Read a DWARF 5 range list from section RANGES_SHNDX at offset RANGES_OFFSET. | ||
| 287 | + | ||
| 288 | +Dwarf_range_list* | ||
| 289 | +Dwarf_ranges_table::read_range_list_v5( | ||
| 290 | + Relobj* object, | ||
| 291 | + const unsigned char* symtab, | ||
| 292 | + off_t symtab_size, | ||
| 293 | + unsigned int addr_size, | ||
| 294 | + unsigned int ranges_shndx, | ||
| 295 | + off_t offset) | ||
| 296 | +{ | ||
| 297 | + Dwarf_range_list* ranges; | ||
| 298 | + | ||
| 299 | + if (!this->read_ranges_table(object, symtab, symtab_size, ranges_shndx, 5)) | ||
| 300 | + return NULL; | ||
| 301 | + | ||
| 302 | + ranges = new Dwarf_range_list(); | ||
| 303 | + off_t base = 0; | ||
| 304 | + unsigned int shndx0 = 0; | ||
| 305 | + | ||
| 306 | + // Correct the offset. For incremental update links, we have a | ||
| 307 | + // relocated offset that is relative to the output section, but | ||
| 308 | + // here we need an offset relative to the input section. | ||
| 309 | + offset -= this->output_section_offset_; | ||
| 310 | + | ||
| 311 | + // Read the range list at OFFSET. | ||
| 312 | + const unsigned char* prle = this->ranges_buffer_ + offset; | ||
| 313 | + while (prle < this->ranges_buffer_end_) | ||
| 314 | + { | ||
| 315 | + off_t start; | ||
| 316 | + off_t end; | ||
| 317 | + unsigned int shndx1 = 0; | ||
| 318 | + unsigned int shndx2 = 0; | ||
| 319 | + size_t len; | ||
| 320 | + | ||
| 321 | + // Read the entry type. | ||
| 322 | + unsigned int rle_type = *prle++; | ||
| 323 | + offset += 1; | ||
| 324 | + | ||
| 325 | + if (rle_type == elfcpp::DW_RLE_end_of_list) | ||
| 326 | + break; | ||
| 327 | + | ||
| 328 | + switch (rle_type) | ||
| 329 | + { | ||
| 330 | + case elfcpp::DW_RLE_base_address: | ||
| 331 | + if (addr_size == 4) | ||
| 332 | + base = this->dwinfo_->read_from_pointer<32>(prle); | ||
| 333 | + else | ||
| 334 | + base = this->dwinfo_->read_from_pointer<64>(prle); | ||
| 335 | + if (this->ranges_reloc_mapper_ != NULL) | ||
| 336 | + shndx0 = this->lookup_reloc(offset, &base); | ||
| 337 | + prle += addr_size; | ||
| 338 | + offset += addr_size; | ||
| 339 | + break; | ||
| 340 | + | ||
| 341 | + case elfcpp::DW_RLE_offset_pair: | ||
| 342 | + start = read_unsigned_LEB_128(prle, &len); | ||
| 343 | + prle += len; | ||
| 344 | + offset += len; | ||
| 345 | + end = read_unsigned_LEB_128(prle, &len); | ||
| 346 | + prle += len; | ||
| 347 | + offset += len; | ||
| 348 | + if (shndx0 == 0 || object->is_section_included(shndx0)) | ||
| 349 | + ranges->add(shndx0, base + start, base + end); | ||
| 350 | + break; | ||
| 351 | + | ||
| 352 | + case elfcpp::DW_RLE_start_end: | ||
| 353 | + if (addr_size == 4) | ||
| 354 | + { | ||
| 355 | + start = this->dwinfo_->read_from_pointer<32>(prle); | ||
| 356 | + end = this->dwinfo_->read_from_pointer<32>(prle + 4); | ||
| 357 | + } | ||
| 358 | + else | ||
| 359 | + { | ||
| 360 | + start = this->dwinfo_->read_from_pointer<64>(prle); | ||
| 361 | + end = this->dwinfo_->read_from_pointer<64>(prle + 8); | ||
| 362 | + } | ||
| 363 | + if (this->ranges_reloc_mapper_ != NULL) | ||
| 364 | + { | ||
| 365 | + shndx1 = this->lookup_reloc(offset, &start); | ||
| 366 | + shndx2 = this->lookup_reloc(offset + addr_size, &end); | ||
| 367 | + if (shndx1 != shndx2) | ||
| 368 | + gold_warning(_("%s: DWARF info may be corrupt; offsets in a " | ||
| 369 | + "range list entry are in different sections"), | ||
| 370 | + object->name().c_str()); | ||
| 371 | + } | ||
| 372 | + prle += addr_size * 2; | ||
| 373 | + offset += addr_size * 2; | ||
| 374 | + if (shndx1 == 0 || object->is_section_included(shndx1)) | ||
| 375 | + ranges->add(shndx1, start, end); | ||
| 376 | + break; | ||
| 377 | + | ||
| 378 | + case elfcpp::DW_RLE_start_length: | ||
| 379 | + if (addr_size == 4) | ||
| 380 | + start = this->dwinfo_->read_from_pointer<32>(prle); | ||
| 381 | + else | ||
| 382 | + start = this->dwinfo_->read_from_pointer<64>(prle); | ||
| 383 | + if (this->ranges_reloc_mapper_ != NULL) | ||
| 384 | + shndx1 = this->lookup_reloc(offset, &start); | ||
| 385 | + prle += addr_size; | ||
| 386 | + offset += addr_size; | ||
| 387 | + end = start + read_unsigned_LEB_128(prle, &len); | ||
| 388 | + prle += len; | ||
| 389 | + offset += len; | ||
| 390 | + if (shndx1 == 0 || object->is_section_included(shndx1)) | ||
| 391 | + ranges->add(shndx1, start, end); | ||
| 392 | + break; | ||
| 393 | + | ||
| 394 | + default: | ||
| 395 | + gold_warning(_("%s: DWARF range list contains " | ||
| 396 | + "unsupported entry type (%d)"), | ||
| 397 | + object->name().c_str(), rle_type); | ||
| 398 | + break; | ||
| 399 | + } | ||
| 400 | + } | ||
| 401 | + | ||
| 402 | + return ranges; | ||
| 403 | +} | ||
| 404 | + | ||
| 405 | // Look for a relocation at offset OFF in the range table, | ||
| 406 | // and return the section index and offset of the target. | ||
| 407 | |||
| 408 | @@ -709,7 +845,13 @@ Dwarf_die::read_attributes() | ||
| 409 | case elfcpp::DW_FORM_flag_present: | ||
| 410 | attr_value.val.intval = 1; | ||
| 411 | break; | ||
| 412 | + case elfcpp::DW_FORM_implicit_const: | ||
| 413 | + attr_value.val.intval = | ||
| 414 | + this->abbrev_code_->attributes[i].implicit_const; | ||
| 415 | + break; | ||
| 416 | case elfcpp::DW_FORM_strp: | ||
| 417 | + case elfcpp::DW_FORM_strp_sup: | ||
| 418 | + case elfcpp::DW_FORM_line_strp: | ||
| 419 | { | ||
| 420 | off_t str_off; | ||
| 421 | if (this->dwinfo_->offset_size() == 4) | ||
| 422 | @@ -722,6 +864,26 @@ Dwarf_die::read_attributes() | ||
| 423 | attr_value.val.refval = str_off; | ||
| 424 | break; | ||
| 425 | } | ||
| 426 | + case elfcpp::DW_FORM_strx: | ||
| 427 | + case elfcpp::DW_FORM_GNU_str_index: | ||
| 428 | + attr_value.val.uintval = read_unsigned_LEB_128(pattr, &len); | ||
| 429 | + pattr += len; | ||
| 430 | + break; | ||
| 431 | + case elfcpp::DW_FORM_strx1: | ||
| 432 | + attr_value.val.uintval = *pattr++; | ||
| 433 | + break; | ||
| 434 | + case elfcpp::DW_FORM_strx2: | ||
| 435 | + attr_value.val.uintval = | ||
| 436 | + this->dwinfo_->read_from_pointer<16>(&pattr); | ||
| 437 | + break; | ||
| 438 | + case elfcpp::DW_FORM_strx3: | ||
| 439 | + attr_value.val.uintval = | ||
| 440 | + this->dwinfo_->read_3bytes_from_pointer(&pattr); | ||
| 441 | + break; | ||
| 442 | + case elfcpp::DW_FORM_strx4: | ||
| 443 | + attr_value.val.uintval = | ||
| 444 | + this->dwinfo_->read_from_pointer<32>(&pattr); | ||
| 445 | + break; | ||
| 446 | case elfcpp::DW_FORM_sec_offset: | ||
| 447 | { | ||
| 448 | off_t sec_off; | ||
| 449 | @@ -747,7 +909,6 @@ Dwarf_die::read_attributes() | ||
| 450 | this->dwinfo_->lookup_reloc(attr_off, &sec_off); | ||
| 451 | attr_value.aux.shndx = shndx; | ||
| 452 | attr_value.val.refval = sec_off; | ||
| 453 | - ref_form = true; | ||
| 454 | break; | ||
| 455 | } | ||
| 456 | case elfcpp::DW_FORM_ref_addr: | ||
| 457 | @@ -815,6 +976,7 @@ Dwarf_die::read_attributes() | ||
| 458 | break; | ||
| 459 | } | ||
| 460 | case elfcpp::DW_FORM_ref4: | ||
| 461 | + case elfcpp::DW_FORM_ref_sup4: | ||
| 462 | { | ||
| 463 | off_t sec_off; | ||
| 464 | sec_off = this->dwinfo_->read_from_pointer<32>(&pattr); | ||
| 465 | @@ -835,11 +997,20 @@ Dwarf_die::read_attributes() | ||
| 466 | attr_value.val.intval = sec_off; | ||
| 467 | break; | ||
| 468 | } | ||
| 469 | + case elfcpp::DW_FORM_data16: | ||
| 470 | + { | ||
| 471 | + // For now, treat this as a 16-byte block. | ||
| 472 | + attr_value.val.blockval = pattr; | ||
| 473 | + attr_value.aux.blocklen = 16; | ||
| 474 | + pattr += 16; | ||
| 475 | + break; | ||
| 476 | + } | ||
| 477 | case elfcpp::DW_FORM_ref_sig8: | ||
| 478 | attr_value.val.uintval = | ||
| 479 | this->dwinfo_->read_from_pointer<64>(&pattr); | ||
| 480 | break; | ||
| 481 | case elfcpp::DW_FORM_ref8: | ||
| 482 | + case elfcpp::DW_FORM_ref_sup8: | ||
| 483 | { | ||
| 484 | off_t sec_off; | ||
| 485 | sec_off = this->dwinfo_->read_from_pointer<64>(&pattr); | ||
| 486 | @@ -856,11 +1027,29 @@ Dwarf_die::read_attributes() | ||
| 487 | pattr += len; | ||
| 488 | break; | ||
| 489 | case elfcpp::DW_FORM_udata: | ||
| 490 | + attr_value.val.uintval = read_unsigned_LEB_128(pattr, &len); | ||
| 491 | + pattr += len; | ||
| 492 | + break; | ||
| 493 | + case elfcpp::DW_FORM_addrx: | ||
| 494 | case elfcpp::DW_FORM_GNU_addr_index: | ||
| 495 | - case elfcpp::DW_FORM_GNU_str_index: | ||
| 496 | attr_value.val.uintval = read_unsigned_LEB_128(pattr, &len); | ||
| 497 | pattr += len; | ||
| 498 | break; | ||
| 499 | + case elfcpp::DW_FORM_addrx1: | ||
| 500 | + attr_value.val.uintval = *pattr++; | ||
| 501 | + break; | ||
| 502 | + case elfcpp::DW_FORM_addrx2: | ||
| 503 | + attr_value.val.uintval = | ||
| 504 | + this->dwinfo_->read_from_pointer<16>(&pattr); | ||
| 505 | + break; | ||
| 506 | + case elfcpp::DW_FORM_addrx3: | ||
| 507 | + attr_value.val.uintval = | ||
| 508 | + this->dwinfo_->read_3bytes_from_pointer(&pattr); | ||
| 509 | + break; | ||
| 510 | + case elfcpp::DW_FORM_addrx4: | ||
| 511 | + attr_value.val.uintval = | ||
| 512 | + this->dwinfo_->read_from_pointer<32>(&pattr); | ||
| 513 | + break; | ||
| 514 | case elfcpp::DW_FORM_sdata: | ||
| 515 | attr_value.val.intval = read_signed_LEB_128(pattr, &len); | ||
| 516 | pattr += len; | ||
| 517 | @@ -870,6 +1059,11 @@ Dwarf_die::read_attributes() | ||
| 518 | len = strlen(attr_value.val.stringval); | ||
| 519 | pattr += len + 1; | ||
| 520 | break; | ||
| 521 | + case elfcpp::DW_FORM_loclistx: | ||
| 522 | + case elfcpp::DW_FORM_rnglistx: | ||
| 523 | + attr_value.val.uintval = read_unsigned_LEB_128(pattr, &len); | ||
| 524 | + pattr += len; | ||
| 525 | + break; | ||
| 526 | default: | ||
| 527 | return false; | ||
| 528 | } | ||
| 529 | @@ -954,9 +1148,12 @@ Dwarf_die::skip_attributes() | ||
| 530 | switch(form) | ||
| 531 | { | ||
| 532 | case elfcpp::DW_FORM_flag_present: | ||
| 533 | + case elfcpp::DW_FORM_implicit_const: | ||
| 534 | break; | ||
| 535 | case elfcpp::DW_FORM_strp: | ||
| 536 | case elfcpp::DW_FORM_sec_offset: | ||
| 537 | + case elfcpp::DW_FORM_strp_sup: | ||
| 538 | + case elfcpp::DW_FORM_line_strp: | ||
| 539 | pattr += this->dwinfo_->offset_size(); | ||
| 540 | break; | ||
| 541 | case elfcpp::DW_FORM_addr: | ||
| 542 | @@ -993,23 +1190,42 @@ Dwarf_die::skip_attributes() | ||
| 543 | case elfcpp::DW_FORM_data1: | ||
| 544 | case elfcpp::DW_FORM_ref1: | ||
| 545 | case elfcpp::DW_FORM_flag: | ||
| 546 | + case elfcpp::DW_FORM_strx1: | ||
| 547 | + case elfcpp::DW_FORM_addrx1: | ||
| 548 | pattr += 1; | ||
| 549 | break; | ||
| 550 | case elfcpp::DW_FORM_data2: | ||
| 551 | case elfcpp::DW_FORM_ref2: | ||
| 552 | + case elfcpp::DW_FORM_strx2: | ||
| 553 | + case elfcpp::DW_FORM_addrx2: | ||
| 554 | pattr += 2; | ||
| 555 | break; | ||
| 556 | + case elfcpp::DW_FORM_strx3: | ||
| 557 | + case elfcpp::DW_FORM_addrx3: | ||
| 558 | + pattr += 3; | ||
| 559 | + break; | ||
| 560 | case elfcpp::DW_FORM_data4: | ||
| 561 | case elfcpp::DW_FORM_ref4: | ||
| 562 | + case elfcpp::DW_FORM_ref_sup4: | ||
| 563 | + case elfcpp::DW_FORM_strx4: | ||
| 564 | + case elfcpp::DW_FORM_addrx4: | ||
| 565 | pattr += 4; | ||
| 566 | break; | ||
| 567 | case elfcpp::DW_FORM_data8: | ||
| 568 | case elfcpp::DW_FORM_ref8: | ||
| 569 | case elfcpp::DW_FORM_ref_sig8: | ||
| 570 | + case elfcpp::DW_FORM_ref_sup8: | ||
| 571 | pattr += 8; | ||
| 572 | break; | ||
| 573 | + case elfcpp::DW_FORM_data16: | ||
| 574 | + pattr += 16; | ||
| 575 | + break; | ||
| 576 | case elfcpp::DW_FORM_ref_udata: | ||
| 577 | case elfcpp::DW_FORM_udata: | ||
| 578 | + case elfcpp::DW_FORM_addrx: | ||
| 579 | + case elfcpp::DW_FORM_strx: | ||
| 580 | + case elfcpp::DW_FORM_loclistx: | ||
| 581 | + case elfcpp::DW_FORM_rnglistx: | ||
| 582 | case elfcpp::DW_FORM_GNU_addr_index: | ||
| 583 | case elfcpp::DW_FORM_GNU_str_index: | ||
| 584 | read_unsigned_LEB_128(pattr, &len); | ||
| 585 | @@ -1313,6 +1529,13 @@ Dwarf_info_reader::do_parse() | ||
| 586 | elfcpp::Swap_unaligned<16, big_endian>::readval(pinfo); | ||
| 587 | pinfo += 2; | ||
| 588 | |||
| 589 | + // DWARF 5: Read the unit type (1 byte) and address size (1 byte). | ||
| 590 | + if (this->cu_version_ >= 5) | ||
| 591 | + { | ||
| 592 | + this->unit_type_ = *pinfo++; | ||
| 593 | + this->address_size_ = *pinfo++; | ||
| 594 | + } | ||
| 595 | + | ||
| 596 | // Read debug_abbrev_offset (4 or 8 bytes). | ||
| 597 | if (this->offset_size_ == 4) | ||
| 598 | abbrev_offset = elfcpp::Swap_unaligned<32, big_endian>::readval(pinfo); | ||
| 599 | @@ -1333,13 +1556,14 @@ Dwarf_info_reader::do_parse() | ||
| 600 | } | ||
| 601 | pinfo += this->offset_size_; | ||
| 602 | |||
| 603 | - // Read address_size (1 byte). | ||
| 604 | - this->address_size_ = *pinfo++; | ||
| 605 | + // DWARF 2-4: Read address_size (1 byte). | ||
| 606 | + if (this->cu_version_ < 5) | ||
| 607 | + this->address_size_ = *pinfo++; | ||
| 608 | |||
| 609 | // For type units, read the two extra fields. | ||
| 610 | uint64_t signature = 0; | ||
| 611 | off_t type_offset = 0; | ||
| 612 | - if (this->is_type_unit_) | ||
| 613 | + if (this->is_type_unit()) | ||
| 614 | { | ||
| 615 | if (!this->check_buffer(pinfo + 8 + this->offset_size_)) | ||
| 616 | break; | ||
| 617 | @@ -1369,7 +1593,7 @@ Dwarf_info_reader::do_parse() | ||
| 618 | if (root_die.tag() != 0) | ||
| 619 | { | ||
| 620 | // Visit the CU or TU. | ||
| 621 | - if (this->is_type_unit_) | ||
| 622 | + if (this->is_type_unit()) | ||
| 623 | this->visit_type_unit(section_offset + this->cu_offset_, | ||
| 624 | cu_end - cu_start, type_offset, signature, | ||
| 625 | &root_die); | ||
| 626 | @@ -1460,6 +1684,19 @@ Dwarf_info_reader::read_from_pointer(const unsigned char** source) | ||
| 627 | return return_value; | ||
| 628 | } | ||
| 629 | |||
| 630 | +// Read a 3-byte integer. Update SOURCE after read. | ||
| 631 | +inline typename elfcpp::Valtype_base<32>::Valtype | ||
| 632 | +Dwarf_info_reader::read_3bytes_from_pointer(const unsigned char** source) | ||
| 633 | +{ | ||
| 634 | + typename elfcpp::Valtype_base<32>::Valtype return_value; | ||
| 635 | + if (this->object_->is_big_endian()) | ||
| 636 | + return_value = ((*source)[0] << 16) | ((*source)[1] << 8) | (*source)[2]; | ||
| 637 | + else | ||
| 638 | + return_value = ((*source)[2] << 16) | ((*source)[1] << 8) | (*source)[0]; | ||
| 639 | + *source += 3; | ||
| 640 | + return return_value; | ||
| 641 | +} | ||
| 642 | + | ||
| 643 | // Look for a relocation at offset ATTR_OFF in the dwarf info, | ||
| 644 | // and return the section index and offset of the target. | ||
| 645 | |||
| 646 | @@ -1561,27 +1798,40 @@ Sized_dwarf_line_info<size, big_endian>::Sized_dwarf_line_info( | ||
| 647 | Object* object, | ||
| 648 | unsigned int read_shndx) | ||
| 649 | : data_valid_(false), buffer_(NULL), buffer_start_(NULL), | ||
| 650 | + str_buffer_(NULL), str_buffer_start_(NULL), | ||
| 651 | reloc_mapper_(NULL), symtab_buffer_(NULL), directories_(), files_(), | ||
| 652 | - current_header_index_(-1) | ||
| 653 | + current_header_index_(-1), reloc_map_(), line_number_map_() | ||
| 654 | { | ||
| 655 | - unsigned int debug_shndx; | ||
| 656 | + unsigned int debug_line_shndx = 0; | ||
| 657 | + unsigned int debug_line_str_shndx = 0; | ||
| 658 | |||
| 659 | - for (debug_shndx = 1; debug_shndx < object->shnum(); ++debug_shndx) | ||
| 660 | + for (unsigned int i = 1; i < object->shnum(); ++i) | ||
| 661 | { | ||
| 662 | + section_size_type buffer_size; | ||
| 663 | + bool is_new = false; | ||
| 664 | + | ||
| 665 | // FIXME: do this more efficiently: section_name() isn't super-fast | ||
| 666 | - std::string name = object->section_name(debug_shndx); | ||
| 667 | + std::string name = object->section_name(i); | ||
| 668 | if (name == ".debug_line" || name == ".zdebug_line") | ||
| 669 | { | ||
| 670 | - section_size_type buffer_size; | ||
| 671 | - bool is_new = false; | ||
| 672 | - this->buffer_ = object->decompressed_section_contents(debug_shndx, | ||
| 673 | - &buffer_size, | ||
| 674 | - &is_new); | ||
| 675 | + this->buffer_ = | ||
| 676 | + object->decompressed_section_contents(i, &buffer_size, &is_new); | ||
| 677 | if (is_new) | ||
| 678 | this->buffer_start_ = this->buffer_; | ||
| 679 | this->buffer_end_ = this->buffer_ + buffer_size; | ||
| 680 | - break; | ||
| 681 | + debug_line_shndx = i; | ||
| 682 | + } | ||
| 683 | + else if (name == ".debug_line_str" || name == ".zdebug_line_str") | ||
| 684 | + { | ||
| 685 | + this->str_buffer_ = | ||
| 686 | + object->decompressed_section_contents(i, &buffer_size, &is_new); | ||
| 687 | + if (is_new) | ||
| 688 | + this->str_buffer_start_ = this->str_buffer_; | ||
| 689 | + this->str_buffer_end_ = this->str_buffer_ + buffer_size; | ||
| 690 | + debug_line_str_shndx = i; | ||
| 691 | } | ||
| 692 | + if (debug_line_shndx > 0 && debug_line_str_shndx > 0) | ||
| 693 | + break; | ||
| 694 | } | ||
| 695 | if (this->buffer_ == NULL) | ||
| 696 | return; | ||
| 697 | @@ -1594,7 +1844,7 @@ Sized_dwarf_line_info<size, big_endian>::Sized_dwarf_line_info( | ||
| 698 | unsigned int reloc_sh_type = object->section_type(i); | ||
| 699 | if ((reloc_sh_type == elfcpp::SHT_REL | ||
| 700 | || reloc_sh_type == elfcpp::SHT_RELA) | ||
| 701 | - && object->section_info(i) == debug_shndx) | ||
| 702 | + && object->section_info(i) == debug_line_shndx) | ||
| 703 | { | ||
| 704 | reloc_shndx = i; | ||
| 705 | this->track_relocs_type_ = reloc_sh_type; | ||
| 706 | @@ -1640,65 +1890,80 @@ Sized_dwarf_line_info<size, big_endian>::read_header_prolog( | ||
| 707 | uint32_t initial_length = elfcpp::Swap_unaligned<32, big_endian>::readval(lineptr); | ||
| 708 | lineptr += 4; | ||
| 709 | |||
| 710 | - // In DWARF2/3, if the initial length is all 1 bits, then the offset | ||
| 711 | + // In DWARF, if the initial length is all 1 bits, then the offset | ||
| 712 | // size is 8 and we need to read the next 8 bytes for the real length. | ||
| 713 | if (initial_length == 0xffffffff) | ||
| 714 | { | ||
| 715 | - header_.offset_size = 8; | ||
| 716 | + this->header_.offset_size = 8; | ||
| 717 | initial_length = elfcpp::Swap_unaligned<64, big_endian>::readval(lineptr); | ||
| 718 | lineptr += 8; | ||
| 719 | } | ||
| 720 | else | ||
| 721 | - header_.offset_size = 4; | ||
| 722 | + this->header_.offset_size = 4; | ||
| 723 | |||
| 724 | - header_.total_length = initial_length; | ||
| 725 | + this->header_.total_length = initial_length; | ||
| 726 | |||
| 727 | - gold_assert(lineptr + header_.total_length <= buffer_end_); | ||
| 728 | + this->end_of_unit_ = lineptr + initial_length; | ||
| 729 | + gold_assert(this->end_of_unit_ <= buffer_end_); | ||
| 730 | |||
| 731 | - header_.version = elfcpp::Swap_unaligned<16, big_endian>::readval(lineptr); | ||
| 732 | + this->header_.version = | ||
| 733 | + elfcpp::Swap_unaligned<16, big_endian>::readval(lineptr); | ||
| 734 | lineptr += 2; | ||
| 735 | |||
| 736 | - // Skip address size and segment selector for DWARF5. | ||
| 737 | - if (header_.version >= 5) | ||
| 738 | - lineptr += 2; | ||
| 739 | + // We can only read versions 2-5 of the DWARF line number table. | ||
| 740 | + // For other versions, just skip the entire line number table. | ||
| 741 | + if (this->header_.version < 2 || this->header_.version > 5) | ||
| 742 | + return this->end_of_unit_; | ||
| 743 | |||
| 744 | - if (header_.offset_size == 4) | ||
| 745 | - header_.prologue_length = elfcpp::Swap_unaligned<32, big_endian>::readval(lineptr); | ||
| 746 | + // DWARF 5 only: address size and segment selector. | ||
| 747 | + if (this->header_.version >= 5) | ||
| 748 | + { | ||
| 749 | + this->header_.address_size = *lineptr; | ||
| 750 | + // We ignore the segment selector. | ||
| 751 | + lineptr += 2; | ||
| 752 | + } | ||
| 753 | + | ||
| 754 | + if (this->header_.offset_size == 4) | ||
| 755 | + this->header_.prologue_length = | ||
| 756 | + elfcpp::Swap_unaligned<32, big_endian>::readval(lineptr); | ||
| 757 | else | ||
| 758 | - header_.prologue_length = elfcpp::Swap_unaligned<64, big_endian>::readval(lineptr); | ||
| 759 | - lineptr += header_.offset_size; | ||
| 760 | + this->header_.prologue_length = | ||
| 761 | + elfcpp::Swap_unaligned<64, big_endian>::readval(lineptr); | ||
| 762 | + lineptr += this->header_.offset_size; | ||
| 763 | |||
| 764 | - header_.min_insn_length = *lineptr; | ||
| 765 | + this->end_of_header_length_ = lineptr; | ||
| 766 | + | ||
| 767 | + this->header_.min_insn_length = *lineptr; | ||
| 768 | lineptr += 1; | ||
| 769 | |||
| 770 | - if (header_.version < 4) | ||
| 771 | - header_.max_ops_per_insn = 1; | ||
| 772 | + if (this->header_.version < 4) | ||
| 773 | + this->header_.max_ops_per_insn = 1; | ||
| 774 | else | ||
| 775 | { | ||
| 776 | // DWARF 4 added the maximum_operations_per_instruction field. | ||
| 777 | - header_.max_ops_per_insn = *lineptr; | ||
| 778 | + this->header_.max_ops_per_insn = *lineptr; | ||
| 779 | lineptr += 1; | ||
| 780 | // TODO: Add support for values other than 1. | ||
| 781 | - gold_assert(header_.max_ops_per_insn == 1); | ||
| 782 | + gold_assert(this->header_.max_ops_per_insn == 1); | ||
| 783 | } | ||
| 784 | |||
| 785 | - header_.default_is_stmt = *lineptr; | ||
| 786 | + this->header_.default_is_stmt = *lineptr; | ||
| 787 | lineptr += 1; | ||
| 788 | |||
| 789 | - header_.line_base = *reinterpret_cast<const signed char*>(lineptr); | ||
| 790 | + this->header_.line_base = *reinterpret_cast<const signed char*>(lineptr); | ||
| 791 | lineptr += 1; | ||
| 792 | |||
| 793 | - header_.line_range = *lineptr; | ||
| 794 | + this->header_.line_range = *lineptr; | ||
| 795 | lineptr += 1; | ||
| 796 | |||
| 797 | - header_.opcode_base = *lineptr; | ||
| 798 | + this->header_.opcode_base = *lineptr; | ||
| 799 | lineptr += 1; | ||
| 800 | |||
| 801 | - header_.std_opcode_lengths.resize(header_.opcode_base + 1); | ||
| 802 | - header_.std_opcode_lengths[0] = 0; | ||
| 803 | - for (int i = 1; i < header_.opcode_base; i++) | ||
| 804 | + this->header_.std_opcode_lengths.resize(this->header_.opcode_base + 1); | ||
| 805 | + this->header_.std_opcode_lengths[0] = 0; | ||
| 806 | + for (int i = 1; i < this->header_.opcode_base; i++) | ||
| 807 | { | ||
| 808 | - header_.std_opcode_lengths[i] = *lineptr; | ||
| 809 | + this->header_.std_opcode_lengths[i] = *lineptr; | ||
| 810 | lineptr += 1; | ||
| 811 | } | ||
| 812 | |||
| 813 | @@ -1707,10 +1972,11 @@ Sized_dwarf_line_info<size, big_endian>::read_header_prolog( | ||
| 814 | |||
| 815 | // The header for a debug_line section is mildly complicated, because | ||
| 816 | // the line info is very tightly encoded. | ||
| 817 | +// This routine is for DWARF versions 2, 3, and 4. | ||
| 818 | |||
| 819 | template<int size, bool big_endian> | ||
| 820 | const unsigned char* | ||
| 821 | -Sized_dwarf_line_info<size, big_endian>::read_header_tables( | ||
| 822 | +Sized_dwarf_line_info<size, big_endian>::read_header_tables_v2( | ||
| 823 | const unsigned char* lineptr) | ||
| 824 | { | ||
| 825 | ++this->current_header_index_; | ||
| 826 | @@ -1775,6 +2041,169 @@ Sized_dwarf_line_info<size, big_endian>::read_header_tables( | ||
| 827 | return lineptr; | ||
| 828 | } | ||
| 829 | |||
| 830 | +// This routine is for DWARF version 5. | ||
| 831 | + | ||
| 832 | +template<int size, bool big_endian> | ||
| 833 | +const unsigned char* | ||
| 834 | +Sized_dwarf_line_info<size, big_endian>::read_header_tables_v5( | ||
| 835 | + const unsigned char* lineptr) | ||
| 836 | +{ | ||
| 837 | + size_t len; | ||
| 838 | + | ||
| 839 | + ++this->current_header_index_; | ||
| 840 | + | ||
| 841 | + gold_assert(static_cast<int>(this->directories_.size()) | ||
| 842 | + == this->current_header_index_); | ||
| 843 | + gold_assert(static_cast<int>(this->files_.size()) | ||
| 844 | + == this->current_header_index_); | ||
| 845 | + | ||
| 846 | + // Read the directory list. | ||
| 847 | + unsigned int format_count = *lineptr; | ||
| 848 | + lineptr += 1; | ||
| 849 | + | ||
| 850 | + unsigned int *types = new unsigned int[format_count]; | ||
| 851 | + unsigned int *forms = new unsigned int[format_count]; | ||
| 852 | + | ||
| 853 | + for (unsigned int i = 0; i < format_count; i++) | ||
| 854 | + { | ||
| 855 | + types[i] = read_unsigned_LEB_128(lineptr, &len); | ||
| 856 | + lineptr += len; | ||
| 857 | + forms[i] = read_unsigned_LEB_128(lineptr, &len); | ||
| 858 | + lineptr += len; | ||
| 859 | + } | ||
| 860 | + | ||
| 861 | + uint64_t entry_count = read_unsigned_LEB_128(lineptr, &len); | ||
| 862 | + lineptr += len; | ||
| 863 | + this->directories_.push_back(std::vector<std::string>(0)); | ||
| 864 | + std::vector<std::string>& dir_list = this->directories_.back(); | ||
| 865 | + | ||
| 866 | + for (unsigned int j = 0; j < entry_count; j++) | ||
| 867 | + { | ||
| 868 | + std::string dirname; | ||
| 869 | + | ||
| 870 | + for (unsigned int i = 0; i < format_count; i++) | ||
| 871 | + { | ||
| 872 | + if (types[i] == elfcpp::DW_LNCT_path) | ||
| 873 | + { | ||
| 874 | + if (forms[i] == elfcpp::DW_FORM_string) | ||
| 875 | + { | ||
| 876 | + dirname = reinterpret_cast<const char*>(lineptr); | ||
| 877 | + lineptr += dirname.size() + 1; | ||
| 878 | + } | ||
| 879 | + else if (forms[i] == elfcpp::DW_FORM_line_strp) | ||
| 880 | + { | ||
| 881 | + uint64_t offset; | ||
| 882 | + if (this->header_.offset_size == 4) | ||
| 883 | + offset = | ||
| 884 | + elfcpp::Swap_unaligned<32, big_endian>::readval(lineptr); | ||
| 885 | + else | ||
| 886 | + offset = | ||
| 887 | + elfcpp::Swap_unaligned<64, big_endian>::readval(lineptr); | ||
| 888 | + typename Reloc_map::const_iterator it | ||
| 889 | + = this->reloc_map_.find(lineptr - this->buffer_); | ||
| 890 | + if (it != reloc_map_.end()) | ||
| 891 | + { | ||
| 892 | + if (this->track_relocs_type_ == elfcpp::SHT_RELA) | ||
| 893 | + offset = 0; | ||
| 894 | + offset += it->second.second; | ||
| 895 | + } | ||
| 896 | + lineptr += this->header_.offset_size; | ||
| 897 | + dirname = reinterpret_cast<const char*>(this->str_buffer_ | ||
| 898 | + + offset); | ||
| 899 | + } | ||
| 900 | + else | ||
| 901 | + return lineptr; | ||
| 902 | + } | ||
| 903 | + else | ||
| 904 | + return lineptr; | ||
| 905 | + } | ||
| 906 | + dir_list.push_back(dirname); | ||
| 907 | + } | ||
| 908 | + | ||
| 909 | + delete[] types; | ||
| 910 | + delete[] forms; | ||
| 911 | + | ||
| 912 | + // Read the filenames list. | ||
| 913 | + format_count = *lineptr; | ||
| 914 | + lineptr += 1; | ||
| 915 | + | ||
| 916 | + types = new unsigned int[format_count]; | ||
| 917 | + forms = new unsigned int[format_count]; | ||
| 918 | + | ||
| 919 | + for (unsigned int i = 0; i < format_count; i++) | ||
| 920 | + { | ||
| 921 | + types[i] = read_unsigned_LEB_128(lineptr, &len); | ||
| 922 | + lineptr += len; | ||
| 923 | + forms[i] = read_unsigned_LEB_128(lineptr, &len); | ||
| 924 | + lineptr += len; | ||
| 925 | + } | ||
| 926 | + | ||
| 927 | + entry_count = read_unsigned_LEB_128(lineptr, &len); | ||
| 928 | + lineptr += len; | ||
| 929 | + this->files_.push_back( | ||
| 930 | + std::vector<std::pair<int, std::string> >(0)); | ||
| 931 | + std::vector<std::pair<int, std::string> >& file_list = this->files_.back(); | ||
| 932 | + | ||
| 933 | + for (unsigned int j = 0; j < entry_count; j++) | ||
| 934 | + { | ||
| 935 | + const char* path = NULL; | ||
| 936 | + int dirindex = 0; | ||
| 937 | + | ||
| 938 | + for (unsigned int i = 0; i < format_count; i++) | ||
| 939 | + { | ||
| 940 | + if (types[i] == elfcpp::DW_LNCT_path) | ||
| 941 | + { | ||
| 942 | + if (forms[i] == elfcpp::DW_FORM_string) | ||
| 943 | + { | ||
| 944 | + path = reinterpret_cast<const char*>(lineptr); | ||
| 945 | + lineptr += strlen(path) + 1; | ||
| 946 | + } | ||
| 947 | + else if (forms[i] == elfcpp::DW_FORM_line_strp) | ||
| 948 | + { | ||
| 949 | + uint64_t offset; | ||
| 950 | + if (this->header_.offset_size == 4) | ||
| 951 | + offset = elfcpp::Swap_unaligned<32, big_endian>::readval(lineptr); | ||
| 952 | + else | ||
| 953 | + offset = elfcpp::Swap_unaligned<64, big_endian>::readval(lineptr); | ||
| 954 | + typename Reloc_map::const_iterator it | ||
| 955 | + = this->reloc_map_.find(lineptr - this->buffer_); | ||
| 956 | + if (it != reloc_map_.end()) | ||
| 957 | + { | ||
| 958 | + if (this->track_relocs_type_ == elfcpp::SHT_RELA) | ||
| 959 | + offset = 0; | ||
| 960 | + offset += it->second.second; | ||
| 961 | + } | ||
| 962 | + lineptr += this->header_.offset_size; | ||
| 963 | + path = reinterpret_cast<const char*>(this->str_buffer_ | ||
| 964 | + + offset); | ||
| 965 | + } | ||
| 966 | + else | ||
| 967 | + return lineptr; | ||
| 968 | + } | ||
| 969 | + else if (types[i] == elfcpp::DW_LNCT_directory_index) | ||
| 970 | + { | ||
| 971 | + if (forms[i] == elfcpp::DW_FORM_udata) | ||
| 972 | + { | ||
| 973 | + dirindex = read_unsigned_LEB_128(lineptr, &len); | ||
| 974 | + lineptr += len; | ||
| 975 | + } | ||
| 976 | + else | ||
| 977 | + return lineptr; | ||
| 978 | + } | ||
| 979 | + else | ||
| 980 | + return lineptr; | ||
| 981 | + } | ||
| 982 | + gold_debug(DEBUG_LOCATION, "File %3d: %s", | ||
| 983 | + static_cast<int>(file_list.size()), path); | ||
| 984 | + file_list.push_back(std::make_pair(dirindex, path)); | ||
| 985 | + } | ||
| 986 | + | ||
| 987 | + delete[] types; | ||
| 988 | + delete[] forms; | ||
| 989 | + | ||
| 990 | + return lineptr; | ||
| 991 | +} | ||
| 992 | + | ||
| 993 | // Process a single opcode in the .debug.line structure. | ||
| 994 | |||
| 995 | template<int size, bool big_endian> | ||
| 996 | @@ -1790,15 +2219,15 @@ Sized_dwarf_line_info<size, big_endian>::process_one_opcode( | ||
| 997 | |||
| 998 | // If the opcode is great than the opcode_base, it is a special | ||
| 999 | // opcode. Most line programs consist mainly of special opcodes. | ||
| 1000 | - if (opcode >= header_.opcode_base) | ||
| 1001 | + if (opcode >= this->header_.opcode_base) | ||
| 1002 | { | ||
| 1003 | - opcode -= header_.opcode_base; | ||
| 1004 | - const int advance_address = ((opcode / header_.line_range) | ||
| 1005 | - * header_.min_insn_length); | ||
| 1006 | + opcode -= this->header_.opcode_base; | ||
| 1007 | + const int advance_address = ((opcode / this->header_.line_range) | ||
| 1008 | + * this->header_.min_insn_length); | ||
| 1009 | lsm->address += advance_address; | ||
| 1010 | |||
| 1011 | - const int advance_line = ((opcode % header_.line_range) | ||
| 1012 | - + header_.line_base); | ||
| 1013 | + const int advance_line = ((opcode % this->header_.line_range) | ||
| 1014 | + + this->header_.line_base); | ||
| 1015 | lsm->line_num += advance_line; | ||
| 1016 | lsm->basic_block = true; | ||
| 1017 | *len = oplen; | ||
| 1018 | @@ -1818,13 +2247,13 @@ Sized_dwarf_line_info<size, big_endian>::process_one_opcode( | ||
| 1019 | const uint64_t advance_address | ||
| 1020 | = read_unsigned_LEB_128(start, &templen); | ||
| 1021 | oplen += templen; | ||
| 1022 | - lsm->address += header_.min_insn_length * advance_address; | ||
| 1023 | + lsm->address += this->header_.min_insn_length * advance_address; | ||
| 1024 | } | ||
| 1025 | break; | ||
| 1026 | |||
| 1027 | case elfcpp::DW_LNS_advance_line: | ||
| 1028 | { | ||
| 1029 | - const uint64_t advance_line = read_signed_LEB_128(start, &templen); | ||
| 1030 | + const int64_t advance_line = read_signed_LEB_128(start, &templen); | ||
| 1031 | oplen += templen; | ||
| 1032 | lsm->line_num += advance_line; | ||
| 1033 | } | ||
| 1034 | @@ -1865,9 +2294,9 @@ Sized_dwarf_line_info<size, big_endian>::process_one_opcode( | ||
| 1035 | |||
| 1036 | case elfcpp::DW_LNS_const_add_pc: | ||
| 1037 | { | ||
| 1038 | - const int advance_address = (header_.min_insn_length | ||
| 1039 | - * ((255 - header_.opcode_base) | ||
| 1040 | - / header_.line_range)); | ||
| 1041 | + const int advance_address = (this->header_.min_insn_length | ||
| 1042 | + * ((255 - this->header_.opcode_base) | ||
| 1043 | + / this->header_.line_range)); | ||
| 1044 | lsm->address += advance_address; | ||
| 1045 | } | ||
| 1046 | break; | ||
| 1047 | @@ -1950,7 +2379,7 @@ Sized_dwarf_line_info<size, big_endian>::process_one_opcode( | ||
| 1048 | default: | ||
| 1049 | { | ||
| 1050 | // Ignore unknown opcode silently | ||
| 1051 | - for (int i = 0; i < header_.std_opcode_lengths[opcode]; i++) | ||
| 1052 | + for (int i = 0; i < this->header_.std_opcode_lengths[opcode]; i++) | ||
| 1053 | { | ||
| 1054 | size_t templen; | ||
| 1055 | read_unsigned_LEB_128(start, &templen); | ||
| 1056 | @@ -1970,28 +2399,24 @@ Sized_dwarf_line_info<size, big_endian>::process_one_opcode( | ||
| 1057 | template<int size, bool big_endian> | ||
| 1058 | unsigned const char* | ||
| 1059 | Sized_dwarf_line_info<size, big_endian>::read_lines(unsigned const char* lineptr, | ||
| 1060 | + unsigned const char* endptr, | ||
| 1061 | unsigned int shndx) | ||
| 1062 | { | ||
| 1063 | struct LineStateMachine lsm; | ||
| 1064 | |||
| 1065 | - // LENGTHSTART is the place the length field is based on. It is the | ||
| 1066 | - // point in the header after the initial length field. | ||
| 1067 | - const unsigned char* lengthstart = buffer_; | ||
| 1068 | - | ||
| 1069 | - // In 64 bit dwarf, the initial length is 12 bytes, because of the | ||
| 1070 | - // 0xffffffff at the start. | ||
| 1071 | - if (header_.offset_size == 8) | ||
| 1072 | - lengthstart += 12; | ||
| 1073 | - else | ||
| 1074 | - lengthstart += 4; | ||
| 1075 | - | ||
| 1076 | - while (lineptr < lengthstart + header_.total_length) | ||
| 1077 | + while (lineptr < endptr) | ||
| 1078 | { | ||
| 1079 | - ResetLineStateMachine(&lsm, header_.default_is_stmt); | ||
| 1080 | + ResetLineStateMachine(&lsm, this->header_.default_is_stmt); | ||
| 1081 | while (!lsm.end_sequence) | ||
| 1082 | { | ||
| 1083 | size_t oplength; | ||
| 1084 | + | ||
| 1085 | + if (lineptr >= endptr) | ||
| 1086 | + break; | ||
| 1087 | + | ||
| 1088 | bool add_line = this->process_one_opcode(lineptr, &lsm, &oplength); | ||
| 1089 | + lineptr += oplength; | ||
| 1090 | + | ||
| 1091 | if (add_line | ||
| 1092 | && (shndx == -1U || lsm.shndx == -1U || shndx == lsm.shndx)) | ||
| 1093 | { | ||
| 1094 | @@ -2012,11 +2437,10 @@ Sized_dwarf_line_info<size, big_endian>::read_lines(unsigned const char* lineptr | ||
| 1095 | map.back().last_line_for_offset = false; | ||
| 1096 | map.push_back(entry); | ||
| 1097 | } | ||
| 1098 | - lineptr += oplength; | ||
| 1099 | } | ||
| 1100 | } | ||
| 1101 | |||
| 1102 | - return lengthstart + header_.total_length; | ||
| 1103 | + return endptr; | ||
| 1104 | } | ||
| 1105 | |||
| 1106 | // Read the relocations into a Reloc_map. | ||
| 1107 | @@ -2057,9 +2481,17 @@ Sized_dwarf_line_info<size, big_endian>::read_line_mappings(unsigned int shndx) | ||
| 1108 | { | ||
| 1109 | const unsigned char* lineptr = this->buffer_; | ||
| 1110 | lineptr = this->read_header_prolog(lineptr); | ||
| 1111 | - lineptr = this->read_header_tables(lineptr); | ||
| 1112 | - lineptr = this->read_lines(lineptr, shndx); | ||
| 1113 | - this->buffer_ = lineptr; | ||
| 1114 | + if (this->header_.version >= 2 && this->header_.version <= 4) | ||
| 1115 | + { | ||
| 1116 | + lineptr = this->read_header_tables_v2(lineptr); | ||
| 1117 | + lineptr = this->read_lines(lineptr, this->end_of_unit_, shndx); | ||
| 1118 | + } | ||
| 1119 | + else if (this->header_.version == 5) | ||
| 1120 | + { | ||
| 1121 | + lineptr = this->read_header_tables_v5(lineptr); | ||
| 1122 | + lineptr = this->read_lines(lineptr, this->end_of_unit_, shndx); | ||
| 1123 | + } | ||
| 1124 | + this->buffer_ = this->end_of_unit_; | ||
| 1125 | } | ||
| 1126 | |||
| 1127 | // Sort the lines numbers, so addr2line can use binary search. | ||
| 1128 | @@ -2215,6 +2647,9 @@ Sized_dwarf_line_info<size, big_endian>::do_addr2line( | ||
| 1129 | off_t offset, | ||
| 1130 | std::vector<std::string>* other_lines) | ||
| 1131 | { | ||
| 1132 | + gold_debug(DEBUG_LOCATION, "do_addr2line: shndx %u offset %08x", | ||
| 1133 | + shndx, static_cast<int>(offset)); | ||
| 1134 | + | ||
| 1135 | if (this->data_valid_ == false) | ||
| 1136 | return ""; | ||
| 1137 | |||
| 1138 | diff --git a/gold/dwarf_reader.h b/gold/dwarf_reader.h | ||
| 1139 | index 80b2231327c..921a1f7c876 100644 | ||
| 1140 | --- a/gold/dwarf_reader.h | ||
| 1141 | +++ b/gold/dwarf_reader.h | ||
| 1142 | @@ -173,11 +173,12 @@ class Dwarf_abbrev_table | ||
| 1143 | // An attribute list entry. | ||
| 1144 | struct Attribute | ||
| 1145 | { | ||
| 1146 | - Attribute(unsigned int a, unsigned int f) | ||
| 1147 | - : attr(a), form(f) | ||
| 1148 | + Attribute(unsigned int a, unsigned int f, int c) | ||
| 1149 | + : attr(a), form(f), implicit_const(c) | ||
| 1150 | { } | ||
| 1151 | unsigned int attr; | ||
| 1152 | unsigned int form; | ||
| 1153 | + int implicit_const; | ||
| 1154 | }; | ||
| 1155 | |||
| 1156 | // An abbrev code entry. | ||
| 1157 | @@ -190,9 +191,9 @@ class Dwarf_abbrev_table | ||
| 1158 | } | ||
| 1159 | |||
| 1160 | void | ||
| 1161 | - add_attribute(unsigned int attr, unsigned int form) | ||
| 1162 | + add_attribute(unsigned int attr, unsigned int form, int implicit_const) | ||
| 1163 | { | ||
| 1164 | - this->attributes.push_back(Attribute(attr, form)); | ||
| 1165 | + this->attributes.push_back(Attribute(attr, form, implicit_const)); | ||
| 1166 | } | ||
| 1167 | |||
| 1168 | // The DWARF tag. | ||
| 1169 | @@ -349,14 +350,15 @@ class Dwarf_ranges_table | ||
| 1170 | delete this->ranges_reloc_mapper_; | ||
| 1171 | } | ||
| 1172 | |||
| 1173 | - // Read the ranges table from an object file. | ||
| 1174 | + // Fetch the contents of the ranges table from an object file. | ||
| 1175 | bool | ||
| 1176 | read_ranges_table(Relobj* object, | ||
| 1177 | const unsigned char* symtab, | ||
| 1178 | off_t symtab_size, | ||
| 1179 | - unsigned int ranges_shndx); | ||
| 1180 | + unsigned int ranges_shndx, | ||
| 1181 | + unsigned int version); | ||
| 1182 | |||
| 1183 | - // Read the range table from an object file. | ||
| 1184 | + // Read the DWARF 2/3/4 range table. | ||
| 1185 | Dwarf_range_list* | ||
| 1186 | read_range_list(Relobj* object, | ||
| 1187 | const unsigned char* symtab, | ||
| 1188 | @@ -365,6 +367,15 @@ class Dwarf_ranges_table | ||
| 1189 | unsigned int ranges_shndx, | ||
| 1190 | off_t ranges_offset); | ||
| 1191 | |||
| 1192 | + // Read the DWARF 5 rnglists table. | ||
| 1193 | + Dwarf_range_list* | ||
| 1194 | + read_range_list_v5(Relobj* object, | ||
| 1195 | + const unsigned char* symtab, | ||
| 1196 | + off_t symtab_size, | ||
| 1197 | + unsigned int address_size, | ||
| 1198 | + unsigned int ranges_shndx, | ||
| 1199 | + off_t ranges_offset); | ||
| 1200 | + | ||
| 1201 | // Look for a relocation at offset OFF in the range table, | ||
| 1202 | // and return the section index and offset of the target. | ||
| 1203 | unsigned int | ||
| 1204 | @@ -490,8 +501,6 @@ class Dwarf_die | ||
| 1205 | unsigned int shndx; | ||
| 1206 | // Block length for block forms. | ||
| 1207 | unsigned int blocklen; | ||
| 1208 | - // Attribute offset for DW_FORM_strp. | ||
| 1209 | - unsigned int attr_off; | ||
| 1210 | } aux; | ||
| 1211 | }; | ||
| 1212 | |||
| 1213 | @@ -684,6 +693,10 @@ class Dwarf_die | ||
| 1214 | // calls the various visit_xxx() methods for each header. Clients | ||
| 1215 | // should derive a new class from this one and implement the | ||
| 1216 | // visit_compilation_unit() and visit_type_unit() functions. | ||
| 1217 | +// IS_TYPE_UNIT is true if we are reading from a .debug_types section, | ||
| 1218 | +// which is used only in DWARF 4. For DWARF 5, it will be false, | ||
| 1219 | +// and we will determine whether it's a type init when we parse the | ||
| 1220 | +// header. | ||
| 1221 | |||
| 1222 | class Dwarf_info_reader | ||
| 1223 | { | ||
| 1224 | @@ -695,7 +708,7 @@ class Dwarf_info_reader | ||
| 1225 | unsigned int shndx, | ||
| 1226 | unsigned int reloc_shndx, | ||
| 1227 | unsigned int reloc_type) | ||
| 1228 | - : is_type_unit_(is_type_unit), object_(object), symtab_(symtab), | ||
| 1229 | + : object_(object), symtab_(symtab), | ||
| 1230 | symtab_size_(symtab_size), shndx_(shndx), reloc_shndx_(reloc_shndx), | ||
| 1231 | reloc_type_(reloc_type), abbrev_shndx_(0), string_shndx_(0), | ||
| 1232 | buffer_(NULL), buffer_end_(NULL), cu_offset_(0), cu_length_(0), | ||
| 1233 | @@ -703,7 +716,12 @@ class Dwarf_info_reader | ||
| 1234 | abbrev_table_(), ranges_table_(this), | ||
| 1235 | reloc_mapper_(NULL), string_buffer_(NULL), string_buffer_end_(NULL), | ||
| 1236 | owns_string_buffer_(false), string_output_section_offset_(0) | ||
| 1237 | - { } | ||
| 1238 | + { | ||
| 1239 | + // For DWARF 4, we infer the unit type from the section name. | ||
| 1240 | + // For DWARF 5, we will read this from the unit header. | ||
| 1241 | + this->unit_type_ = | ||
| 1242 | + (is_type_unit ? elfcpp::DW_UT_type : elfcpp::DW_UT_compile); | ||
| 1243 | + } | ||
| 1244 | |||
| 1245 | virtual | ||
| 1246 | ~Dwarf_info_reader() | ||
| 1247 | @@ -714,6 +732,13 @@ class Dwarf_info_reader | ||
| 1248 | delete[] this->string_buffer_; | ||
| 1249 | } | ||
| 1250 | |||
| 1251 | + bool | ||
| 1252 | + is_type_unit() const | ||
| 1253 | + { | ||
| 1254 | + return (this->unit_type_ == elfcpp::DW_UT_type | ||
| 1255 | + || this->unit_type_ == elfcpp::DW_UT_split_type); | ||
| 1256 | + } | ||
| 1257 | + | ||
| 1258 | // Begin parsing the debug info. This calls visit_compilation_unit() | ||
| 1259 | // or visit_type_unit() for each compilation or type unit found in the | ||
| 1260 | // section, and visit_die() for each top-level DIE. | ||
| 1261 | @@ -745,6 +770,9 @@ class Dwarf_info_reader | ||
| 1262 | inline typename elfcpp::Valtype_base<valsize>::Valtype | ||
| 1263 | read_from_pointer(const unsigned char** source); | ||
| 1264 | |||
| 1265 | + inline typename elfcpp::Valtype_base<32>::Valtype | ||
| 1266 | + read_3bytes_from_pointer(const unsigned char** source); | ||
| 1267 | + | ||
| 1268 | // Look for a relocation at offset ATTR_OFF in the dwarf info, | ||
| 1269 | // and return the section index and offset of the target. | ||
| 1270 | unsigned int | ||
| 1271 | @@ -818,12 +846,20 @@ class Dwarf_info_reader | ||
| 1272 | Dwarf_range_list* | ||
| 1273 | read_range_list(unsigned int ranges_shndx, off_t ranges_offset) | ||
| 1274 | { | ||
| 1275 | - return this->ranges_table_.read_range_list(this->object_, | ||
| 1276 | - this->symtab_, | ||
| 1277 | - this->symtab_size_, | ||
| 1278 | - this->address_size_, | ||
| 1279 | - ranges_shndx, | ||
| 1280 | - ranges_offset); | ||
| 1281 | + if (this->cu_version_ < 5) | ||
| 1282 | + return this->ranges_table_.read_range_list(this->object_, | ||
| 1283 | + this->symtab_, | ||
| 1284 | + this->symtab_size_, | ||
| 1285 | + this->address_size_, | ||
| 1286 | + ranges_shndx, | ||
| 1287 | + ranges_offset); | ||
| 1288 | + else | ||
| 1289 | + return this->ranges_table_.read_range_list_v5(this->object_, | ||
| 1290 | + this->symtab_, | ||
| 1291 | + this->symtab_size_, | ||
| 1292 | + this->address_size_, | ||
| 1293 | + ranges_shndx, | ||
| 1294 | + ranges_offset); | ||
| 1295 | } | ||
| 1296 | |||
| 1297 | // Return the object. | ||
| 1298 | @@ -873,8 +909,8 @@ class Dwarf_info_reader | ||
| 1299 | bool | ||
| 1300 | do_read_string_table(unsigned int string_shndx); | ||
| 1301 | |||
| 1302 | - // True if this is a type unit; false for a compilation unit. | ||
| 1303 | - bool is_type_unit_; | ||
| 1304 | + // The unit type (DW_UT_xxx). | ||
| 1305 | + unsigned int unit_type_; | ||
| 1306 | // The object containing the .debug_info or .debug_types input section. | ||
| 1307 | Relobj* object_; | ||
| 1308 | // The ELF symbol table. | ||
| 1309 | @@ -1008,6 +1044,8 @@ class Sized_dwarf_line_info : public Dwarf_line_info | ||
| 1310 | { | ||
| 1311 | if (this->buffer_start_ != NULL) | ||
| 1312 | delete[] this->buffer_start_; | ||
| 1313 | + if (this->str_buffer_start_ != NULL) | ||
| 1314 | + delete[] this->str_buffer_start_; | ||
| 1315 | } | ||
| 1316 | |||
| 1317 | private: | ||
| 1318 | @@ -1030,19 +1068,23 @@ class Sized_dwarf_line_info : public Dwarf_line_info | ||
| 1319 | void | ||
| 1320 | read_relocs(); | ||
| 1321 | |||
| 1322 | - // Reads the DWARF2/3 header for this line info. Each takes as input | ||
| 1323 | + // Reads the DWARF header for this line info. Each takes as input | ||
| 1324 | // a starting buffer position, and returns the ending position. | ||
| 1325 | const unsigned char* | ||
| 1326 | read_header_prolog(const unsigned char* lineptr); | ||
| 1327 | |||
| 1328 | const unsigned char* | ||
| 1329 | - read_header_tables(const unsigned char* lineptr); | ||
| 1330 | + read_header_tables_v2(const unsigned char* lineptr); | ||
| 1331 | + | ||
| 1332 | + const unsigned char* | ||
| 1333 | + read_header_tables_v5(const unsigned char* lineptr); | ||
| 1334 | |||
| 1335 | - // Reads the DWARF2/3 line information. If shndx is non-negative, | ||
| 1336 | + // Reads the DWARF line information. If shndx is non-negative, | ||
| 1337 | // discard all line information that doesn't pertain to the given | ||
| 1338 | // section. | ||
| 1339 | const unsigned char* | ||
| 1340 | - read_lines(const unsigned char* lineptr, unsigned int shndx); | ||
| 1341 | + read_lines(const unsigned char* lineptr, const unsigned char* endptr, | ||
| 1342 | + unsigned int shndx); | ||
| 1343 | |||
| 1344 | // Process a single line info opcode at START using the state | ||
| 1345 | // machine at LSM. Return true if we should define a line using the | ||
| 1346 | @@ -1069,6 +1111,7 @@ class Sized_dwarf_line_info : public Dwarf_line_info | ||
| 1347 | { | ||
| 1348 | off_t total_length; | ||
| 1349 | int version; | ||
| 1350 | + int address_size; | ||
| 1351 | off_t prologue_length; | ||
| 1352 | int min_insn_length; // insn stands for instruction | ||
| 1353 | int max_ops_per_insn; // Added in DWARF-4. | ||
| 1354 | @@ -1089,6 +1132,20 @@ class Sized_dwarf_line_info : public Dwarf_line_info | ||
| 1355 | // of the buffer. | ||
| 1356 | const unsigned char* buffer_start_; | ||
| 1357 | |||
| 1358 | + // str_buffer is the buffer for the line table strings. | ||
| 1359 | + const unsigned char* str_buffer_; | ||
| 1360 | + const unsigned char* str_buffer_end_; | ||
| 1361 | + // If the buffer was allocated temporarily, and therefore must be | ||
| 1362 | + // deallocated in the dtor, this contains a pointer to the start | ||
| 1363 | + // of the buffer. | ||
| 1364 | + const unsigned char* str_buffer_start_; | ||
| 1365 | + | ||
| 1366 | + // Pointer to the end of the header_length field (aka prologue_length). | ||
| 1367 | + const unsigned char* end_of_header_length_; | ||
| 1368 | + | ||
| 1369 | + // Pointer to the end of the current compilation unit. | ||
| 1370 | + const unsigned char* end_of_unit_; | ||
| 1371 | + | ||
| 1372 | // This has relocations that point into buffer. | ||
| 1373 | Sized_elf_reloc_mapper<size, big_endian>* reloc_mapper_; | ||
| 1374 | // The type of the reloc section in track_relocs_--SHT_REL or SHT_RELA. | ||
