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:
+
+@smallexample
+@group
+  extern char start_of_ROM[], end_of_ROM[], start_of_FLASH[];
+
+  memcpy (start_of_FLASH, start_of_ROM, end_of_ROM - start_of_ROM);
+@end group
+@end smallexample
+
+Note how using this method does not require the use of @samp{&}
+operators.

 @node SECTIONS
 @section SECTIONS Command


_______________________________________________
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils

Reply via email to