Page 1 of 1
linker complains that mcount is not defined...
Posted: Tue Aug 18, 2009 9:57 am
by nicesj
I've got a strange error from the linker,.
Just I added few files to implement more components,. and compiles them,..
but this time, Linker complains that the mcount is not defined,. so it gives up to link objects,...
I can't understand what happens to the linker,.
so I checked the symbol tables of all object files,. then, I found strange symbol "mcount" with UND flag,.
I guess that is used for profiling,. but I didn't use profiling options for compiling codes (gcc, such as -pg, I didn't turn it on).
how can I figure this out?
thanks,.
Re: linker complains that mcount is not defined...
Posted: Tue Aug 18, 2009 10:16 am
by 01000101
Where is mcount declared? Is it a global variable in a single file, or is it in a header, or is it used with the extern keyword, etc... we need more information.
Posting the exact error message also helps.
Re: linker complains that mcount is not defined...
Posted: Tue Aug 18, 2009 2:30 pm
by gravaera
01000101 wrote:
Posting the exact error message also helps.
QFT. Anyway: you need to do some research. Simple, really: This is a hack, and is intended only as a temporary solution until you've gotten to the root of it. From the small google escapade I just undertook, based on what Berkus said, I believe he's right.
However if that doesn't work, go read up the Std C/C++ ABI and find out exectly what features of the language require the compiler to link in that symbol. If you don't need the feature, turn it off. This is the proper solution.
The temporary hack is, (it will work assuming you're not using whatever compiler feature that's being generated) to include a static c style linked variable of the same name as the problematic one and initialize it as type void *, with a value of 0.
Code: Select all
/*From the googling I did, GCC is required to link in this symbol for one reason or another*/
static void *__gnu_mcount_nc = 0;
Re: linker complains that mcount is not defined...
Posted: Tue Aug 18, 2009 6:20 pm
by nicesj
Thanks.
This can be off-topic, What happens with GCC? why it try to insert 'mcount' to the object files?
I didn't use '-pg' option for compiling c sources,.
Why GCC tries to add "mcount" to the object?
and isn't there a way to remove "mcount" from all object files?
only I have to declare the "mcount" to make sure linker works?
Re: linker complains that mcount is not defined...
Posted: Wed Aug 19, 2009 9:15 am
by quok
nicesj wrote:Thanks.
This can be off-topic, What happens with GCC? why it try to insert 'mcount' to the object files?
I didn't use '-pg' option for compiling c sources,.
Why GCC tries to add "mcount" to the object?
and isn't there a way to remove "mcount" from all object files?
only I have to declare the "mcount" to make sure linker works?
Well, what flags did you pass to GCC? And what's the exact linker error you're getting? Show us those and you're much more likely to get proper answers to your questions.
Also, the gcc docs can be quite enlightening.
Re: linker complains that mcount is not defined...
Posted: Thu Aug 20, 2009 6:29 am
by nicesj
Thank you,.
This is the error message of linker.
Code: Select all
make[1]: Leaving directory `/friend_home/sjpark/workspace/public/ncloader/tools'
ncloader
./.output/buddy.o: In function `buddy_init':
src/buddy.c:28: undefined reference to `mcount'
./.output/buddy.o: In function `buddy_alloc_pages':
src/buddy.c:66: undefined reference to `mcount'
./.output/buddy.o: In function `buddy_get_order':
src/buddy.c:12: undefined reference to `mcount'
./.output/buddy.o: In function `buddy_free_pages':
src/buddy.c:147: undefined reference to `mcount'
./.output/dma.o: In function `dma_init':
src/dma.c:9: undefined reference to `mcount'
./.output/fdc.o:src/fdc.c:46: more undefined references to `mcount' follow
I have 2 machine, one for server and the other one for desktop,.
When I compile my kernel on the server, linker complains to me
server has
gcc version is 4.3.1-r1
ld is 2.16.1
and my desktop has gcc 4.3.3, ld 2.19.1
it works fine, its linker did not complains to me,.
So I think, this error may be related with the version of LD.
but It is not the correct answer, so If anyone has exp like this, tell me, to understand why I failed to compile it on my server.
Re: linker complains that mcount is not defined...
Posted: Thu Aug 20, 2009 6:49 am
by 01000101
./.output/buddy.o: In function `buddy_init':
src/buddy.c:28: undefined reference to `mcount'
./.output/buddy.o: In function `buddy_alloc_pages':
src/buddy.c:66: undefined reference to `mcount'
So, what's the code at line 28 and 66 look like? Did you reference 'mcount' without declaring it?
Could you post your link/compile flags? I still have a feeling profiling is being used. Have you tried to clean your build and try again with different flags?
Re: linker complains that mcount is not defined...
Posted: Thu Aug 20, 2009 6:47 pm
by nicesj
Oooooooooops...
I'm so sorry 8 ~ |
The environment variable contains -pg flags, so when I invoke the 'make',
it started compile with "-pg" option.
I have missed the checking environment variable,
thank you for helping me,.