_memcpy

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
hElPnEeded

_memcpy

Post by hElPnEeded »

Today I changed some stuff in my OS, so that an ASM-handler calls a C handler and pushes some arguments. I know the code is working (cause the error only occured when I changed this for lots of functions). I get this error:

Exceptions.o(.text+0x15a):Exceptions.c: undefined reference to `_memcpy'

I?ve had trouble with this before and I?ve forgotten how to get around this. Must be something with the linker..
hElPnEeded

Re:_memcpy

Post by hElPnEeded »

and, I do NOT use any memcpy function in my code or something like that
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:_memcpy

Post by df »

is it a gcc builtin function? did you disable builtins?
-- Stu --
hElPnEeded

Re:_memcpy

Post by hElPnEeded »

nope, how do I do that?
but I dont use it in my code..
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:_memcpy

Post by Solar »

--no-builtin.
Every good solution is obvious once you've found it.
hElPnEeded

Re:_memcpy

Post by hElPnEeded »

How? Like this
gcc -c System.c -o System.o

Should I replace that with

gcc -c --no-builtin System.c -o System.o
Therx

Re:_memcpy

Post by Therx »

yes. my compile line is:-

gcc -c -O2 -fno-builtin -Wall -W -nostdinc -Iinclude -o file.c

Pete
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:_memcpy

Post by Neo »

if you haven't figured it out by now, yeah thats about it
you could also use

Code: Select all

 -ffreestanding -fno-builtin
the freestanding being another option.
Only Human
hElPnEeded

Re:_memcpy

Post by hElPnEeded »

I dont get it, why does the linker try to use memcpy (when my code doesnt?). really need help with this (cant run/modify my OS right now)
hElPnEeded

Re:_memcpy

Post by hElPnEeded »

it doesnt work.. I use this now:
gcc -c -ffreestanding -fno-builtin Exceptions.c -o Exceptions.o
but no, same error (I use the -ffrestanding / fnobultin for all files I compile)
hElPnEeded

Re:_memcpy

Post by hElPnEeded »

can tell you something more.. my exceptionhandlers(called from the asm-written ISR) looks like this:

void int_00(exception_descriptor status)
{
   panic("Divide By Zero Error", status);
}

void int_01(exception_descriptor status)
{
   panic("Debug Error", status);
}
...
when I remove the panic (..) lines (panic is a function in the same file), I dont get the memcpy error..
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:_memcpy

Post by Neo »

i guess we'll need to have a look at the code to help.
Only Human
Therx

Re:_memcpy

Post by Therx »

When I remove the panic (..) lines (panic is a function in the same file), I dont get the memcpy error..
Ah. Maybe GCC is trying to use memcpy to pass one of the arguments. If the "exception_descriptor" structure is too big maybe GCC has decided it won't fit on the stack? What is the code for panic()?

Pete
hElPnEeded

Re:_memcpy

Post by hElPnEeded »

The code for the panic:

Code: Select all

void panic(char *message, char *code, exceptions_descriptor status)
{
   printf("\nAn Exception has occured\n%s at EIP=%i\n", WHITE_TXT, 2, message, status.eip);
   printf("eax=%i  ebx=%i  ecx=%i  edx=%i  esi=%i  edi=%i  ebp=%i  esp=%i\n", WHITE_TXT, 8, status.regs[0],status.regs[1],status.regs[2],status.regs[3],status.regs[4], status.regs[5], status.regs[6], status.regs[7]);
   printf("Error Code=%i\ncs register=%i\n", WHITE_TXT, 1, status.errcode, status.cs);
   print("System halted\n", RED_TXT);
   enableInt(false);
   asm("hlt");
}
The code for the struct

Code: Select all

struct exception_descriptor{
    unsigned long gs, fs, es, ds;
    unsigned long regs[8]; // eax, ecx, edx, ebx and friends.
    unsigned long errcode;
    unsigned long eip;
    unsigned long cs;
    unsigned long eflags;
}__attribute__ ((packed));
typedef struct exception_descriptor exception_descriptor;

so the struct is 64 bytes..
bkilgore

Re:_memcpy

Post by bkilgore »

Why not just pass it by pointer instead of copy? If that doesn't fix it, attach your exceptions.c file so we can take a look.
Post Reply