xref: /onnv-gate/usr/src/cmd/sgs/librtld/common/syms.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  *	Copyright (c) 1995-2001 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  *	All rights reserved.
25*0Sstevel@tonic-gate  *
26*0Sstevel@tonic-gate  * Update the symbol table entries:
27*0Sstevel@tonic-gate  *
28*0Sstevel@tonic-gate  *  o	If addr is non-zero then every symbol entry is updated to indicate the
29*0Sstevel@tonic-gate  *	new location to which the object will be mapped.
30*0Sstevel@tonic-gate  *
31*0Sstevel@tonic-gate  *  o	The address of the `_edata' and `_end' symbols, and their associated
32*0Sstevel@tonic-gate  *	section, is updated to reflect any new heap addition.
33*0Sstevel@tonic-gate  */
34*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #include	<libelf.h>
37*0Sstevel@tonic-gate #include	<string.h>
38*0Sstevel@tonic-gate #include	"sgs.h"
39*0Sstevel@tonic-gate #include	"machdep.h"
40*0Sstevel@tonic-gate #include	"msg.h"
41*0Sstevel@tonic-gate #include	"_librtld.h"
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate void
44*0Sstevel@tonic-gate update_sym(Cache *cache, Cache *_cache, Addr edata, Half endx, Addr addr)
45*0Sstevel@tonic-gate {
46*0Sstevel@tonic-gate 	char	*strs;
47*0Sstevel@tonic-gate 	Sym	*syms;
48*0Sstevel@tonic-gate 	Shdr	*shdr;
49*0Sstevel@tonic-gate 	Xword	symn, cnt;
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate 	/*
52*0Sstevel@tonic-gate 	 * Set up to read the symbol table and its associated string table.
53*0Sstevel@tonic-gate 	 */
54*0Sstevel@tonic-gate 	shdr = _cache->c_shdr;
55*0Sstevel@tonic-gate 	syms = (Sym *)_cache->c_data->d_buf;
56*0Sstevel@tonic-gate 	symn = shdr->sh_size / shdr->sh_entsize;
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate 	strs = (char *)cache[shdr->sh_link].c_data->d_buf;
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate 	/*
61*0Sstevel@tonic-gate 	 * Loop through the symbol table looking for `_end' and `_edata'.
62*0Sstevel@tonic-gate 	 */
63*0Sstevel@tonic-gate 	for (cnt = 0; cnt < symn; cnt++, syms++) {
64*0Sstevel@tonic-gate 		char	*name = strs + syms->st_name;
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate 		if (addr) {
67*0Sstevel@tonic-gate 			if (syms->st_value)
68*0Sstevel@tonic-gate 				syms->st_value += addr;
69*0Sstevel@tonic-gate 		}
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate 		if ((name[0] != '_') || (name[1] != 'e'))
72*0Sstevel@tonic-gate 			continue;
73*0Sstevel@tonic-gate 		if (strcmp(name, MSG_ORIG(MSG_SYM_END)) &&
74*0Sstevel@tonic-gate 		    strcmp(name, MSG_ORIG(MSG_SYM_EDATA)))
75*0Sstevel@tonic-gate 			continue;
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate 		syms->st_value = edata + addr;
78*0Sstevel@tonic-gate 		if (endx)
79*0Sstevel@tonic-gate 			syms->st_shndx = endx;
80*0Sstevel@tonic-gate 	}
81*0Sstevel@tonic-gate }
82