Function keeps getting embedded into object!

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.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Function keeps getting embedded into object!

Post by pcmattman »

I've hit a problem in my multitasker. The code compiles fine, but in the process of compiling about 3 references to '_memcpy' are added. This would normally be fine, but there's a problem with this: at the moment I'm using C++, which sort of makes life difficult - no name mangling = serious problem!

The code has no reference to memcpy (apart from a header, where it's defined once as a prototype). I'm stumped on this problem... any ideas?

Edit: example of the error:

Code: Select all

mt.o(.text+0xaa):mtask.cc: undefined reference to `_memcpy'
mt.o(.text+0x15e):mtask.cc: undefined reference to `_memcpy'
mt.o(.text+0x18d):mtask.cc: undefined reference to `_memcpy'
Edit 2: Ahhh, it was in this:

Code: Select all

current_task[0] = ptable[pid];
I didn't realize that was memcpy...
grimpy
Posts: 11
Joined: Thu May 03, 2007 11:27 am

Re: Function keeps getting embedded into object!

Post by grimpy »

pcmattman wrote: Edit 2: Ahhh, it was in this:

Code: Select all

current_task[0] = ptable[pid];
I didn't realize that was memcpy...
Seriously, you need to compile your kernel in nostdlib / freestanding mode, so it doesn't emit library calls.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

I do.

The only other problem with this is that for some really strange reason G++ compiles the whole file as a C file. Even when i explicity tell it to use C++, it still uses C (see the _memcpy example in previous post, and I don't need to use 'extern "C"' on symbols in the file). This makes coding really difficult - any ideas?
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

memcpy is a part of the standard C library right? Doesn't that mean that it will always be declared extern "C". That would explain the name mangling that you are getting.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Good point.

Still, the whole file is being treated as a c file, not a c++ file.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Are you sure, how can you tell? Not that I don't believe you but some symptoms might help in diagnosing the problem.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

For a start, I have a structure that is to be accessed from assembly code. It's not defined as extern "C" (I forgot at the time) but there are no problems accessing it as a typical C name, ie. no mangling.

objdump shows this:

Code: Select all

<_ptable>
That's in the BSS section too, when it's defined as a static array?
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

pcmattman wrote:For a start, I have a structure that is to be accessed from assembly code. It's not defined as extern "C" (I forgot at the time) but there are no problems accessing it as a typical C name, ie. no mangling.
Okay well I can't explain that other than to say to look for an unended extern "C" { in some header file somewhere
pcmattman wrote: objdump shows this:

Code: Select all

<_ptable>
That's in the BSS section too, when it's defined as a static array?
It could be in the BSS section if it was either initialized with all zeros or not initialized at all. (IIRC)
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

ptable is defined as

Code: Select all

struct tagTask ptable[1024];
And I don't have an extern "C" in a header...
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

wow thats weird, i don't know what to say about that. Maybe try reinstalling gcc and g++.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

For starters, build a GCC Cross-Compiler instead of using your system gcc.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

I found the source of the problem: large structures...

And when I tried to build a cross-compiler it didn't work (followed the instructions in the wiki for Cygwin)...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

The memcpy() you are seeing is likely not the one from the standard library, but the one built into GCC because the compiler has to copy memory areas itself (like in the case of the object copy you mentioned). It is thus a dependency of the compiler, not of your code.
pcmattman wrote:And when I tried to build a cross-compiler it didn't work (followed the instructions in the wiki for Cygwin)...
"It didn't work" is not a description that could lead to a solution. And while I do offer you to help you with your problem via PM, I would take bets that the instructions are correct (because I have been through this numerous times). 8)
Every good solution is obvious once you've found it.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

"It didn't work" means it didn't work and I don't want to resolve it yet.

Basically, the cross-compiler didn't compile. It spewed errors about multiply defined symbols and such... I'm about to try again and if it doesn't work I'll post here, if it'll make you happy :D

Edit: here's the problem:

Code: Select all

make[4]: Entering directory `/usr/src/build-binutils/binutils'
/bin/sh ./libtool --mode=link gcc -W -Wall -Wstrict-prototypes -Wmissing-prototy
pes -Werror -g -O2   -o ar.exe  arparse.o arlex.o ar.o not-ranlib.o arsup.o rena
me.o binemul.o emul_vanilla.o bucomm.o version.o filemode.o ../bfd/libbfd.la ../
libiberty/libiberty.a
gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror -g -O2 -o ar.exe a
rparse.o arlex.o ar.o not-ranlib.o arsup.o rename.o binemul.o emul_vanilla.o buc
omm.o version.o filemode.o  ../bfd/.libs/libbfd.a ../libiberty/libiberty.a
arlex.o: In function `main':
/usr/src/build-binutils/binutils/arlex.c:1: multiple definition of `_main'
arparse.o:/usr/src/build-binutils/binutils/arparse.c:1: first defined here
ar.o: In function `main':
/usr/src/build-binutils/binutils/../../binutils-20060817-1/binutils/ar.c:337: mu
ltiple definition of `_main'
arparse.o:/usr/src/build-binutils/binutils/arparse.c:1: first defined here
ar.o: In function `mri_emul':
/usr/src/build-binutils/binutils/../../binutils-20060817-1/binutils/ar.c:141: un
defined reference to `_yyparse'
collect2: ld returned 1 exit status
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

You could always try using Google or something, I'm going to make an educated guess and say you're missing "bison" :wink:

Hope that helps...
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
Post Reply