Page 1 of 1

object file linking

Posted: Mon May 18, 2009 7:47 am
by FlashBurn
I link my source files with the option -i so that I can link "modules" in my loader to a kernel executable.

My problem is now that I have variables which I define as a global variable (outside from any function) and this variables use the section "COMMON" and I don´t know how to handle such variables. I would like to have that all symbols (functions and objects) are defined in relative to a section. The same problem applies to variables I define global and want to use in another source file, but in scope of the same module.

I hope you get the point.

sample code:

Code: Select all

uint32t foo;

void bar() {
 ...
}
If you compile this code and link it with "-i" and then do an "objdump -x file" the section to which "foo" applies is *COM* and this is my problem, better would be if it would be apply to .data or .bss!

Re: object file linking

Posted: Mon May 18, 2009 7:55 am
by pcmattman
Add -fno-common to your compile line.

Re: object file linking

Posted: Mon May 18, 2009 8:58 am
by FlashBurn
Thanks that solved my problem!

Is there a place where I can look for what this common section stuff is good?

Re: object file linking

Posted: Tue May 19, 2009 4:01 am
by Solar
The ld manual is spattered with references to COMMON, but doesn't give a detailed explanation.

There are two postings I found that, on first quick glance, seem to be very insightful:

How do linkers work and How a linker works (continued). I didn't check whether there are more parts to this.

Re: object file linking

Posted: Tue May 19, 2009 7:31 am
by MasterLee
FlashBurn wrote:

Code: Select all

uint32t foo;
It could be better to add extern before the definition:

Code: Select all

extern uint32t foo;

Re: object file linking

Posted: Tue May 19, 2009 9:30 am
by Solar
MasterLee wrote:
FlashBurn wrote:

Code: Select all

uint32t foo;
It could be better to add extern before the definition:

Code: Select all

extern uint32t foo;
Then it wouldn't be a definition anymore, would it?

Re: object file linking

Posted: Tue May 19, 2009 2:42 pm
by MasterLee
Yes, but he could then define the symbols in the assembler files of the kernel

Re: object file linking

Posted: Tue May 19, 2009 3:18 pm
by FlashBurn
As I´ve written, the option -fno-common solved the problem.