Linker Scripts - Tutorial?

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

Linker Scripts - Tutorial?

Post by Solar »

One thing that gives me a headache are linker scripts.

I mean, of course I've read the ld manual. And there are lots of linker scrpts around on various tutorial webpages and everything.

But... the manual tells me how to do things, and those tutorials tell me what to do, but there's little to no information on the why.

I found stuff like "*.o (.gnu.linkonce.t.*) /*C++ templates? */" in one tutorial which I found nowhere else - and where do I check what .gnu.linkonce.t.* really stands for to do away with the question mark (I hate question marks in comments)?

I found references to ".stab" and ".stabstr" (huh?), some examples link "*.o (COMMON)" while others don't, and yet others write it as "*(.common)". Some scripts call SORT() on .ctors which I found no explanation for, etc. etc. ad absurdum.

Google gives me a plethora of examples, but virtually no explanations. Anybody knowing a source of enlightenment?
Every good solution is obvious once you've found it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Linker Scripts - Tutorial?

Post by Pype.Clicker »

the .gnu* sections are probably gcc-specific ... other sections should be described in the ELF documentation.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Linker Scripts - Tutorial?

Post by Solar »

OK, here's what I found.

.stab and .stabstr refer to the STABS debugger format (http://sources.redhat.com/gdb/onlinedocs/stabs_toc.html).

.ctors and .dtors are of course the array of static / global constructors and destructors.

I found an info about both SORT and COMMON in the ld manual - after using Google instead of ld's manual index, which proves the ld manual index sucks heavily. :-( (Not excusing myself from reading it not thoroughly enough...)

SORT: http://www-es.fernuni-hagen.de/cgi-bin/info2html?(ld)Output%20Section%20Keywords

COMMON: http://www-es.fernuni-hagen.de/cgi-bin/info2html?(ld.info)Input%20Section%20Common

I still came up empty looking for info on .common though.

I found this about .gnu.linkonce.t.* in the gcc internals manual at http://gcc.gnu.org/onlinedocs/gccint/Function-Basics.html#Function%20Basics:
DECL_LINKONCE_P
This macro holds if multiple copies of this function may be emitted in various translation units. It is the responsibility of the linker to merge the various copies. Template instantiations are the most common example of functions for which DECL_LINKONCE_P holds; G++ instantiates needed templates in all translation units which require them, and then relies on the linker to remove duplicate instantiations.
FIXME: This macro is not yet implemented.
Hm. That's some info but not really satisfying. I guess I have to write that tutorial myself... :-\
Every good solution is obvious once you've found it.
VE3MTM

Re:Linker Scripts - Tutorial?

Post by VE3MTM »

I could use a good tutorial on this topic too... My linker script works fine, except that string arrays declared globally (placed in the data segment) are not linked properly. I'm using an overlay to link for a set place in memory, and I think that's where the problem is. I can post the script, if that would help. I'm sure someone's had a similar problem. Any help would be appreciated

- Michael
Post Reply