Re: converting function pointers to/from object pointers

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

 



/* Define a symbol to mark the start of the code region we need to copy.
  */
static void clone_region_start (void)
{
}
...
/* Define a symbol to mark the end of the code region we need to copy.
  */
static void clone_region_end (void)
{
}



/* This is the external interface for the flash driver.
  */
void flash_upgrade (chip_t *chip, unsigned short *pos, int cnt,
                     unsigned short *contents)
{
     unsigned short clone[600]; /* 1200 bytes for RAM-copy */

     /* Calculate code length and offsets for functions we need to copy/call
      */
     int code_length = ((char *)clone_region_end) - ((char *)clone_region_start);
     int flash_offset   = ((short *)flash_op)   - ((short *)clone_region_start);
     int read_id_offset = ((short *)read_id_op) - ((short *)clone_region_start);

These computations assume the symbols in the program image will
be emitted in the same order as those in the source file. That's
not a safe assumption since neither the compiler nor the linker
guarantee any particular order of symbols. IIRC, in my last job,
I saw the same assumption break after switching from gcc 4.2 to
4.5 and binutils 2.18 to 2.21.

Martin



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux