bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Off-by-one error in ld documentation


From: Hans-Peter Nilsson
Subject: Re: Off-by-one error in ld documentation
Date: Sat, 5 Sep 2015 12:00:44 -0400 (EDT)
User-agent: Alpine 2.02 (BSF 1266 2009-07-14)

On Thu, 3 Sep 2015, Nick Clifton wrote:
> Hi Mark,
>
> > In ld/ld.texinfo, the following example code is offered:
> >
> > >   start_of_ROM   = .ROM;
> > >   end_of_ROM     = .ROM + sizeof (.ROM) - 1;
> > >   start_of_FLASH = .FLASH;
> > >
> > > Then the C source code to perform the copy would be:
> > >
> > >   extern char start_of_ROM, end_of_ROM, start_of_FLASH;
> > >
> > >   memcpy (& start_of_FLASH, & start_of_ROM, & end_of_ROM - &
> > > start_of_ROM);
> >
> > But I think this does not copy the last byte of ROM due to the -1 in
> > the end_of_ROM definition.
>
> Thanks for pointing this out.  I have checked in the obvious fix to the
> documentation.

While we're at that example, is there a reason why it is
pretending that the symbols are for variables whose address is
then taken (to get the proper symbol address instead of the
faked variable values), and that the sections aren't actually
vectors of char (unsigned if you will)?  This would IMHO yield
more intuitive code, where newbies wouldn't be confused by
and/or forget the address operator.  To wit:

extern char start_of_ROM[], end_of_ROM[], start_of_FLASH[];
memcpy (start_of_FLASH, start_of_ROM, end_of_ROM - start_of_ROM);

Maybe it's just my taste of toolshed color...

brgds, H-P



reply via email to

[Prev in Thread] Current Thread [Next in Thread]