1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<!-- Copyright (C) 1992-2021 Free Software Foundation, Inc. 4Contributed by Cygnus Support. Written by Julia Menapace, Jim Kingdon, 5and David MacKenzie. 6 7Permission is granted to copy, distribute and/or modify this document 8under the terms of the GNU Free Documentation License, Version 1.3 or 9any later version published by the Free Software Foundation; with no 10Invariant Sections, with no Front-Cover Texts, and with no Back-Cover 11Texts. A copy of the license is included in the section entitled "GNU 12Free Documentation License". --> 13<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 14<head> 15<title>STABS: ELF Linker Relocation</title> 16 17<meta name="description" content="STABS: ELF Linker Relocation"> 18<meta name="keywords" content="STABS: ELF Linker Relocation"> 19<meta name="resource-type" content="document"> 20<meta name="distribution" content="global"> 21<meta name="Generator" content="makeinfo"> 22<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 23<link href="index.html#Top" rel="start" title="Top"> 24<link href="Symbol-Types-Index.html#Symbol-Types-Index" rel="index" title="Symbol Types Index"> 25<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 26<link href="Stab-Sections.html#Stab-Sections" rel="up" title="Stab Sections"> 27<link href="GNU-Free-Documentation-License.html#GNU-Free-Documentation-License" rel="next" title="GNU Free Documentation License"> 28<link href="Stab-Section-Basics.html#Stab-Section-Basics" rel="previous" title="Stab Section Basics"> 29<style type="text/css"> 30<!-- 31a.summary-letter {text-decoration: none} 32blockquote.smallquotation {font-size: smaller} 33div.display {margin-left: 3.2em} 34div.example {margin-left: 3.2em} 35div.indentedblock {margin-left: 3.2em} 36div.lisp {margin-left: 3.2em} 37div.smalldisplay {margin-left: 3.2em} 38div.smallexample {margin-left: 3.2em} 39div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 40div.smalllisp {margin-left: 3.2em} 41kbd {font-style:oblique} 42pre.display {font-family: inherit} 43pre.format {font-family: inherit} 44pre.menu-comment {font-family: serif} 45pre.menu-preformatted {font-family: serif} 46pre.smalldisplay {font-family: inherit; font-size: smaller} 47pre.smallexample {font-size: smaller} 48pre.smallformat {font-family: inherit; font-size: smaller} 49pre.smalllisp {font-size: smaller} 50span.nocodebreak {white-space:nowrap} 51span.nolinebreak {white-space:nowrap} 52span.roman {font-family:serif; font-weight:normal} 53span.sansserif {font-family:sans-serif; font-weight:normal} 54ul.no-bullet {list-style: none} 55--> 56</style> 57 58 59</head> 60 61<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 62<a name="ELF-Linker-Relocation"></a> 63<div class="header"> 64<p> 65Previous: <a href="Stab-Section-Basics.html#Stab-Section-Basics" accesskey="p" rel="previous">Stab Section Basics</a>, Up: <a href="Stab-Sections.html#Stab-Sections" accesskey="u" rel="up">Stab Sections</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p> 66</div> 67<hr> 68<a name="Having-the-Linker-Relocate-Stabs-in-ELF"></a> 69<h3 class="appendixsec">F.2 Having the Linker Relocate Stabs in ELF</h3> 70 71<p>This section describes some Sun hacks for Stabs in ELF; it does not 72apply to COFF or SOM. While <small>GDB</small> no longer supports this hack 73for Sun Stabs in ELF, this section is kept to document the issue. 74</p> 75<p>To keep linking fast, you don’t want the linker to have to relocate very 76many stabs. Making sure this is done for <code>N_SLINE</code>, 77<code>N_RBRAC</code>, and <code>N_LBRAC</code> stabs is the most important thing 78(see the descriptions of those stabs for more information). But Sun’s 79stabs in ELF has taken this further, to make all addresses in the 80<code>n_value</code> field (functions and static variables) relative to the 81source file. For the <code>N_SO</code> symbol itself, Sun simply omits the 82address. To find the address of each section corresponding to a given 83source file, the compiler puts out symbols giving the address of each 84section for a given source file. Since these are ELF (not stab) 85symbols, the linker relocates them correctly without having to touch the 86stabs section. They are named <code>Bbss.bss</code> for the bss section, 87<code>Ddata.data</code> for the data section, and <code>Drodata.rodata</code> for 88the rodata section. For the text section, there is no such symbol (but 89there should be, see below). For an example of how these symbols work, 90See <a href="Stab-Section-Transformations.html#Stab-Section-Transformations">Stab Section Transformations</a>. GCC does not provide these symbols; 91it instead relies on the stabs getting relocated. Thus addresses which 92would normally be relative to <code>Bbss.bss</code>, etc., are already 93relocated. The Sun linker provided with Solaris 2.2 and earlier 94relocates stabs using normal ELF relocation information, as it would do 95for any section. Sun has been threatening to kludge their linker to not 96do this (to speed up linking), even though the correct way to avoid 97having the linker do these relocations is to have the compiler no longer 98output relocatable values. Last I heard they had been talked out of the 99linker kludge. See Sun point patch 101052-01 and Sun bug 1142109. With 100the Sun compiler this affects ‘<samp>S</samp>’ symbol descriptor stabs 101(see <a href="Statics.html#Statics">Statics</a>) and functions (see <a href="Procedures.html#Procedures">Procedures</a>). In the latter 102case, to adopt the clean solution (making the value of the stab relative 103to the start of the compilation unit), it would be necessary to invent a 104<code>Ttext.text</code> symbol, analogous to the <code>Bbss.bss</code>, etc., 105symbols. I recommend this rather than using a zero value and getting 106the address from the ELF symbols. 107</p> 108<p>Finding the correct <code>Bbss.bss</code>, etc., symbol is difficult, because 109the linker simply concatenates the <code>.stab</code> sections from each 110<samp>.o</samp> file without including any information about which part of a 111<code>.stab</code> section comes from which <samp>.o</samp> file. The way GDB use to 112do this is to look for an ELF <code>STT_FILE</code> symbol which has the same 113name as the last component of the file name from the <code>N_SO</code> symbol 114in the stabs (for example, if the file name is <samp>../../gdb/main.c</samp>, 115it looks for an ELF <code>STT_FILE</code> symbol named <code>main.c</code>). This 116loses if different files have the same name (they could be in different 117directories, a library could have been copied from one system to 118another, etc.). It would be much cleaner to have the <code>Bbss.bss</code> 119symbols in the stabs themselves. Having the linker relocate them there 120is no more work than having the linker relocate ELF symbols, and it 121solves the problem of having to associate the ELF and stab symbols. 122However, no one has yet designed or implemented such a scheme. 123</p> 124<hr> 125<div class="header"> 126<p> 127Previous: <a href="Stab-Section-Basics.html#Stab-Section-Basics" accesskey="p" rel="previous">Stab Section Basics</a>, Up: <a href="Stab-Sections.html#Stab-Sections" accesskey="u" rel="up">Stab Sections</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p> 128</div> 129 130 131 132</body> 133</html> 134