GNU Binutils with patches for OS216
Revision | d1c4b12b9d48d9266b78e2c22d70aa25830b9f8f (tree) |
---|---|
Time | 2015-05-15 19:24:33 |
Author | Nick Clifton <nickc@redh...> |
Commiter | Nick Clifton |
Fix PR18374 by making readelf and objdump ignore end-of-list markers in the .debug_loc section if there are relocations against them.
PR binutils/18374
bin * dwarf.h (struct dwarf_section): Add reloc_info and num_relocs
fields.
(struct dwarf_section_display): Change bitfield to boolean.
(reloc_at): Add prototype.
* dwarf.c (display_loc_list): Ignore list terminators if there are
relocs against them.
(display_debug_loc): Issue a warning if there are relocs against
the .debug_loc section.
(display_displays): Initialise reloc_info and num_relocs fields.
* objdump.c (load_specific_debug_section): Initialise reloc_info
and num_relocs fields.
(reloc_at): New function.
* readelf.c (is_32bit_abs_reloc): Add IA64's R_IA64_DIS32LSB
reloc.
(reloc_at): New function.
(apply_relocations): Add relocs_return and num_relocs_return
parameters. Fill them in with the loaded relocs if non-NULL.
(dump_section_as_bytes): Update call to apply_relocations.
(load_specific_debug_section): Initialise reloc_info and
num_relocs fields.
tests * binutils-all/pr18374.s: New test file.
* binutils-all/readelf.exp: Assemble and run the new test.
* binutils-all/readelf.pr18374: Expected output from readelf.
@@ -8,6 +8,30 @@ | ||
8 | 8 | uncompressed size. Don't check the zlib header. |
9 | 9 | (load_specific_debug_section): Updated. |
10 | 10 | |
11 | +2015-05-15 Nick Clifton <nickc@redhat.com> | |
12 | + | |
13 | + PR binutils/18374 | |
14 | + * dwarf.h (struct dwarf_section): Add reloc_info and num_relocs | |
15 | + fields. | |
16 | + (struct dwarf_section_display): Change bitfield to boolean. | |
17 | + (reloc_at): Add prototype. | |
18 | + * dwarf.c (display_loc_list): Ignore list terminators if there are | |
19 | + relocs against them. | |
20 | + (display_debug_loc): Issue a warning if there are relocs against | |
21 | + the .debug_loc section. | |
22 | + (display_displays): Initialise reloc_info and num_relocs fields. | |
23 | + * objdump.c (load_specific_debug_section): Initialise reloc_info | |
24 | + and num_relocs fields. | |
25 | + (reloc_at): New function. | |
26 | + * readelf.c (is_32bit_abs_reloc): Add IA64's R_IA64_DIS32LSB | |
27 | + reloc. | |
28 | + (reloc_at): New function. | |
29 | + (apply_relocations): Add relocs_return and num_relocs_return | |
30 | + parameters. Fill them in with the loaded relocs if non-NULL. | |
31 | + (dump_section_as_bytes): Update call to apply_relocations. | |
32 | + (load_specific_debug_section): Initialise reloc_info and | |
33 | + num_relocs fields. | |
34 | + | |
11 | 35 | 2015-05-13 H.J. Lu <hongjiu.lu@intel.com> |
12 | 36 | |
13 | 37 | * elfedit.c (elf_class): Return ELF_CLASS_BOTH by default. |
@@ -4367,6 +4367,8 @@ display_loc_list (struct dwarf_section *section, | ||
4367 | 4367 | |
4368 | 4368 | while (1) |
4369 | 4369 | { |
4370 | + unsigned long off = offset + (start - *start_ptr); | |
4371 | + | |
4370 | 4372 | if (start + 2 * pointer_size > section_end) |
4371 | 4373 | { |
4372 | 4374 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), |
@@ -4374,7 +4376,7 @@ display_loc_list (struct dwarf_section *section, | ||
4374 | 4376 | break; |
4375 | 4377 | } |
4376 | 4378 | |
4377 | - printf (" %8.8lx ", offset + (start - *start_ptr)); | |
4379 | + printf (" %8.8lx ", off); | |
4378 | 4380 | |
4379 | 4381 | /* Note: we use sign extension here in order to be sure that we can detect |
4380 | 4382 | the -1 escape value. Sign extension into the top 32 bits of a 32-bit |
@@ -4385,8 +4387,18 @@ display_loc_list (struct dwarf_section *section, | ||
4385 | 4387 | |
4386 | 4388 | if (begin == 0 && end == 0) |
4387 | 4389 | { |
4388 | - printf (_("<End of list>\n")); | |
4389 | - break; | |
4390 | + /* PR 18374: In a object file we can have a location list that | |
4391 | + starts with a begin and end of 0 because there are relocations | |
4392 | + that need to be applied to the addresses. Actually applying | |
4393 | + the relocations now does not help as they will probably resolve | |
4394 | + to 0, since the object file has not been fully linked. Real | |
4395 | + end of list markers will not have any relocations against them. */ | |
4396 | + if (! reloc_at (section, off) | |
4397 | + && ! reloc_at (section, off + pointer_size)) | |
4398 | + { | |
4399 | + printf (_("<End of list>\n")); | |
4400 | + break; | |
4401 | + } | |
4390 | 4402 | } |
4391 | 4403 | |
4392 | 4404 | /* Check base address specifiers. */ |
@@ -4607,7 +4619,6 @@ display_debug_loc (struct dwarf_section *section, void *file) | ||
4607 | 4619 | unsigned int first = 0; |
4608 | 4620 | unsigned int i; |
4609 | 4621 | unsigned int j; |
4610 | - unsigned int k; | |
4611 | 4622 | int seen_first_offset = 0; |
4612 | 4623 | int locs_sorted = 1; |
4613 | 4624 | unsigned char *next; |
@@ -4683,13 +4694,16 @@ display_debug_loc (struct dwarf_section *section, void *file) | ||
4683 | 4694 | if (!locs_sorted) |
4684 | 4695 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); |
4685 | 4696 | printf (_("Contents of the %s section:\n\n"), section->name); |
4686 | - printf (_(" Offset Begin End Expression\n")); | |
4697 | + if (reloc_at (section, 0)) | |
4698 | + printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
4699 | + printf (_(" Offset Begin End Expression\n")); | |
4687 | 4700 | |
4688 | 4701 | seen_first_offset = 0; |
4689 | 4702 | for (i = first; i < num_debug_info_entries; i++) |
4690 | 4703 | { |
4691 | 4704 | unsigned long offset; |
4692 | 4705 | unsigned long base_address; |
4706 | + unsigned int k; | |
4693 | 4707 | int has_frame_base; |
4694 | 4708 | |
4695 | 4709 | if (!locs_sorted) |
@@ -7561,76 +7575,76 @@ dwarf_select_sections_all (void) | ||
7561 | 7575 | |
7562 | 7576 | struct dwarf_section_display debug_displays[] = |
7563 | 7577 | { |
7564 | - { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL }, | |
7565 | - display_debug_abbrev, &do_debug_abbrevs, 0 }, | |
7566 | - { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL }, | |
7567 | - display_debug_aranges, &do_debug_aranges, 1 }, | |
7568 | - { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL }, | |
7569 | - display_debug_frames, &do_debug_frames, 1 }, | |
7570 | - { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL }, | |
7571 | - display_debug_info, &do_debug_info, 1 }, | |
7572 | - { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL }, | |
7573 | - display_debug_lines, &do_debug_lines, 1 }, | |
7574 | - { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL }, | |
7575 | - display_debug_pubnames, &do_debug_pubnames, 0 }, | |
7576 | - { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL }, | |
7577 | - display_debug_gnu_pubnames, &do_debug_pubnames, 0 }, | |
7578 | - { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL }, | |
7579 | - display_debug_frames, &do_debug_frames, 1 }, | |
7580 | - { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL }, | |
7581 | - display_debug_macinfo, &do_debug_macinfo, 0 }, | |
7582 | - { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL }, | |
7583 | - display_debug_macro, &do_debug_macinfo, 1 }, | |
7584 | - { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL }, | |
7585 | - display_debug_str, &do_debug_str, 0 }, | |
7586 | - { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL }, | |
7587 | - display_debug_loc, &do_debug_loc, 1 }, | |
7588 | - { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL }, | |
7589 | - display_debug_pubnames, &do_debug_pubtypes, 0 }, | |
7590 | - { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL }, | |
7591 | - display_debug_gnu_pubnames, &do_debug_pubtypes, 0 }, | |
7592 | - { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL }, | |
7593 | - display_debug_ranges, &do_debug_ranges, 1 }, | |
7594 | - { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL }, | |
7595 | - display_debug_not_supported, NULL, 0 }, | |
7596 | - { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL }, | |
7597 | - display_debug_not_supported, NULL, 0 }, | |
7598 | - { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL }, | |
7599 | - display_debug_types, &do_debug_info, 1 }, | |
7600 | - { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL }, | |
7601 | - display_debug_not_supported, NULL, 0 }, | |
7602 | - { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL }, | |
7603 | - display_gdb_index, &do_gdb_index, 0 }, | |
7604 | - { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL }, | |
7605 | - display_trace_info, &do_trace_info, 1 }, | |
7606 | - { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL }, | |
7607 | - display_debug_abbrev, &do_trace_abbrevs, 0 }, | |
7608 | - { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL }, | |
7609 | - display_debug_aranges, &do_trace_aranges, 0 }, | |
7610 | - { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL }, | |
7611 | - display_debug_info, &do_debug_info, 1 }, | |
7612 | - { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL }, | |
7613 | - display_debug_abbrev, &do_debug_abbrevs, 0 }, | |
7614 | - { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL }, | |
7615 | - display_debug_types, &do_debug_info, 1 }, | |
7616 | - { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL }, | |
7617 | - display_debug_lines, &do_debug_lines, 1 }, | |
7618 | - { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL }, | |
7619 | - display_debug_loc, &do_debug_loc, 1 }, | |
7620 | - { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL }, | |
7621 | - display_debug_macro, &do_debug_macinfo, 1 }, | |
7622 | - { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL }, | |
7623 | - display_debug_macinfo, &do_debug_macinfo, 0 }, | |
7624 | - { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL }, | |
7625 | - display_debug_str, &do_debug_str, 1 }, | |
7626 | - { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL }, | |
7627 | - display_debug_str_offsets, NULL, 0 }, | |
7628 | - { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL }, | |
7629 | - display_debug_str_offsets, NULL, 0 }, | |
7630 | - { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL }, | |
7631 | - display_debug_addr, &do_debug_addr, 1 }, | |
7632 | - { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL }, | |
7633 | - display_cu_index, &do_debug_cu_index, 0 }, | |
7634 | - { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL }, | |
7635 | - display_cu_index, &do_debug_cu_index, 0 }, | |
7578 | + { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7579 | + display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
7580 | + { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7581 | + display_debug_aranges, &do_debug_aranges, TRUE }, | |
7582 | + { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7583 | + display_debug_frames, &do_debug_frames, TRUE }, | |
7584 | + { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL }, | |
7585 | + display_debug_info, &do_debug_info, TRUE }, | |
7586 | + { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7587 | + display_debug_lines, &do_debug_lines, TRUE }, | |
7588 | + { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7589 | + display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
7590 | + { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7591 | + display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
7592 | + { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7593 | + display_debug_frames, &do_debug_frames, TRUE }, | |
7594 | + { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7595 | + display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
7596 | + { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7597 | + display_debug_macro, &do_debug_macinfo, TRUE }, | |
7598 | + { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7599 | + display_debug_str, &do_debug_str, FALSE }, | |
7600 | + { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7601 | + display_debug_loc, &do_debug_loc, TRUE }, | |
7602 | + { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7603 | + display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
7604 | + { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7605 | + display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
7606 | + { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7607 | + display_debug_ranges, &do_debug_ranges, TRUE }, | |
7608 | + { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7609 | + display_debug_not_supported, NULL, FALSE }, | |
7610 | + { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7611 | + display_debug_not_supported, NULL, FALSE }, | |
7612 | + { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL }, | |
7613 | + display_debug_types, &do_debug_info, TRUE }, | |
7614 | + { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7615 | + display_debug_not_supported, NULL, FALSE }, | |
7616 | + { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7617 | + display_gdb_index, &do_gdb_index, FALSE }, | |
7618 | + { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL, 0, NULL }, | |
7619 | + display_trace_info, &do_trace_info, TRUE }, | |
7620 | + { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7621 | + display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
7622 | + { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7623 | + display_debug_aranges, &do_trace_aranges, FALSE }, | |
7624 | + { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL }, | |
7625 | + display_debug_info, &do_debug_info, TRUE }, | |
7626 | + { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7627 | + display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
7628 | + { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL }, | |
7629 | + display_debug_types, &do_debug_info, TRUE }, | |
7630 | + { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7631 | + display_debug_lines, &do_debug_lines, TRUE }, | |
7632 | + { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7633 | + display_debug_loc, &do_debug_loc, TRUE }, | |
7634 | + { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7635 | + display_debug_macro, &do_debug_macinfo, TRUE }, | |
7636 | + { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7637 | + display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
7638 | + { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7639 | + display_debug_str, &do_debug_str, TRUE }, | |
7640 | + { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7641 | + display_debug_str_offsets, NULL, FALSE }, | |
7642 | + { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7643 | + display_debug_str_offsets, NULL, FALSE }, | |
7644 | + { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7645 | + display_debug_addr, &do_debug_addr, TRUE }, | |
7646 | + { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7647 | + display_cu_index, &do_debug_cu_index, FALSE }, | |
7648 | + { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL }, | |
7649 | + display_cu_index, &do_debug_cu_index, FALSE }, | |
7636 | 7650 | }; |
@@ -124,6 +124,11 @@ struct dwarf_section | ||
124 | 124 | dwarf_vma address; |
125 | 125 | dwarf_size_type size; |
126 | 126 | enum dwarf_section_display_enum abbrev_sec; |
127 | + | |
128 | + /* Used by clients to help them implement the reloc_at callback. */ | |
129 | + void * reloc_info; | |
130 | + unsigned long num_relocs; | |
131 | + | |
127 | 132 | /* A spare field for random use. */ |
128 | 133 | void *user_data; |
129 | 134 | }; |
@@ -135,7 +140,7 @@ struct dwarf_section_display | ||
135 | 140 | struct dwarf_section section; |
136 | 141 | int (*display) (struct dwarf_section *, void *); |
137 | 142 | int *enabled; |
138 | - unsigned int relocate : 1; | |
143 | + bfd_boolean relocate; | |
139 | 144 | }; |
140 | 145 | |
141 | 146 | extern struct dwarf_section_display debug_displays []; |
@@ -217,3 +222,8 @@ extern void * xcmalloc (size_t, size_t); | ||
217 | 222 | extern void * xcrealloc (void *, size_t, size_t); |
218 | 223 | |
219 | 224 | extern dwarf_vma read_leb128 (unsigned char *, unsigned int *, bfd_boolean, const unsigned char * const); |
225 | + | |
226 | +/* A callback into the client. Retuns TRUE if there is a | |
227 | + relocation against the given debug section at the given | |
228 | + offset. */ | |
229 | +extern bfd_boolean reloc_at (struct dwarf_section *, dwarf_vma); |
@@ -2278,6 +2278,8 @@ load_specific_debug_section (enum dwarf_section_display_enum debug, | ||
2278 | 2278 | if (section->start != NULL) |
2279 | 2279 | return 1; |
2280 | 2280 | |
2281 | + section->reloc_info = NULL; | |
2282 | + section->num_relocs = 0; | |
2281 | 2283 | section->address = bfd_get_section_vma (abfd, sec); |
2282 | 2284 | section->size = bfd_get_section_size (sec); |
2283 | 2285 | section->start = NULL; |
@@ -2308,11 +2310,49 @@ load_specific_debug_section (enum dwarf_section_display_enum debug, | ||
2308 | 2310 | section->name); |
2309 | 2311 | return 0; |
2310 | 2312 | } |
2311 | - } | |
2313 | + | |
2314 | + long reloc_size; | |
2315 | + | |
2316 | + reloc_size = bfd_get_reloc_upper_bound (abfd, sec); | |
2317 | + if (reloc_size > 0) | |
2318 | + { | |
2319 | + unsigned long reloc_count; | |
2320 | + arelent **relocs; | |
2321 | + | |
2322 | + relocs = (arelent **) xmalloc (reloc_size); | |
2323 | + | |
2324 | + reloc_count = bfd_canonicalize_reloc (abfd, sec, relocs, NULL); | |
2325 | + if (reloc_count == 0) | |
2326 | + free (relocs); | |
2327 | + else | |
2328 | + { | |
2329 | + section->reloc_info = relocs; | |
2330 | + section->num_relocs = reloc_count; | |
2331 | + } | |
2332 | + } | |
2333 | + } | |
2312 | 2334 | |
2313 | 2335 | return 1; |
2314 | 2336 | } |
2315 | 2337 | |
2338 | +bfd_boolean | |
2339 | +reloc_at (struct dwarf_section * dsec, dwarf_vma offset) | |
2340 | +{ | |
2341 | + arelent ** relocs; | |
2342 | + arelent * rp; | |
2343 | + | |
2344 | + if (dsec == NULL || dsec->reloc_info == NULL) | |
2345 | + return FALSE; | |
2346 | + | |
2347 | + relocs = (arelent **) dsec->reloc_info; | |
2348 | + | |
2349 | + for (; (rp = * relocs) != NULL; ++ relocs) | |
2350 | + if (rp->address == offset) | |
2351 | + return TRUE; | |
2352 | + | |
2353 | + return FALSE; | |
2354 | +} | |
2355 | + | |
2316 | 2356 | int |
2317 | 2357 | load_debug_section (enum dwarf_section_display_enum debug, void *file) |
2318 | 2358 | { |
@@ -11302,7 +11302,8 @@ is_32bit_abs_reloc (unsigned int reloc_type) | ||
11302 | 11302 | case EM_H8_300H: |
11303 | 11303 | return reloc_type == 1; /* R_H8_DIR32. */ |
11304 | 11304 | case EM_IA_64: |
11305 | - return reloc_type == 0x65; /* R_IA64_SECREL32LSB. */ | |
11305 | + return reloc_type == 0x65 /* R_IA64_SECREL32LSB. */ | |
11306 | + || reloc_type == 0x25; /* R_IA64_DIR32LSB. */ | |
11306 | 11307 | case EM_IP2K_OLD: |
11307 | 11308 | case EM_IP2K: |
11308 | 11309 | return reloc_type == 2; /* R_IP2K_32. */ |
@@ -11696,19 +11697,51 @@ is_none_reloc (unsigned int reloc_type) | ||
11696 | 11697 | return FALSE; |
11697 | 11698 | } |
11698 | 11699 | |
11700 | +/* Returns TRUE if there is a relocation against | |
11701 | + section NAME at OFFSET bytes. */ | |
11702 | + | |
11703 | +bfd_boolean | |
11704 | +reloc_at (struct dwarf_section * dsec, dwarf_vma offset) | |
11705 | +{ | |
11706 | + Elf_Internal_Rela * relocs; | |
11707 | + Elf_Internal_Rela * rp; | |
11708 | + | |
11709 | + if (dsec == NULL || dsec->reloc_info == NULL) | |
11710 | + return FALSE; | |
11711 | + | |
11712 | + relocs = (Elf_Internal_Rela *) dsec->reloc_info; | |
11713 | + | |
11714 | + for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp) | |
11715 | + if (rp->r_offset == offset) | |
11716 | + return TRUE; | |
11717 | + | |
11718 | + return FALSE; | |
11719 | +} | |
11720 | + | |
11699 | 11721 | /* Apply relocations to a section. |
11700 | 11722 | Note: So far support has been added only for those relocations |
11701 | 11723 | which can be found in debug sections. |
11724 | + If RELOCS_RETURN is non-NULL then returns in it a pointer to the | |
11725 | + loaded relocs. It is then the caller's responsibility to free them. | |
11702 | 11726 | FIXME: Add support for more relocations ? */ |
11703 | 11727 | |
11704 | 11728 | static void |
11705 | -apply_relocations (void * file, | |
11706 | - const Elf_Internal_Shdr * section, | |
11707 | - unsigned char * start, bfd_size_type size) | |
11729 | +apply_relocations (void * file, | |
11730 | + const Elf_Internal_Shdr * section, | |
11731 | + unsigned char * start, | |
11732 | + bfd_size_type size, | |
11733 | + void ** relocs_return, | |
11734 | + unsigned long * num_relocs_return) | |
11708 | 11735 | { |
11709 | 11736 | Elf_Internal_Shdr * relsec; |
11710 | 11737 | unsigned char * end = start + size; |
11711 | 11738 | |
11739 | + if (relocs_return != NULL) | |
11740 | + { | |
11741 | + * (Elf_Internal_Rela **) relocs_return = NULL; | |
11742 | + * num_relocs_return = 0; | |
11743 | + } | |
11744 | + | |
11712 | 11745 | if (elf_header.e_type != ET_REL) |
11713 | 11746 | return; |
11714 | 11747 |
@@ -11860,7 +11893,15 @@ apply_relocations (void * file, | ||
11860 | 11893 | } |
11861 | 11894 | |
11862 | 11895 | free (symtab); |
11863 | - free (relocs); | |
11896 | + | |
11897 | + if (relocs_return) | |
11898 | + { | |
11899 | + * (Elf_Internal_Rela **) relocs_return = relocs; | |
11900 | + * num_relocs_return = num_relocs; | |
11901 | + } | |
11902 | + else | |
11903 | + free (relocs); | |
11904 | + | |
11864 | 11905 | break; |
11865 | 11906 | } |
11866 | 11907 | } |
@@ -11999,7 +12040,7 @@ dump_section_as_bytes (Elf_Internal_Shdr * section, | ||
11999 | 12040 | |
12000 | 12041 | if (relocate) |
12001 | 12042 | { |
12002 | - apply_relocations (file, section, start, section->sh_size); | |
12043 | + apply_relocations (file, section, start, section->sh_size, NULL, NULL); | |
12003 | 12044 | } |
12004 | 12045 | else |
12005 | 12046 | { |
@@ -12194,7 +12235,13 @@ load_specific_debug_section (enum dwarf_section_display_enum debug, | ||
12194 | 12235 | return 0; |
12195 | 12236 | |
12196 | 12237 | if (debug_displays [debug].relocate) |
12197 | - apply_relocations ((FILE *) file, sec, section->start, section->size); | |
12238 | + apply_relocations ((FILE *) file, sec, section->start, section->size, | |
12239 | + & section->reloc_info, & section->num_relocs); | |
12240 | + else | |
12241 | + { | |
12242 | + section->reloc_info = NULL; | |
12243 | + section->num_relocs = 0; | |
12244 | + } | |
12198 | 12245 | |
12199 | 12246 | return 1; |
12200 | 12247 | } |
@@ -4,6 +4,13 @@ | ||
4 | 4 | with "$OBJDUMP -W". |
5 | 5 | * binutils-all/libdw2-compressedgabi.out: Updated. |
6 | 6 | |
7 | +2015-05-15 Nick Clifton <nickc@redhat.com> | |
8 | + | |
9 | + PR binutils/18374 | |
10 | + * binutils-all/pr18374.s: New test file. | |
11 | + * binutils-all/readelf.exp: Assemble and run the new test. | |
12 | + * binutils-all/readelf.pr18374: Expected output from readelf. | |
13 | + | |
7 | 14 | 2015-05-12 H.J. Lu <hongjiu.lu@intel.com> |
8 | 15 | |
9 | 16 | * binutils-all/elfedit-1.d: Also skip x86_64-*-nacl*. |
@@ -0,0 +1,234 @@ | ||
1 | + .section .debug_info,"",%progbits | |
2 | + .4byte 0x77 | |
3 | + .2byte 0x4 | |
4 | + .4byte .Ldebug_abbrev0 | |
5 | + .byte 0x4 | |
6 | + .uleb128 0x1 | |
7 | + .4byte .LASF3 | |
8 | + .byte 0xc | |
9 | + .ascii "x.c\000" | |
10 | + .4byte .LASF4 | |
11 | + .4byte .Ltext0 | |
12 | + .4byte .Letext0 | |
13 | + .4byte .Ldebug_line0 | |
14 | + .uleb128 0x2 | |
15 | + .ascii "foo\000" | |
16 | + .byte 0x1 | |
17 | + .byte 0x2 | |
18 | + .4byte .LFB0 | |
19 | + .4byte .LFE0 | |
20 | + .uleb128 0x1 | |
21 | + .byte 0x9c | |
22 | + .4byte 0x64 | |
23 | + .uleb128 0x3 | |
24 | + .ascii "b\000" | |
25 | + .byte 0x1 | |
26 | + .byte 0x2 | |
27 | + .4byte 0x64 | |
28 | + .4byte .LLST0 | |
29 | + .uleb128 0x4 | |
30 | + .4byte .LASF0 | |
31 | + .byte 0x1 | |
32 | + .byte 0x2 | |
33 | + .4byte 0x66 | |
34 | + .4byte .LLST1 | |
35 | + .uleb128 0x5 | |
36 | + .ascii "ptr\000" | |
37 | + .byte 0x1 | |
38 | + .byte 0x4 | |
39 | + .4byte 0x6d | |
40 | + .uleb128 0x1 | |
41 | + .byte 0x50 | |
42 | + .byte 0 | |
43 | + .uleb128 0x6 | |
44 | + .byte 0x4 | |
45 | + .uleb128 0x7 | |
46 | + .byte 0x4 | |
47 | + .byte 0x7 | |
48 | + .4byte .LASF1 | |
49 | + .uleb128 0x8 | |
50 | + .byte 0x4 | |
51 | + .4byte 0x73 | |
52 | + .uleb128 0x7 | |
53 | + .byte 0x1 | |
54 | + .byte 0x8 | |
55 | + .4byte .LASF2 | |
56 | + .byte 0 | |
57 | + | |
58 | + .section .debug_abbrev,"",%progbits | |
59 | +.Ldebug_abbrev0: | |
60 | + .uleb128 0x1 | |
61 | + .uleb128 0x11 | |
62 | + .byte 0x1 | |
63 | + .uleb128 0x25 | |
64 | + .uleb128 0xe | |
65 | + .uleb128 0x13 | |
66 | + .uleb128 0xb | |
67 | + .uleb128 0x3 | |
68 | + .uleb128 0x8 | |
69 | + .uleb128 0x1b | |
70 | + .uleb128 0xe | |
71 | + .uleb128 0x11 | |
72 | + .uleb128 0x1 | |
73 | + .uleb128 0x12 | |
74 | + .uleb128 0x6 | |
75 | + .uleb128 0x10 | |
76 | + .uleb128 0x17 | |
77 | + .byte 0 | |
78 | + .byte 0 | |
79 | + .uleb128 0x2 | |
80 | + .uleb128 0x2e | |
81 | + .byte 0x1 | |
82 | + .uleb128 0x3f | |
83 | + .uleb128 0x19 | |
84 | + .uleb128 0x3 | |
85 | + .uleb128 0x8 | |
86 | + .uleb128 0x3a | |
87 | + .uleb128 0xb | |
88 | + .uleb128 0x3b | |
89 | + .uleb128 0xb | |
90 | + .uleb128 0x27 | |
91 | + .uleb128 0x19 | |
92 | + .uleb128 0x11 | |
93 | + .uleb128 0x1 | |
94 | + .uleb128 0x12 | |
95 | + .uleb128 0x6 | |
96 | + .uleb128 0x40 | |
97 | + .uleb128 0x18 | |
98 | + .uleb128 0x2117 | |
99 | + .uleb128 0x19 | |
100 | + .uleb128 0x1 | |
101 | + .uleb128 0x13 | |
102 | + .byte 0 | |
103 | + .byte 0 | |
104 | + .uleb128 0x3 | |
105 | + .uleb128 0x5 | |
106 | + .byte 0 | |
107 | + .uleb128 0x3 | |
108 | + .uleb128 0x8 | |
109 | + .uleb128 0x3a | |
110 | + .uleb128 0xb | |
111 | + .uleb128 0x3b | |
112 | + .uleb128 0xb | |
113 | + .uleb128 0x49 | |
114 | + .uleb128 0x13 | |
115 | + .uleb128 0x2 | |
116 | + .uleb128 0x17 | |
117 | + .byte 0 | |
118 | + .byte 0 | |
119 | + .uleb128 0x4 | |
120 | + .uleb128 0x5 | |
121 | + .byte 0 | |
122 | + .uleb128 0x3 | |
123 | + .uleb128 0xe | |
124 | + .uleb128 0x3a | |
125 | + .uleb128 0xb | |
126 | + .uleb128 0x3b | |
127 | + .uleb128 0xb | |
128 | + .uleb128 0x49 | |
129 | + .uleb128 0x13 | |
130 | + .uleb128 0x2 | |
131 | + .uleb128 0x17 | |
132 | + .byte 0 | |
133 | + .byte 0 | |
134 | + .uleb128 0x5 | |
135 | + .uleb128 0x34 | |
136 | + .byte 0 | |
137 | + .uleb128 0x3 | |
138 | + .uleb128 0x8 | |
139 | + .uleb128 0x3a | |
140 | + .uleb128 0xb | |
141 | + .uleb128 0x3b | |
142 | + .uleb128 0xb | |
143 | + .uleb128 0x49 | |
144 | + .uleb128 0x13 | |
145 | + .uleb128 0x2 | |
146 | + .uleb128 0x18 | |
147 | + .byte 0 | |
148 | + .byte 0 | |
149 | + .uleb128 0x6 | |
150 | + .uleb128 0xf | |
151 | + .byte 0 | |
152 | + .uleb128 0xb | |
153 | + .uleb128 0xb | |
154 | + .byte 0 | |
155 | + .byte 0 | |
156 | + .uleb128 0x7 | |
157 | + .uleb128 0x24 | |
158 | + .byte 0 | |
159 | + .uleb128 0xb | |
160 | + .uleb128 0xb | |
161 | + .uleb128 0x3e | |
162 | + .uleb128 0xb | |
163 | + .uleb128 0x3 | |
164 | + .uleb128 0xe | |
165 | + .byte 0 | |
166 | + .byte 0 | |
167 | + .uleb128 0x8 | |
168 | + .uleb128 0xf | |
169 | + .byte 0 | |
170 | + .uleb128 0xb | |
171 | + .uleb128 0xb | |
172 | + .uleb128 0x49 | |
173 | + .uleb128 0x13 | |
174 | + .byte 0 | |
175 | + .byte 0 | |
176 | + .byte 0 | |
177 | + | |
178 | + .section .debug_loc,"",%progbits | |
179 | +.Ldebug_loc0: | |
180 | +.LLST0: | |
181 | + .4byte .LVL0 | |
182 | + .4byte .LVL2 | |
183 | + .2byte 0x1 | |
184 | + .byte 0x50 | |
185 | + .4byte .LVL2 | |
186 | + .4byte .LFE0 | |
187 | + .2byte 0x4 | |
188 | + .byte 0xf3 | |
189 | + .uleb128 0x1 | |
190 | + .byte 0x50 | |
191 | + .byte 0x9f | |
192 | + .4byte 0 | |
193 | + .4byte 0 | |
194 | +.LLST1: | |
195 | + .4byte .LVL0 | |
196 | + .4byte .LVL1 | |
197 | + .2byte 0x1 | |
198 | + .byte 0x51 | |
199 | + .4byte .LVL1 | |
200 | + .4byte .LVL2 | |
201 | + .2byte 0x3 | |
202 | + .byte 0x71 | |
203 | + .sleb128 -1 | |
204 | + .byte 0x9f | |
205 | + .4byte .LVL2 | |
206 | + .4byte .LVL3 | |
207 | + .2byte 0xb | |
208 | + .byte 0x70 | |
209 | + .sleb128 0 | |
210 | + .byte 0x20 | |
211 | + .byte 0xf3 | |
212 | + .uleb128 0x1 | |
213 | + .byte 0x51 | |
214 | + .byte 0x22 | |
215 | + .byte 0x70 | |
216 | + .sleb128 0 | |
217 | + .byte 0x22 | |
218 | + .byte 0x9f | |
219 | + .4byte .LVL3 | |
220 | + .4byte .LFE0 | |
221 | + .2byte 0xb | |
222 | + .byte 0x70 | |
223 | + .sleb128 0 | |
224 | + .byte 0x20 | |
225 | + .byte 0x70 | |
226 | + .sleb128 0 | |
227 | + .byte 0x22 | |
228 | + .byte 0xf3 | |
229 | + .uleb128 0x1 | |
230 | + .byte 0x51 | |
231 | + .byte 0x22 | |
232 | + .byte 0x9f | |
233 | + .4byte 0 | |
234 | + .4byte 0 |
@@ -356,3 +356,19 @@ if ![is_remote host] { | ||
356 | 356 | } |
357 | 357 | |
358 | 358 | readelf_test -n $tempfile readelf.n {} |
359 | + | |
360 | +# PR 18374 - Check that relocations against the .debug_loc section | |
361 | +# do not prevent readelf from displaying all the location lists. | |
362 | +if {![binutils_assemble $srcdir/$subdir/pr18374.s tmpdir/pr18374.o]} then { | |
363 | + perror "could not assemble PR18374 test file" | |
364 | + unresolved "readelf - failed to assemble" | |
365 | + return | |
366 | +} | |
367 | + | |
368 | +if ![is_remote host] { | |
369 | + set tempfile tmpdir/pr18374.o | |
370 | +} else { | |
371 | + set tempfile [remote_download host tmpdir/pr18374.o] | |
372 | +} | |
373 | + | |
374 | +readelf_test --debug-dump=loc $tempfile readelf.pr18374 {} |
@@ -0,0 +1,14 @@ | ||
1 | +Contents of the .*ebug_loc section: | |
2 | + | |
3 | + Warning: This section has relocations - addresses seen here may not be accurate. | |
4 | + | |
5 | + Offset Begin End Expression | |
6 | + 0+0 0+0 0+0 .* | |
7 | + 0000000b 0+0 0+0 .* | |
8 | + 00000019 <End of list> | |
9 | + 00000021 0+0 0+0 .* | |
10 | + 0000002c 0+0 0+0 .* | |
11 | + 00000039 0+0 0+0 .* | |
12 | + 0000004e 0+0 0+0 .* | |
13 | + 00000063 <End of list> | |
14 | +#pass |