This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: PR ld/3191: Linker failed to handle DW_FORM_ref_addr properly
On Tue, Sep 19, 2006 at 10:20:10PM -0700, H. J. Lu wrote:
> On Tue, Sep 19, 2006 at 09:37:02PM -0700, H. J. Lu wrote:
> > DW_FORM_ref_addr is offset_size according to DWARF3 and gcc follows
> > DWARF3. This patch fixes
> >
> > http://sourceware.org/bugzilla/show_bug.cgi?id=3191
> >
> >
It turns out that the problem is we didn't properly adjust debug_info
section vmas when we put them together. I think this is a right fix.
H.J.
----
2006-09-19 H.J. Lu <hongjiu.lu@intel.com>
PR ld/3191
* dwarf2.c (_bfd_dwarf2_find_nearest_line): Adjust debug_info
section vma when needed.
--- bfd/dwarf2.c.ref_addr 2006-05-02 03:01:56.000000000 -0700
+++ bfd/dwarf2.c 2006-09-20 15:15:17.000000000 -0700
@@ -2354,6 +2354,9 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd
{
bfd_size_type total_size;
asection *msec;
+ bfd_vma last_vma;
+ bfd_size_type size;
+ asection *first_msec;
*pinfo = stash;
@@ -2368,9 +2371,26 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd
Read them all in and produce one large stash. We do this in two
passes - in the first pass we just accumulate the section sizes.
In the second pass we read in the section's contents. The allows
- us to avoid reallocing the data as we add sections to the stash. */
+ us to avoid reallocing the data as we add sections to the stash.
+
+ We may need to adjust debug_info section vmas since we will
+ concatenate them together. Otherwise relocations may be
+ incorrect. */
+ first_msec = msec;
+ last_vma = 0;
for (total_size = 0; msec; msec = find_debug_info (abfd, msec))
- total_size += msec->size;
+ {
+ size = msec->size;
+ if (size == 0)
+ continue;
+
+ total_size += size;
+
+ BFD_ASSERT (msec->alignment_power == 0);
+
+ msec->vma += last_vma;
+ last_vma += size;
+ }
stash->info_ptr = bfd_alloc (abfd, total_size);
if (stash->info_ptr == NULL)
@@ -2378,7 +2398,7 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd
stash->info_ptr_end = stash->info_ptr;
- for (msec = find_debug_info (abfd, NULL);
+ for (msec = first_msec;
msec;
msec = find_debug_info (abfd, msec))
{
@@ -2398,9 +2418,15 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd
stash->info_ptr_end = stash->info_ptr + start + size;
}
+ /* Restore section vma. */
+ for (msec = first_msec;
+ msec;
+ msec = find_debug_info (abfd, msec))
+ msec->vma = 0;
+
BFD_ASSERT (stash->info_ptr_end == stash->info_ptr + total_size);
- stash->sec = find_debug_info (abfd, NULL);
+ stash->sec = first_msec;
stash->sec_info_ptr = stash->info_ptr;
stash->syms = symbols;
}