This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

incorrect dereference of implicit memcpy


Hello,

I am working on an x86 embedded system where we do not have ld/libc
onboard. our OS provides basic libc functions and does it's own dynamic
linking for the applications. 

Basic function dereferencing works properly, our problem is with the
implicit function calls that gcc makes for copying structs.

When the application code below gets started our OS finds the 'imex'
structure and correctly fills out the required function pointers so that
calls to the fn's result in the code provided by the os getting called.

Thus the explicit call
  jimbob(815);
translates to 
  push   $0x32f
  call   *0x804912c

  memcpy (dest, src, 20);
translates to 
  push   $0x14
  push   %ebx
  lea    0xffffff61(%ebp),%eax
  push   %eax
  call   *0x8049128

which is also good
BUT the structure copy x=y becomes
  push   $0x16
  push   %eax
  push   %edx
  call   8049128  <- no '*'

which is a direct jump into memory instead of a jump to the dereference
of the memory location. as of that moment the application crashes. below
are our build commands and the program.

Am I doing something wrong here, or do i have incorrect cflags/ldflags?
ie can i get gcc to produce the same derefecenced call as per the
explicit calls?

Thanks in advance for any input
  Charlie  



gcc testjmp.c -c -o testjmp.o -ffreestanding -march=i386 -g -Os
-fno-builtin 
ld testjmp.o -o testjmp -static -nostdlib
objdump testjmp -DSx > testjmp.dis

testjmp.c:

// structure def for our import/export table
typedef struct imex_s {
  char name[16];
  void *ptr;
  } imex_t;

// fixed typedefs for our funcions
typedef int  (*jimbob_t)(int jb);
typedef void (*memcpy_t)(char *d, char *s, int l);

// memory space for the to be linked fn's will be in .bss
jimbob_t jimbob;
memcpy_t memcpy;

// our import table will be in .const
const imex_t imex[] =
 {
   { "jimbob", (void*)&jimbob},
   { "memcpy", (void*)&memcpy}
 };

// test struct for x=y
typedef struct
   {
   char Bytes[22];
   } structure_t;

int main(int argc, char *argv[])
  {
  char dest[100];
  char src[] = {"hello pdts"};
  volatile structure_t X, Y;

  jimbob(815);

  memcpy (dest, src, 20);
  X = Y; /* gcc creates a memcpy here */

  return 0;
  }// main


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]