Linking

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.
Post Reply
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Linking

Post by salil_bhagurkar »

I have a problem with ld (or may be gcc) . I have about 30 files in my kernel. I compile all, then link groups into object files using the '--relocatable' switch of ld. Then at the end i link all the object files of the groups.

e.g.:

ld -T (linkscript) -o image res1.o res2.o

ld --relocatable -o res1.o fdc.o hd.o

ld --relocatable -o res2.o lpt.o ser.o

While linking the whole kernel at the end i get an error from ld that it found multiple definitions of symbol "__environ" which i never declared in any of my files.
It is found in one or two of my source files which are not different than others in any way that could cause such a problem

--So what is the cause of this "__environ"?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

__environ usually points to the string field holding the environment variables... dragged in some unwanted dependencies, perhaps?
Every good solution is obvious once you've found it.
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Post by salil_bhagurkar »

I am unaware of that term 'dependencies'. Do you mean i included some unwanted headers or declared protorypes of functions that do not exist?
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 »

salil_bhagurkar wrote:I am unaware of that term 'dependencies'. Do you mean i included some unwanted headers or declared protorypes of functions that do not exist?
Possibly linking with a library from your development system? could be possibly including a system header.. (Why?.)..

I can't be sure.. :?
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Post by salil_bhagurkar »

I am surely not linking with any system library or including a system header. I thought giving a switch '-ffreestanding' would help (i referred gcc man) but even that made no difference...
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 »

salil_bhagurkar wrote:I am surely not linking with any system library or including a system header. I thought giving a switch '-ffreestanding' would help (i referred gcc man) but even that made no difference...
What are the commands do you use to build your kernel?

:?
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Post by salil_bhagurkar »

All C compilations done with -c
and ld uses -T link.ld -o
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 »

Is your kernel Open Source? maybe someone else can track it down for you.. if not.. manually going through your source with the grep command would be recommended.. :wink:
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
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 »

salil_bhagurkar wrote:All C compilations done with -c
and ld uses -T link.ld -o
Try BareBones in the Wiki for your GCC and LD command lines... I think you'll find that there's more to them then just -c...
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 »

A GCC Cross-Compiler is recommended practice. If your kernel wont link properly, then the barebones might suffer the same problem...
"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 ]
Mikae
Member
Member
Posts: 94
Joined: Sun Jul 30, 2006 1:08 pm

Post by Mikae »

I thought giving a switch '-ffreestanding' would help (i referred gcc man) but even that made no difference...
Try also '-nostdlib' option. May be, it will help.
Post Reply