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?
Linker Scripts - Tutorial?
Linker Scripts - Tutorial?
Every good solution is obvious once you've found it.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Linker Scripts - Tutorial?
the .gnu* sections are probably gcc-specific ... other sections should be described in the ELF documentation.
Re:Linker Scripts - Tutorial?
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:
.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:
Hm. That's some info but not really satisfying. I guess I have to write that tutorial myself... :-\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.
Every good solution is obvious once you've found it.
Re:Linker Scripts - Tutorial?
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
- Michael