Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / mingw / info / stabs / ELF-Linker-Relocation.html
blob797e010d3ae8a5725bbef887ce86f4cf21687f4d
1 <html lang="en">
2 <head>
3 <title>STABS</title>
4 <meta http-equiv="Content-Type" content="text/html">
5 <meta name="description" content="STABS">
6 <meta name="generator" content="makeinfo 4.3">
7 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
8 </head>
9 <body>
10 <div class="node">
11 <p>
12 Node:<a name="ELF%20Linker%20Relocation">ELF Linker Relocation</a>,
13 Previous:<a rel="previous" accesskey="p" href="Stab-Section-Basics.html#Stab%20Section%20Basics">Stab Section Basics</a>,
14 Up:<a rel="up" accesskey="u" href="Stab-Sections.html#Stab%20Sections">Stab Sections</a>
15 <hr><br>
16 </div>
18 <h3 class="appendixsec">Having the Linker Relocate Stabs in ELF</h3>
20 <p>This section describes some Sun hacks for Stabs in ELF; it does not
21 apply to COFF or SOM.
23 <p>To keep linking fast, you don't want the linker to have to relocate very
24 many stabs. Making sure this is done for <code>N_SLINE</code>,
25 <code>N_RBRAC</code>, and <code>N_LBRAC</code> stabs is the most important thing
26 (see the descriptions of those stabs for more information). But Sun's
27 stabs in ELF has taken this further, to make all addresses in the
28 <code>n_value</code> field (functions and static variables) relative to the
29 source file. For the <code>N_SO</code> symbol itself, Sun simply omits the
30 address. To find the address of each section corresponding to a given
31 source file, the compiler puts out symbols giving the address of each
32 section for a given source file. Since these are ELF (not stab)
33 symbols, the linker relocates them correctly without having to touch the
34 stabs section. They are named <code>Bbss.bss</code> for the bss section,
35 <code>Ddata.data</code> for the data section, and <code>Drodata.rodata</code> for
36 the rodata section. For the text section, there is no such symbol (but
37 there should be, see below). For an example of how these symbols work,
38 See <a href="Stab-Section-Transformations.html#Stab%20Section%20Transformations">Stab Section Transformations</a>. GCC does not provide these symbols;
39 it instead relies on the stabs getting relocated. Thus addresses which
40 would normally be relative to <code>Bbss.bss</code>, etc., are already
41 relocated. The Sun linker provided with Solaris 2.2 and earlier
42 relocates stabs using normal ELF relocation information, as it would do
43 for any section. Sun has been threatening to kludge their linker to not
44 do this (to speed up linking), even though the correct way to avoid
45 having the linker do these relocations is to have the compiler no longer
46 output relocatable values. Last I heard they had been talked out of the
47 linker kludge. See Sun point patch 101052-01 and Sun bug 1142109. With
48 the Sun compiler this affects <code>S</code> symbol descriptor stabs
49 (see <a href="Statics.html#Statics">Statics</a>) and functions (see <a href="Procedures.html#Procedures">Procedures</a>). In the latter
50 case, to adopt the clean solution (making the value of the stab relative
51 to the start of the compilation unit), it would be necessary to invent a
52 <code>Ttext.text</code> symbol, analogous to the <code>Bbss.bss</code>, etc.,
53 symbols. I recommend this rather than using a zero value and getting
54 the address from the ELF symbols.
56 <p>Finding the correct <code>Bbss.bss</code>, etc., symbol is difficult, because
57 the linker simply concatenates the <code>.stab</code> sections from each
58 <code>.o</code> file without including any information about which part of a
59 <code>.stab</code> section comes from which <code>.o</code> file. The way GDB does
60 this is to look for an ELF <code>STT_FILE</code> symbol which has the same
61 name as the last component of the file name from the <code>N_SO</code> symbol
62 in the stabs (for example, if the file name is <code>../../gdb/main.c</code>,
63 it looks for an ELF <code>STT_FILE</code> symbol named <code>main.c</code>). This
64 loses if different files have the same name (they could be in different
65 directories, a library could have been copied from one system to
66 another, etc.). It would be much cleaner to have the <code>Bbss.bss</code>
67 symbols in the stabs themselves. Having the linker relocate them there
68 is no more work than having the linker relocate ELF symbols, and it
69 solves the problem of having to associate the ELF and stab symbols.
70 However, no one has yet designed or implemented such a scheme.
72 </body></html>