[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Off-by-one error in ld documentation
From: |
Nick Clifton |
Subject: |
Re: Off-by-one error in ld documentation |
Date: |
Mon, 7 Sep 2015 17:12:04 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 |
Hi Hans-Peter,
extern char start_of_ROM, end_of_ROM, start_of_FLASH;
memcpy (& start_of_FLASH, & start_of_ROM, & end_of_ROM - &
start_of_ROM);
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);
Actually that *is* a nicer way of writing it.
But, I wrote the original example based upon code that a customer had
written (without the ampersand operators) and then complained that it
did not work. The point of the example therefore was to catch the
reader's eye as code that they might write, and then show them how it
really should be written.
I agree however that your way is better, so how does this addition to
the linker manual sit with you ?
Cheers
Nick
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index d20a59f..be1d490 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -3887,6 +3887,19 @@ Then the C source code to perform the copy would be:
@end smallexample
Note the use of the @samp{&} operators. These are correct.
+Alternatively the symbols can be treated as the names of vectors or
+arrays and then the code will again work as expected:
+
address@hidden
address@hidden
+ extern char start_of_ROM[], end_of_ROM[], start_of_FLASH[];
+
+ memcpy (start_of_FLASH, start_of_ROM, end_of_ROM - start_of_ROM);
address@hidden group
address@hidden smallexample
+
+Note how using this method does not require the use of @samp{&}
+operators.
@node SECTIONS
@section SECTIONS Command