object file linking

Programming, for all ages and all languages.
Post Reply
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

object file linking

Post 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!
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:

Re: object file linking

Post by pcmattman »

Add -fno-common to your compile line.
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

Re: object file linking

Post by FlashBurn »

Thanks that solved my problem!

Is there a place where I can look for what this common section stuff is good?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: object file linking

Post 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.
Every good solution is obvious once you've found it.
MasterLee
Member
Member
Posts: 90
Joined: Fri Mar 13, 2009 8:51 am

Re: object file linking

Post 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;
50₰
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: object file linking

Post 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?
Every good solution is obvious once you've found it.
MasterLee
Member
Member
Posts: 90
Joined: Fri Mar 13, 2009 8:51 am

Re: object file linking

Post by MasterLee »

Yes, but he could then define the symbols in the assembler files of the kernel
50₰
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

Re: object file linking

Post by FlashBurn »

As I´ve written, the option -fno-common solved the problem.
Post Reply