+
+ /* Copy fde_table to obstack: it is needed at runtime. */
+ fde_table2 = XOBNEW (&objfile->objfile_obstack, struct dwarf2_fde_table);
+
+ if (fde_table.num_entries == 0)
+ {
+ fde_table2->entries = NULL;
+ fde_table2->num_entries = 0;
+ }
+ else
+ {
+ struct dwarf2_fde *fde_prev = NULL;
+ struct dwarf2_fde *first_non_zero_fde = NULL;
+ int i;
+
+ /* Prepare FDE table for lookups. */
+ std::sort (fde_table.entries, fde_table.entries + fde_table.num_entries,
+ fde_is_less_than);
+
+ /* Check for leftovers from --gc-sections. The GNU linker sets
+ the relevant symbols to zero, but doesn't zero the FDE *end*
+ ranges because there's no relocation there. It's (offset,
+ length), not (start, end). On targets where address zero is
+ just another valid address this can be a problem, since the
+ FDEs appear to be non-empty in the output --- we could pick
+ out the wrong FDE. To work around this, when overlaps are
+ detected, we prefer FDEs that do not start at zero.
+
+ Start by finding the first FDE with non-zero start. Below
+ we'll discard all FDEs that start at zero and overlap this
+ one. */
+ for (i = 0; i < fde_table.num_entries; i++)
+ {
+ struct dwarf2_fde *fde = fde_table.entries[i];
+
+ if (fde->initial_location != 0)
+ {
+ first_non_zero_fde = fde;
+ break;
+ }
+ }
+
+ /* Since we'll be doing bsearch, squeeze out identical (except
+ for eh_frame_p) fde entries so bsearch result is predictable.
+ Also discard leftovers from --gc-sections. */
+ fde_table2->num_entries = 0;
+ for (i = 0; i < fde_table.num_entries; i++)
+ {
+ struct dwarf2_fde *fde = fde_table.entries[i];
+
+ if (fde->initial_location == 0
+ && first_non_zero_fde != NULL
+ && (first_non_zero_fde->initial_location
+ < fde->initial_location + fde->address_range))
+ continue;
+
+ if (fde_prev != NULL
+ && fde_prev->initial_location == fde->initial_location)
+ continue;
+
+ obstack_grow (&objfile->objfile_obstack, &fde_table.entries[i],
+ sizeof (fde_table.entries[0]));
+ ++fde_table2->num_entries;
+ fde_prev = fde;
+ }
+ fde_table2->entries
+ = (struct dwarf2_fde **) obstack_finish (&objfile->objfile_obstack);
+
+ /* Discard the original fde_table. */
+ xfree (fde_table.entries);
+ }
+
+ dwarf2_frame_objfile_data.set (objfile, fde_table2);