• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisiond1c4b12b9d48d9266b78e2c22d70aa25830b9f8f (tree)
Time2015-05-15 19:24:33
AuthorNick Clifton <nickc@redh...>
CommiterNick Clifton

Log Message

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.

Change Summary

Incremental Difference

--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -8,6 +8,30 @@
88 uncompressed size. Don't check the zlib header.
99 (load_specific_debug_section): Updated.
1010
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+
1135 2015-05-13 H.J. Lu <hongjiu.lu@intel.com>
1236
1337 * elfedit.c (elf_class): Return ELF_CLASS_BOTH by default.
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -4367,6 +4367,8 @@ display_loc_list (struct dwarf_section *section,
43674367
43684368 while (1)
43694369 {
4370+ unsigned long off = offset + (start - *start_ptr);
4371+
43704372 if (start + 2 * pointer_size > section_end)
43714373 {
43724374 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
@@ -4374,7 +4376,7 @@ display_loc_list (struct dwarf_section *section,
43744376 break;
43754377 }
43764378
4377- printf (" %8.8lx ", offset + (start - *start_ptr));
4379+ printf (" %8.8lx ", off);
43784380
43794381 /* Note: we use sign extension here in order to be sure that we can detect
43804382 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,
43854387
43864388 if (begin == 0 && end == 0)
43874389 {
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+ }
43904402 }
43914403
43924404 /* Check base address specifiers. */
@@ -4607,7 +4619,6 @@ display_debug_loc (struct dwarf_section *section, void *file)
46074619 unsigned int first = 0;
46084620 unsigned int i;
46094621 unsigned int j;
4610- unsigned int k;
46114622 int seen_first_offset = 0;
46124623 int locs_sorted = 1;
46134624 unsigned char *next;
@@ -4683,13 +4694,16 @@ display_debug_loc (struct dwarf_section *section, void *file)
46834694 if (!locs_sorted)
46844695 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
46854696 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"));
46874700
46884701 seen_first_offset = 0;
46894702 for (i = first; i < num_debug_info_entries; i++)
46904703 {
46914704 unsigned long offset;
46924705 unsigned long base_address;
4706+ unsigned int k;
46934707 int has_frame_base;
46944708
46954709 if (!locs_sorted)
@@ -7561,76 +7575,76 @@ dwarf_select_sections_all (void)
75617575
75627576 struct dwarf_section_display debug_displays[] =
75637577 {
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 },
76367650 };
--- a/binutils/dwarf.h
+++ b/binutils/dwarf.h
@@ -124,6 +124,11 @@ struct dwarf_section
124124 dwarf_vma address;
125125 dwarf_size_type size;
126126 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+
127132 /* A spare field for random use. */
128133 void *user_data;
129134 };
@@ -135,7 +140,7 @@ struct dwarf_section_display
135140 struct dwarf_section section;
136141 int (*display) (struct dwarf_section *, void *);
137142 int *enabled;
138- unsigned int relocate : 1;
143+ bfd_boolean relocate;
139144 };
140145
141146 extern struct dwarf_section_display debug_displays [];
@@ -217,3 +222,8 @@ extern void * xcmalloc (size_t, size_t);
217222 extern void * xcrealloc (void *, size_t, size_t);
218223
219224 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);
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -2278,6 +2278,8 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
22782278 if (section->start != NULL)
22792279 return 1;
22802280
2281+ section->reloc_info = NULL;
2282+ section->num_relocs = 0;
22812283 section->address = bfd_get_section_vma (abfd, sec);
22822284 section->size = bfd_get_section_size (sec);
22832285 section->start = NULL;
@@ -2308,11 +2310,49 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
23082310 section->name);
23092311 return 0;
23102312 }
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+ }
23122334
23132335 return 1;
23142336 }
23152337
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+
23162356 int
23172357 load_debug_section (enum dwarf_section_display_enum debug, void *file)
23182358 {
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -11302,7 +11302,8 @@ is_32bit_abs_reloc (unsigned int reloc_type)
1130211302 case EM_H8_300H:
1130311303 return reloc_type == 1; /* R_H8_DIR32. */
1130411304 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. */
1130611307 case EM_IP2K_OLD:
1130711308 case EM_IP2K:
1130811309 return reloc_type == 2; /* R_IP2K_32. */
@@ -11696,19 +11697,51 @@ is_none_reloc (unsigned int reloc_type)
1169611697 return FALSE;
1169711698 }
1169811699
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+
1169911721 /* Apply relocations to a section.
1170011722 Note: So far support has been added only for those relocations
1170111723 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.
1170211726 FIXME: Add support for more relocations ? */
1170311727
1170411728 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)
1170811735 {
1170911736 Elf_Internal_Shdr * relsec;
1171011737 unsigned char * end = start + size;
1171111738
11739+ if (relocs_return != NULL)
11740+ {
11741+ * (Elf_Internal_Rela **) relocs_return = NULL;
11742+ * num_relocs_return = 0;
11743+ }
11744+
1171211745 if (elf_header.e_type != ET_REL)
1171311746 return;
1171411747
@@ -11860,7 +11893,15 @@ apply_relocations (void * file,
1186011893 }
1186111894
1186211895 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+
1186411905 break;
1186511906 }
1186611907 }
@@ -11999,7 +12040,7 @@ dump_section_as_bytes (Elf_Internal_Shdr * section,
1199912040
1200012041 if (relocate)
1200112042 {
12002- apply_relocations (file, section, start, section->sh_size);
12043+ apply_relocations (file, section, start, section->sh_size, NULL, NULL);
1200312044 }
1200412045 else
1200512046 {
@@ -12194,7 +12235,13 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
1219412235 return 0;
1219512236
1219612237 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+ }
1219812245
1219912246 return 1;
1220012247 }
--- a/binutils/testsuite/ChangeLog
+++ b/binutils/testsuite/ChangeLog
@@ -4,6 +4,13 @@
44 with "$OBJDUMP -W".
55 * binutils-all/libdw2-compressedgabi.out: Updated.
66
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+
714 2015-05-12 H.J. Lu <hongjiu.lu@intel.com>
815
916 * binutils-all/elfedit-1.d: Also skip x86_64-*-nacl*.
--- /dev/null
+++ b/binutils/testsuite/binutils-all/pr18374.s
@@ -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
--- a/binutils/testsuite/binutils-all/readelf.exp
+++ b/binutils/testsuite/binutils-all/readelf.exp
@@ -356,3 +356,19 @@ if ![is_remote host] {
356356 }
357357
358358 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 {}
--- /dev/null
+++ b/binutils/testsuite/binutils-all/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