aboutsummaryrefslogtreecommitdiff
path: root/ld/ldlang.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2016-04-08 17:52:03 +0930
committerAlan Modra <amodra@gmail.com>2016-04-08 23:41:44 +0930
commit136a43b762ce7bc692645cc0d9d50c934f9aa392 (patch)
treedb533380053e2f10f28e97d5209a471bf643c9b7 /ld/ldlang.c
parent065005336492337c92d06e87544646635a5b9566 (diff)
downloadgdb-136a43b762ce7bc692645cc0d9d50c934f9aa392.zip
gdb-136a43b762ce7bc692645cc0d9d50c934f9aa392.tar.gz
gdb-136a43b762ce7bc692645cc0d9d50c934f9aa392.tar.bz2
PR18452, ld allows overlapping sections
PR 18452 * ldlang.c (maybe_overlays): Delete. (lang_size_sections_1): Remove code setting maybe_overlays. (lang_check_section_addresses): Instead detect overlays by exact match of section VMAs here. Fix memory leak.
Diffstat (limited to 'ld/ldlang.c')
-rw-r--r--ld/ldlang.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 5fbea3f..1947efc 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -75,7 +75,6 @@ static lang_statement_list_type **stat_save_ptr = &stat_save[0];
static struct unique_sections *unique_section_list;
static struct asneeded_minfo *asneeded_list_head;
static unsigned int opb_shift = 0;
-static bfd_boolean maybe_overlays = FALSE;
/* Forward declarations. */
static void exp_init_os (etree_type *);
@@ -4742,6 +4741,7 @@ lang_check_section_addresses (void)
bfd_vma p_start = 0;
bfd_vma p_end = 0;
lang_memory_region_type *m;
+ bfd_boolean overlays;
if (bfd_count_sections (link_info.output_bfd) <= 1)
return;
@@ -4763,11 +4763,14 @@ lang_check_section_addresses (void)
}
if (count <= 1)
- return;
+ {
+ free (sections);
+ return;
+ }
qsort (sections, count, sizeof (*sections), sort_sections_by_lma);
- /* First check sections LMAs. There should be no overlap of LMAs on
+ /* First check section LMAs. There should be no overlap of LMAs on
loadable sections, even with overlays. */
for (p = NULL, i = 0; i < count; i++)
{
@@ -4797,11 +4800,28 @@ lang_check_section_addresses (void)
}
}
- /* Now check sections VMAs if no overlays were detected. */
- if (!maybe_overlays)
+ /* If any non-zero size allocated section (excluding tbss) starts at
+ exactly the same VMA as another such section, then we have
+ overlays. Overlays generated by the OVERLAY keyword will have
+ this property. It is possible to intentionally generate overlays
+ that fail this test, but it would be unusual. */
+ qsort (sections, count, sizeof (*sections), sort_sections_by_vma);
+ overlays = FALSE;
+ p_start = sections[0].sec->vma;
+ for (i = 1; i < count; i++)
{
- qsort (sections, count, sizeof (*sections), sort_sections_by_vma);
+ s_start = sections[i].sec->vma;
+ if (p_start == s_start)
+ {
+ overlays = TRUE;
+ break;
+ }
+ p_start = s_start;
+ }
+ /* Now check section VMAs if no overlays were detected. */
+ if (!overlays)
+ {
for (p = NULL, i = 0; i < count; i++)
{
s = sections[i].sec;
@@ -4835,7 +4855,6 @@ lang_check_section_addresses (void)
if (m->had_full_message)
einfo (_("%X%P: region `%s' overflowed by %ld bytes\n"),
m->name_list.name, (long)(m->current - (m->origin + m->length)));
-
}
/* Make sure the new address is within the region. We explicitly permit the
@@ -5149,18 +5168,6 @@ lang_size_sections_1
if (bfd_is_abs_section (os->bfd_section) || os->ignored)
break;
- if (r->last_os != NULL
- && !IGNORE_SECTION (os->bfd_section)
- && os->bfd_section->size != 0)
- {
- asection *last;
-
- last = r->last_os->output_section_statement.bfd_section;
- if (dot + TO_ADDR (os->bfd_section->size) > last->vma
- && dot < last->vma + TO_ADDR (last->size))
- maybe_overlays = TRUE;
- }
-
/* Keep track of normal sections using the default
lma region. We use this to set the lma for
following sections. Overlays or other linker