public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Error while using Linker Relaxation
@ 2011-12-08 11:13 Kaushik, Praveen_Kumar
  2011-12-08 22:15 ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: Kaushik, Praveen_Kumar @ 2011-12-08 11:13 UTC (permalink / raw)
  To: binutils; +Cc: Kaushik, Praveen_Kumar


Hi,
    I am facing an issue while using linker relaxation feature in
binutils-2.22.
The testcase works fine with binutils-2.20.1.
 
As a newbie I don't know much what is going wrong but I dig up the issue
and 
found buffer allocated in bfd_get_full_section_contents function in
bfd/compress.c
is overflowed and hence the error is generated (because some other value
is being overwritten).


I see the following difference in the length of the buffer allocated
across the two versions
of binutils.

This is a code snippet in binutils-2.20.1/bfd/section.c

bfd_boolean
bfd_malloc_and_get_section (bfd *abfd, sec_ptr sec, bfd_byte **buf)
{
  ....

  p = (bfd_byte *)

      <<<<<the buffer length here is greater of size and rawsize >>>>
      
       bfd_malloc (sec->rawsize > sec->size ? sec->rawsize : sec->size);


  if (p == NULL)
    return FALSE;
  *buf = p;

  return bfd_get_section_contents (abfd, sec, p, 0, sz);
}


And this is in binutils-2.22/bfd/compress.c

bfd_boolean
bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr)
{
 ...

if (abfd->direction != write_direction && sec->rawsize != 0)
    sz = sec->rawsize;
  else 
    sz = sec->size;
   ...
  switch (sec->compress_status)
    {
    case COMPRESS_SECTION_NONE:
      if (p == NULL)
        {

       
          <<<<the buffer length here is rawsize(if its not zero), size
otherwise>>>>

          p = (bfd_byte *) bfd_malloc (sz);

          if (p == NULL)
            return FALSE;
        }
   ....
}

I am using avr32 target. Is this change in the buffer length correct?
 
Thanks in advance
Praveen Kaushik


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Error while using Linker Relaxation
  2011-12-08 11:13 Error while using Linker Relaxation Kaushik, Praveen_Kumar
@ 2011-12-08 22:15 ` Alan Modra
  2011-12-19  6:16   ` Kaushik, Praveen_Kumar
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2011-12-08 22:15 UTC (permalink / raw)
  To: Kaushik, Praveen_Kumar; +Cc: binutils

On Thu, Dec 08, 2011 at 07:13:19PM +0800, Kaushik, Praveen_Kumar wrote:
> I am using avr32 target. Is this change in the buffer length correct?

I thought so when I made the change, and haven't seen anything to make
me think otherwise.  If you post a small testcase (.s or .o files, not
.c) I'll take a look.  Most likely there is a bug in the avr backend.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Error while using Linker Relaxation
  2011-12-08 22:15 ` Alan Modra
@ 2011-12-19  6:16   ` Kaushik, Praveen_Kumar
  2011-12-27  4:05     ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: Kaushik, Praveen_Kumar @ 2011-12-19  6:16 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils, Kaushik, Praveen_Kumar

Hi Alan,
   Sorry for replying late!
First, I am using AVR32 target not AVR, these two are totally different
ones. The avr32 target is not yet upstreamed. I can send you the patches
if you want.
Second, changing the size allocated back to greater of sec->size and 
sec->rawsize, and building binutils again solves the problem. I have few
.o files I can send that as well if you want.

Thanks and Regards,
Praveen Kaushik



> -----Original Message-----
> From: Alan Modra [mailto:amodra@gmail.com]
> Sent: Friday, December 09, 2011 3:45 AM
> To: Kaushik, Praveen_Kumar
> Cc: binutils@sourceware.org
> Subject: Re: Error while using Linker Relaxation
> 
> On Thu, Dec 08, 2011 at 07:13:19PM +0800, Kaushik, Praveen_Kumar
wrote:
> > I am using avr32 target. Is this change in the buffer length
correct?
> 
> I thought so when I made the change, and haven't seen anything to make
> me think otherwise.  If you post a small testcase (.s or .o files, not
> .c) I'll take a look.  Most likely there is a bug in the avr backend.
> 
> --
> Alan Modra
> Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Error while using Linker Relaxation
  2011-12-19  6:16   ` Kaushik, Praveen_Kumar
@ 2011-12-27  4:05     ` Alan Modra
  2011-12-28  5:15       ` Kaushik, Praveen_Kumar
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2011-12-27  4:05 UTC (permalink / raw)
  To: Kaushik, Praveen_Kumar; +Cc: binutils

On Mon, Dec 19, 2011 at 02:15:42PM +0800, Kaushik, Praveen_Kumar wrote:
> ones. The avr32 target is not yet upstreamed.

In that case it will need updating before it is contributed, to use
rawsize according to the comments in bfd/section.c.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Error while using Linker Relaxation
  2011-12-27  4:05     ` Alan Modra
@ 2011-12-28  5:15       ` Kaushik, Praveen_Kumar
  0 siblings, 0 replies; 5+ messages in thread
From: Kaushik, Praveen_Kumar @ 2011-12-28  5:15 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

Thanks for the reply Alan.

Praveen Kaushik

> -----Original Message-----
> From: Alan Modra [mailto:amodra@gmail.com]
> Sent: Tuesday, December 27, 2011 9:35 AM
> To: Kaushik, Praveen_Kumar
> Cc: binutils@sourceware.org
> Subject: Re: Error while using Linker Relaxation
> 
> On Mon, Dec 19, 2011 at 02:15:42PM +0800, Kaushik, Praveen_Kumar
wrote:
> > ones. The avr32 target is not yet upstreamed.
> 
> In that case it will need updating before it is contributed, to use
> rawsize according to the comments in bfd/section.c.
> 
> --
> Alan Modra
> Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-12-28  5:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-08 11:13 Error while using Linker Relaxation Kaushik, Praveen_Kumar
2011-12-08 22:15 ` Alan Modra
2011-12-19  6:16   ` Kaushik, Praveen_Kumar
2011-12-27  4:05     ` Alan Modra
2011-12-28  5:15       ` Kaushik, Praveen_Kumar

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).