public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: Andrew Stubbs <ams@codesourcery.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCH] Debug info read problem
Date: Thu, 12 Mar 2009 16:58:00 -0000	[thread overview]
Message-ID: <20090312165752.GA19086@caradoc.them.org> (raw)
In-Reply-To: <49B91B5F.9030906@codesourcery.com>

On Thu, Mar 12, 2009 at 02:25:35PM +0000, Andrew Stubbs wrote:
> I have been investigating a problem in which I see this message, in  
> addition to "undefined reference to" messages:
>
>> arm-none-eabi-ld: Dwarf Error: Offset (273) greater than or equal to .debug_str size (268).
>
> The problem is that it mis-reads the size of the .debug_str section. This 
> leads to valid offsets appearing out-of-range.
>
> Debugging shows that the section "rawsize" field contains the correct  
> size, but the code prefers the "size" field, which does not.
>
> It's not entirely clear to me why there would be two different sizes for  
> this section - the comments on the fields talk about relaxation and such, 
> but I don't understand how this related to debug info. It does say that, 
> if set, the field contains the original size of the input section on disk. 
> This would appear to be the right thing, in this case.
>
> The attached patch fixes the problem for the test case, but I don't if  
> I'm fixing the symptom, or the root cause.
>
> Note that this code is usually only called for building diagnostic  
> messages from debug info.
>
> OK?

I took a look at bfd_simple_get_relocated_section_contents, which is
providing the buffer.  If the section does not have relocations, it
uses rawsize if set and otherwise size.  If it does have relocations,
it uses just sec->size.  So this patch could lead to us allocating
and relocating only size, but returning rawsize as the buffer size.
This doesn't happen in practice only because .debug_str won't contain
relocated contents.

The description of rawsize does apply - this is an input section with
SEC_MERGE set.  I suspect size is how much this section contributes to
the final executable after discarding duplicate strings.

I chased up a few implementations of
bfd_get_relocated_section_contents, which is how the buffer is filled
in for sections with the SEC_RELOC flag.  It uses rawsize if set too.
So I think your patch is right, but simple.c needs an equivalent fix.

-- 
Daniel Jacobowitz
CodeSourcery

  reply	other threads:[~2009-03-12 16:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-12 14:25 Andrew Stubbs
2009-03-12 16:58 ` Daniel Jacobowitz [this message]
2009-03-16  1:04   ` Alan Modra
2009-03-16  1:15 ` Alan Modra
2009-03-16 12:42   ` Andrew Stubbs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090312165752.GA19086@caradoc.them.org \
    --to=drow@false.org \
    --cc=ams@codesourcery.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).