This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
RE: No error for Linker Section Overlapping
- From: "Deepen Mantri" <Deepen dot Mantri at kpitcummins dot com>
- To: "Alan Modra" <amodra at bigpond dot net dot au>
- Cc: <binutils at sources dot redhat dot com>
- Date: Thu, 19 Apr 2007 21:12:23 +0530
- Subject: RE: No error for Linker Section Overlapping
On Wed, 18th April, 2007 13:23:57 +0930 Alan Modra wrote:
> >> But can't we add an additional check, whether the sections having
> >>overlapped VMAs are overlay or not, before changing their LMAs?
> Hmm, we could, by making the OVERLAY keyword affect the section type.
> This should bring back the old behaviour for you but still give most
> of the ease of use improvement for overlays.
Thank you for the patch. Linker now generates an error when the VMAs of
non-overlay sections overlap.
But their are two issues which need to be handled:
1. Error prints the LMA addresses instead of VMA addresses when VMAs of
the sections overlap. This might create confusion.
2. Also the allocation of the LMA address to non-loadable sections
(such as ".bss" section) is not prevented.
I was able to deal with these issues by developing the following patch
which is an addition to your's. I would like to have your comments on
it.
ChangeLog:
2007-04-19 Deepen Mantri <Deepen.Mantri@kpitcummins.com>
bfd/
* bfd-in2.h (struct bfd_section): Add an integer as a flag for
checking whether it's VMA has overlapped or not.
* bfd-in2.h (#define BFD_FAKE_SECTION): Initialise the
the above introduced VMA overlap flag also.
ld/
* ldlang.c (lang_check_section_addresses): Check whether LMA is
overlapping or VMA depending on the value of the vma overlap
flag. For the latter case, print overlapping VMA addresses.
* ldlang.c (lang_size_sections_1): When setting lma, first
detect overlays by os->sectype. If sections are not overlays,
check whether their VMAs are overlapping. If yes, set the
vma overlap
flag of that section. Otherwise if that section is
non-loadable, set lma=vma else keep the same lma to vma relationship
as that of previous section.
Index: bfd/bfd-in2.h
===================================================================
--- binutils-061211_orig/bfd/bfd-in2.h 2006-12-29 12:39:33.000000000
+0530
+++ binutils-061211/bfd/bfd-in2.h 2007-04-19 19:00:15.000000000
+0530
@@ -1474,6 +1474,8 @@ typedef struct bfd_section
struct bfd_link_order *link_order;
struct bfd_section *s;
} map_head, map_tail;
+
+ unsigned int vma_overlap_flag;
} asection;
/* These sections are global, and are managed by BFD. The application
@@ -1632,8 +1634,8 @@ extern asection bfd_ind_section;
/* symbol, symbol_ptr_ptr, */
\
(struct bfd_symbol *) SYM, &SEC.symbol,
\
\
- /* map_head, map_tail */
\
- { NULL }, { NULL }
\
+ /* map_head, map_tail, vma_overlap_flag */
\
+ { NULL }, { NULL }, 0
\
}
void bfd_section_list_clear (bfd *);
===================================================================
Index: ld/ldlang.c
===================================================================
--- binutils-061211_orig/ld/ldlang.c 2006-12-29 12:39:30.000000000
+0530
+++ binutils-061211/ld/ldlang.c 2007-04-19 13:57:51.000000000 +0530
@@ -4159,10 +4160,15 @@ lang_check_section_addresses (void)
s_start = bfd_section_lma (output_bfd, s);
s_end = s_start + TO_ADDR (s->size) - 1;
- /* Look for an overlap. */
- if (s_end >= os_start && s_start <= os_end)
- einfo (_("%X%P: section %s [%V -> %V] overlaps section %s [%V ->
%V]\n"),
+ /* Look for LMA overlap. */
+ if (s_end >= os_start && s_start <= os_end &&
!(s->vma_overlap_flag))
+
+ einfo (_("%X%P: LMA Overlapping: section %s [%V -> %V] overlaps
section %s [%V -> %V]\n"),
s->name, s_start, s_end, os->name, os_start, os_end);
+ /* Look for VMA overlap. */
+ if (s->vma_overlap_flag)
+ einfo (_("%X%P: VMA Overlapping: section %s [%V -> %V]
overlaps section %s [%V -> %V]\n"),
+ s->name, s->vma,(s->vma + s->size), os->name, os->vma,
(os->vma + os->size));
}
free (sections);
@@ -4428,25 +4434,35 @@ lang_size_sections_1
}
else
{
- /* If the current vma overlaps the previous section,
- then set the current lma to that at the end of
- the previous section. The previous section was
- probably an overlay. */
- if ((dot >= last->vma
- && dot < last->vma + last->size)
- || (last->vma >= dot
- && last->vma < dot + os->bfd_section->size))
- lma = last->lma + last->size;
-
- /* Otherwise, keep the same lma to vma relationship
- as the previous section. */
- else
- lma = dot + last->lma - last->vma;
-
- if (os->section_alignment != -1)
- lma = align_power (lma, os->section_alignment);
- os->bfd_section->lma = lma;
- }
+ /* If this is an overlay, set the current lma to
that
+ at the end of the previous section. */
+ if (os->sectype == overlay_section)
+ lma = last->lma + last->size;
+ else
+ {
+ /* Check for the VMA overlapping. If it overlaps
then set
+ the vma_overlap_flag which will help to print
the error */
+ if ((dot >= last->vma && dot < last->vma +
last->size)
+ || (last->vma >= dot && last->vma < dot +
os->bfd_section->size))
+ {
+ os->bfd_section->vma_overlap_flag=1;
+ }
+
+ /* Otherwise, keep the same lma to vma
relationship
+ as the previous section.But do not change
the LMA=VMA
+ relationship for non-loadable sections(like
.bss section)*/
+
+ if(os->bfd_section->flags & SEC_LOAD)
+ lma = dot + last->lma - last->vma;
+ else
+ lma = dot;
+
+ if (os->section_alignment != -1)
+ lma = align_power (lma,
os->section_alignment);
+
+ os->bfd_section->lma = lma;
+ }
+ }
}
os->processed_lma = TRUE;
===================================================================
Regards,
Deepen Mantri
KPIT Cummins InfoSystems Ltd.
Pune, India
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based tool-chains for Renesas' SH, H8, R8C, M16C
and M32C Series. The following site also offers free technical support
to its users. Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU tools were released on February 6, 2007.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~