From f4427a75c8c7166f2c9e08ec75115743344c5519 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Sat, 17 Jul 2010 03:12:02 +0000 Subject: * ldlang.c (lang_check_section_addresses): Catch overlap for sections that wrap around the address space. --- ld/ChangeLog | 5 +++++ ld/ldlang.c | 27 ++++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) (limited to 'ld') diff --git a/ld/ChangeLog b/ld/ChangeLog index 864901d..80bcd25 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,8 @@ +2010-07-17 Alan Modra + + * ldlang.c (lang_check_section_addresses): Catch overlap for + sections that wrap around the address space. + 2010-06-29 Nick Clifton * scripttempl/xstormy16.sc (.gcc_except_table): Include sections diff --git a/ld/ldlang.c b/ld/ldlang.c index 5ba4360..9c4e17b 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -4561,13 +4561,13 @@ sort_sections_by_lma (const void *arg1, const void *arg2) static void lang_check_section_addresses (void) { - asection *s, *os; + asection *s, *p; asection **sections, **spp; unsigned int count; bfd_vma s_start; bfd_vma s_end; - bfd_vma os_start; - bfd_vma os_end; + bfd_vma p_start; + bfd_vma p_end; bfd_size_type amt; lang_memory_region_type *m; @@ -4600,24 +4600,29 @@ lang_check_section_addresses (void) spp = sections; s = *spp++; - s_start = bfd_section_lma (link_info.output_bfd, s); + s_start = s->lma; s_end = s_start + TO_ADDR (s->size) - 1; for (count--; count; count--) { /* We must check the sections' LMA addresses not their VMA addresses because overlay sections can have overlapping VMAs but they must have distinct LMAs. */ - os = s; - os_start = s_start; - os_end = s_end; + p = s; + p_start = s_start; + p_end = s_end; s = *spp++; - s_start = bfd_section_lma (link_info.output_bfd, s); + s_start = s->lma; s_end = s_start + TO_ADDR (s->size) - 1; - /* Look for an overlap. */ - if (s_end >= os_start && s_start <= os_end) + /* Look for an overlap. We have sorted sections by lma, so we + know that s_start >= p_start. Besides the obvious case of + overlap when the current section starts before the previous + one ends, we also must have overlap if the previous section + wraps around the address space. */ + if (s_start <= p_end + || p_end < p_start) einfo (_("%X%P: section %s loaded at [%V,%V] overlaps section %s loaded at [%V,%V]\n"), - s->name, s_start, s_end, os->name, os_start, os_end); + s->name, s_start, s_end, p->name, p_start, p_end); } free (sections); -- cgit v1.1